① 單片機萬年歷
今天碰到了N個白痴問題。萬年歷是能夠顯示年月日、二十四節氣、農歷之類的東西,單片機是一塊晶元。萬年歷可以用單片機來做,但是我真不知道「萬年歷單片機」怎麼做。我想你應該想問的是怎麼用單片機來做萬年歷,我提供思路。 1、單片機最小系統一塊。可以用STC89C52晶元+外圍電路。可以燒入用戶編寫的程序,實現萬年歷所需的邏輯。 2、實時時鍾電路一塊,可以用DS1302晶元。提供年月日、時分秒數據給單片機。 3、顯示器電路一塊。用來顯示這些數據。 4、一些必要的按鍵,用來調整數據。
② 急求一片基於單片機的電子鍾 或者萬年歷的英文文獻5000字左右的!!!! 急求!!
Design of the digital Perpetual Calendar based on
real-time clock chip
Abstract:This Electronic calendar uses the AT89S52 microcontroller as the core for the control. Time Circuit which is constituted by Dallas's DS1302 real-time clock chip achieved a time and date display, it increased functionality for the temperature display and the whole point timekeeping. This paper discusses the hardware circuit of the system, principle in detail,and gives the flow chart of the software design and the major source code. keywords:microcontroller; real-time clock; Temperature measurement
1 Introction
E-calendar-bedroom at home,schools,stations and more and more extensive use of plaza for people's lives,study,work great convenience. Electronics calendar for the past need to re-adjust after power-off time and date,and time is a big error. Designed the system using real-time clock chip (DS1302) as a timer parts,the chip comes with an internal crystal oscillator,so that effectively guarantee the accuracy of the time and hang own internal battery power makes the situation will continue to update the time information . This design uses AT89S52 as the main controller,in order to improve the practicality of the circuit add temperature measurement circuit,timekeeping and alarm functions.
2 System hardware design
Schematic circuit shown in Figure 2:
System architecture diagram
2.1 Power Supply Circuit
In order to rece circuit costs,the system power supply circuit by the transformer transformer,three-terminal integrated regulator (L7805> circuit 5V, has a simple,reliable, inexpensive and so on.
2.2 Host Controller
Host controller using ATMEL's latest MCU Procts AT89S52. Apart from the single-chip microcomputer has a MCS-51 series single-chip all the benefits of things,also has 8KB of internal in-system programmable FLASH memory,free and low-power brown-out mode, greatly recing the power circuit . In addition,also has a watchdog circuit,a reliable job for the circuit provides greater assurance.
2.3 digital tube display circuit
Show circuit with a high brightness,long life,low cost features such as the LED digital tube. Throughout the show circuit by the digital control and display LED drive circuit and decoding circuit. Because of the system to display the contents of more,a total of 16 digital tube, respectively,with eight shows year,month,day,four show time,show that 22 weeks,2 show the temperature. Controller in order to save resources,between the controller and displays add a decoding circuit 16 so that would have required the line of control into the circuit only 4 control lines,a great save system resources. The decoder by the decoder constitute both 3-8.
2.4 Real-time clock chip
This design uses the United States Dallas company DS1302, the chip can automatically generate century,year,month,day,hour,minute,second,such as time information. Century the use of internal registers with the software will be able to resolve the 'Millennium', the problem. The chip has its own internal battery-keng,external brown-out,the internal time information also be able to maintain for 10 years. Time for a single day record of 12 hours and there is a 24-hour mode. Time Table
Ways that also has two kinds of binary numbers,and the other with BCD code express. The chip with 128 bytes of internal RAM,one of 11 bytes used to store time information,4 bytes of memory chips used to control information,known as the control register,113-byte general-purpose RAM for users to store temporary information. In addition,users can also program the chip to control a variety of square-wave output,and its internal three-way through the software interrupt shielding.
2.5 Buttons and temperature measurements and circuit
The system in order to make the circuit more easy,button circuit design only three keys, which are 'set','+','-', three keys to adjust the calendar and clock. The system in order to improve the practicality of the circuit,an increase of a temperature display. The system temperature measurement circuit using Dallas's DS18B20. The device because of its low price,easy circuits,measurement precision,etc..
2.6 audio signal generator and driver circuit
The circuit's function is to receive control circuit to send to the entire point of time and timing signal,according to system settings proce different frequencies of audio signals,amplification by the drive circuit to drive speakers to voice their opinions in order to realize the whole point timekeeping and alarm functions.
中文譯文:
基於實時鍾晶元的電子萬年歷的設計
摘要:電子萬年歷以AT89S52單片機為控制核心,採用Dallas公司的DS1302實時鍾晶元構成計時電路,實現了時間和日期的顯示,還增加了溫度顯示和整點報時的功能。文章對該系統的硬體電路、工作原理做了詳細介紹,同時給出了軟體設計的流程圖及主要程序源代碼。
關鍵詞:單片機,實時鍾.溫度測量
1引言
電子萬年歷在家庭居室、學校、車站和廣場使用越來越廣泛,給人們的生活、學習、工作帶來極大的方便。針對以往的電子萬年歷斷電後需重新調整時間與日期,且計時誤差大的現象。本系統設計採用實時鍾晶元(DS1302)作為計時器件,該晶元內部自帶晶體振盪器,這樣就有效的保證了計時的精確性,並且內部自帶鏗電池使得在斷電情況能繼續更新時間信息。本設計採用AT89S52作為主控制器,為了提高電路的實用性加入溫度測量電路、報時和鬧鍾功能。
2系統硬體的設計
電路原理圖如圖所示:
該系統的結構框圖
系統的工作原理是:主控制器每隔一段時間(小於一秒鍾)讀一次時鍾晶元的內部寄存器的值,將讀出的日歷、時間信息實時的顯示在LED數碼顯示器一上。同時,主控制器不斷的掃描按鍵電路和溫度測量電路,當有鍵按下時,識別出按鍵的值並調整相應的時間或日歷的值再寫入時鍾晶元內部。溫度數據由測量電路(DS18B20)獲得的溫度值送入顯示電路顯示。
2. 1電源電路
為了減少電路成本,本系統電源電路由變壓器變壓、三端集成穩壓(L7805>電路產生5V,具有簡單、可靠、價格低廉等特點。
2. 2主控制器
主控制器採用ATMEL公司的最新系列單片機產品AT89S52。該單片機除了擁有MCS-51系列單片機的所有優點外,內部還具有8KB的在系統可編程FLASH存儲器,低功耗的空閑和掉電模式,極大的降低了電路的功耗。另外,還具有一個看門狗電路,為電路的可靠工作提供了更大的保證。
2. 3數碼管顯示電路
顯示電路採用具有高亮度、使用壽命長、價格低廉等特點的LED數碼管。整個顯示電路由LED數碼管和顯示驅動電路和解碼電路構成。由於本系統中顯示的內容較多,共需要16個數碼管,分別用八位顯示年、月、日,四位顯示時間,二二位顯示星期,二位顯示溫度。為了節省控制器的資源,在控制器和顯示器之間加入一個解碼電路使本來需要16根控制線的電路變成只需四根控制線,極大的節省了系統資源。該解碼器由兩個3-8解碼器構成。
2. 4實時鍾晶元
本設計採用美國Dallas公司的DS12C887A,該晶元能夠自動產生世紀、年、月、日、時、分、秒等時間信息。利用內部的世紀寄存器,配合軟體就能解決』千年』,的問題。該晶元內部自帶有鏗電池,外部掉電時,其內部的時間信息還能夠保持10年之久。對於一天內的時間記錄有 12小時制和24小時制兩種模式。時間的表示方法也有兩種,一種用二進制數表示,另一種用BCD碼表示。該晶元內部帶有128位元組的RAM,其中11位元組用來存儲時間信息,4位元組用來存儲晶元的控制信息,稱為控制寄存器,113位元組通用RAM可供用戶存儲臨時信息。此外,用戶還可以對晶元進行編程式控制制輸出各種方波,並可對其內部的三路中斷通過軟體進行屏蔽。
2. 5按鍵與溫度測且電路
本系統為了使電路更簡單,按鍵電路只設計了三個按鍵,分別是』設置』、』+』、』-』,三個鍵用來調整日歷以及時鍾。本系統為了提高電路的實用性,增加了一個溫度顯示功能。該系統的溫度測量電路採用Dallas公司的DS1280。該器件由於其具有價格低廉、電路簡單、測量精確等優點。
2. 6音頻信號產生及驅動電路
本電路的功能是接收控制電路發送來的整點報時及定時信號,根據系統設定產生不同頻率的音頻信號,由驅動電路加以放大驅動揚聲器發出聲音,從而實現整點報時及鬧鍾的功能。
希望可以幫到你!!!
③ AT89C52+DS1302單片機萬年歷程序
參考程序,可以調節時間,設置鬧鍾,音樂鬧鈴
#include<reg52.h>
#include<INTRINS.H>
/************************************************************/
#define uchar unsigned char
#define uint unsigned int
#define TIME (0X10000-50000)
#define FLAG 0XEF //鬧鍾標志
/************************************************************/
//引腳連接圖
sbit CLK=P1^2;
sbit RST=P1^4;
sbit DAT=P1^3;
sbit RS=P1^5;
sbit RW=P1^6;
sbit E=P1^7;
sbit P32=P3^2;
sbit KEY1 = P2^7;
sbit KEY2 = P2^6;
sbit KEY3 = P2^5;
sbit KEY4 = P2^4;
sbit ACC_7=ACC^7;
/************************************************************/
//全局變數及常量定義
uchar i=20,j;
uchar DataBuf[16] = {};//日期
uchar TimeBuf[16] = {};//時間
uchar alarm[2],time[3];
uchar code Day[]={31,28,31,30,31,30,31,31,30,31,30,31};//12個月的最大日期(非閏年)
//閏年月星期表
const unsigned char WeekTab[] = {
(3 << 5) + 31,///1月
(6 << 5) + 29,///2月
(0 << 5) + 31,///3月
(3 << 5) + 30,///4月
(5 << 5) + 31,//5月
(1 << 5) + 30,//6月
(3 << 5) + 31,//7月
(6 << 5) + 31,//8月
(1 << 5) + 30,//9月
(4 << 5) + 31,//10月
(0 << 5) + 30,//11月
(2 << 5) + 31 //12月
};
//音律表
uint code table1[]={64260,64400,64524,64580,64684,64777,
64820,64898,64968,65030,65058,65110,65157,65178,65217};
//發聲部分的延時時間
uchar code table2[]={0x82,1,0x81,0xf4,0xd4,0xb4,0xa4,
0x94,0xe2,1,0xe1,0xd4,0xb4,0xc4,0xb4,4,0};
//鬧鍾中用的全局變數
uchar th1,tl1;
/************************************************************/
//延時1ms函數
delay1ms(uchar time)
{
uchar i,j;
for(i=0;i<time;i++)
{
for(j=0;j<250;j++);
}
}
/************************************************************/
//LCD控制函數
Enable()
{
RS=0;
RW=0;
E=0;
delay1ms(3);
E=1;
}
/************************************************************/
//LCD1602寫入字元函數
LCD1602_WriteSChr(uchar i)
{
P0=i;
RS=1;
RW=0;
E=0;
delay1ms(2);
E=1;
}
/************************************************************/
//LCD1602寫入字元串函數
//入口函數
//uchar data *address : 寫入數據首地址
//ucharm:寫入位元組數
LCD1602_WriteStr(uchar *address,uchar m)
{
uchar i,j;
for(i=0;i<m;i++,address++)
{
j=*address;
LCD1602_WriteSChr(j);
}
}
/************************************************************/
//LCD顯示
void LCDShow(void)
{
P0=0XC; //顯示器開、游標關
Enable();
//P0=0x80; //寫入顯示起始地址
//Enable();
//LCD1602_WriteStr(DataBuf,16); //寫入日期顯示緩存
P0=0xc1; //寫入顯示起始地址
Enable();
LCD1602_WriteStr(TimeBuf,16); //寫入時間顯示緩存
}
/************************************************************/
//DS1302寫入子程序
void DS1302_Write(uchar temp)
{
uchar i;
CLK=0; //將DS1320時鍾脈沖拉低
_nop_();//延時一指令周期
RST=1; //RST置高電平
_nop_();//延時一指令周期
for(i=0;i<8;i++) //循環8次
{
DAT=temp&0x01; //向DS1302寫入一位元組數據
_nop_(); //延時一指令周期
CLK=1; //拉高時鍾脈沖
temp>>=1; //右移一位
CLK=0; //拉低時鍾脈沖
}
}
/************************************************************/
//DS1302讀取子程序
uchar DS1302_Read()
{
uchar i,j=0;
for(i=0;i<8;i++)//循環8次
{
j>>=1; //右移一位
_nop_(); //延時一指令周期
CLK=0; //拉低時鍾脈沖
_nop_(); //延時一指令周期
if(DAT) //判斷接收該位數據是否為1
j|=0x80;//該位置1
_nop_(); //延時一指令周期
CLK=1; //拉高時鍾脈沖
}
return(j); //返回數值
}
/************************************************************/
//部分顯示數據初始化
TimeStart()
{
TimeBuf[0]=TimeBuf[8]=TimeBuf[9]=TimeBuf[10]=0x20; //不顯示字元
TimeBuf[2]=TimeBuf[5]=':'; //時間分隔顯示
DS1302_Write(0xc1);
alarm[0]=DS1302_Read();
RST=0;
DS1302_Write(0xc3);
alarm[1]=DS1302_Read();
RST=0;
DS1302_Write(0xc5);
DataBuf[0]=DS1302_Read();
RST=0;
}
/************************************************************/
//讀取時間
ReadTime()
{
uchar i,m,n;
for(m=0,i=0,n=0x85;i<7;i+=3,n-=2,m++) //連續讀取時,分,秒
{
DS1302_Write(n); //寫入讀取寄存器指令
time[m]=DS1302_Read(); //讀取數據
RST=0; //將RST電平拉低,停止傳輸
TimeBuf[i]=time[m]/16+0x30; //將兩位數據的十位轉為字元格式
TimeBuf[i+1]=time[m]%16+0x30;//將兩位數據的個位轉為字元格式
}
}
/************************************************************/
//功能選擇超時定時器
time0() interrupt 1 using 1
{
i--;
if(i==0)
{
if(j!=0)
j--;
i=20;
}
TH0=TIME/256,TL0=TIME%256;
}
/************************************************************/
//產生鬧鈴音調
intime1() interrupt 3
{
TH1=th1,TL1=tl1;
P32=!P32;
}
/************************************************************/
//鬧鍾顯示
void AlarmShow(void)
{
uchar i,j,a,b,n;
ET1=1;
for(j=0;j<6;j++)
{
i=0;
while(1)
{
a=table2[i];
if(a==0)
break;
b=a&0xf;
a>>=4;
if(a==0)
{
TR1=0;
goto D1;
}
a=((--a)<<1)/2;
TH1=th1=table1[a]/256,TL1=tl1=table1[a]%256;
TR1=1;
D1: do
{
b--;
for(n=0;n<3;n++)
{
ReadTime();
LCDShow();
P2=0xff;
if(KEY4 == 1)
{
delay1ms(100);
if(KEY4 == 1)
{
TR1=0;
ET1=0;
P32 = 1;
return;
}
}
}
}while(b!=0);
i++;
}
TR1=0;
}
ET1=0;
}
/************************************************************/
//設置日期、時間
void SetTime(void)
{
uchar i=0xc2,year,month,day,n;
TimeBuf[6]=TimeBuf[7]=0x30;
DataBuf[14]=DataBuf[15]=0x20;
LCDShow();
while(1)
{
P0=0xe; //顯示器開、游標開
Enable();
P0=i; //定游標
Enable();
P2=0xff;
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1)||(KEY4 == 1))
{
delay1ms(100); //延時0.1s去抖動
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1)||(KEY4 == 1))
{
j=7;
if(KEY1 == 1)
{
i+=3; //更改設置項目
if(i==0x8e)
i=0xc2;
else if(i>0xc5)
i=0xc2;
}
else if(KEY2 == 1)
{
year=(DataBuf[4]&0xf)*10+(DataBuf[5]&0xf); //將字元格式的年份轉換為數值格式
month=(DataBuf[7]&0xf)*10+(DataBuf[8]&0xf); //將字元格式的月份轉換為數值格式
day=(DataBuf[10]&0xf)*10+(DataBuf[11]&0xf); //將字元格式的日數轉換為數值格式
if(i==0x85) //設置年份
{
year++;
if(year>99)
year=0;
if((year%4)!=0)
if(month==2&&day==29)
day=28;
}
else if(i==0x88) //設置月份
{
month++;
if(month>12)
month=1;
if(day>Day[month-1])
{
day=Day[month-1];
if(month==2&&(year%4)==0) //計算是否閏年
day=29;
}
}
else if(i==0x8b) //設置日期
{
day++;
if(day>Day[month-1])
{
if(month==2&&(year%4)==0) //計算是否閏年
{
if(day>29)
day=1;
}
if(month!=2)
day=1;
}
}
else if(i==0xc2) //設置小時
{
n=(TimeBuf[0]&0xf)*10+(TimeBuf[1]&0xf);
n++;
if(n>23)
n=0;
TimeBuf[0]=n/10+0x30;
TimeBuf[1]=n%10+0x30;
}
else //設置分鍾
{
n=(TimeBuf[3]&0xf)*10+(TimeBuf[4]&0xf);
n++;
if(n>59)
n=0;
TimeBuf[3]=n/10+0x30;
TimeBuf[4]=n%10+0x30;
}
DataBuf[4]=year/10+0x30; //將數值格式的日期轉換為字元形式
DataBuf[5]=year%10+0x30;
DataBuf[7]=month/10+0x30;
DataBuf[8]=month%10+0x30;
DataBuf[10]=day/10+0x30;
DataBuf[11]=day%10+0x30;
LCDShow();
}
else if(KEY3 == 1) //按保存退出鍵後,向DS1302寫入設置後的日期時間
{
DS1302_Write(0x8c);
DS1302_Write((DataBuf[4]&0xf)*16+(DataBuf[5]&0xf));
RST=0;
DS1302_Write(0x8a);
DS1302_Write(SetWeek());
RST=0;
for(i=7,n=0x88;i<11;i+=3,n-=2)
{
DS1302_Write(n);
DS1302_Write((DataBuf[i]&0xf)*16+(DataBuf[i+1]&0xf));
RST=0;
}
for(i=0;i<7;i+=3,n-=2)
{
DS1302_Write(n);
DS1302_Write((TimeBuf[i]&0xf)*16+(TimeBuf[i+1]&0xf));
RST=0;
}
TR0=0;
return;
}
else
{
TR0=0;
return;
}
}
}
if(j==0)
{
TR0=0;
return;
}
}
}
/************************************************************/
//設置鬧鍾
void SetAlarm(void)
{
uchar i,n;
for(i=1;i<16;i++)
{
DataBuf[i]=0x20;
}
TimeBuf[0]=alarm[0]/16+0x30;
TimeBuf[1]=(alarm[0]&0xf)+0x30;
TimeBuf[3]=alarm[1]/16+0x30;
TimeBuf[4]=(alarm[1]&0xf)+0x30;
TimeBuf[6]=TimeBuf[7]=0x30;
LCDShow();
i=0xc2;
while(1)
{
P0=0xe; //顯示器開、游標開
Enable();
P0=i; //定游標
Enable();
P2=0xff;
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1)||(KEY4 == 1))
{
delay1ms(100); //延時0.1s去抖動
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1)||(KEY4 == 1))
{
j=7;
if(KEY1 == 1)
{
i+=3;
if(i>0xc5)
i=0xc2;
}
else if(KEY2 == 1)
{
if(i==0xc2)
{
n=(TimeBuf[0]&0xf)*10+(TimeBuf[1]&0xf);
n++;
if(n>23)
n=0;
TimeBuf[0]=n/10+0x30;
TimeBuf[1]=n%10+0x30;
}
else
{
n=(TimeBuf[3]&0xf)*10+(TimeBuf[4]&0xf);
n++;
if(n>59)
n=0;
TimeBuf[3]=n/10+0x30;
TimeBuf[4]=n%10+0x30;
}
LCDShow();
}
else if(KEY3 == 1)
{
DS1302_Write(0xc0);
DS1302_Write((TimeBuf[0]&0xf)*16+(TimeBuf[1]&0xf));
RST=0;
DS1302_Write(0xc2);
DS1302_Write((TimeBuf[3]&0xf)*16+(TimeBuf[4]&0xf));
RST=0;
DataBuf[0]=FLAG;
DS1302_Write(0xc4);
DS1302_Write(DataBuf[0]);
RST=0;
TR0=0;
TimeStart();
return;
}
else
{
TR0=0;
TimeStart();
return;
}
}
}
if(j==0)
{
TR0=0;
TimeStart();
return;
}
}
}
/************************************************************/
//DS1302初始化程序
void DS1302_Init(void)
{
uchar i,n;
DS1302_Write(0x8c);
DS1302_Write((DataBuf[4]&0xf)*16+(DataBuf[5]&0xf));
RST=0;
DS1302_Write(0x8a);
DS1302_Write(SetWeek());
RST=0;
for(i=7,n=0x88;i<11;i+=3,n-=2)
{
DS1302_Write(n);
DS1302_Write((DataBuf[i]&0xf)*16+(DataBuf[i+1]&0xf));
RST=0;
}
for(i=0;i<7;i+=3,n-=2)
{
DS1302_Write(n);
DS1302_Write((TimeBuf[i]&0xf)*16+(TimeBuf[i+1]&0xf));
RST=0;
}
}
/************************************************************/
//主函數
main()
{
IE=0x82;
TMOD=0x11;
DS1302_Write(0x8E); //禁止防寫
DS1302_Write(0);
RST=0;
P0=1; //清屏並游標復位
Enable();
P0=0x38; //設置顯示模式:8位2行5x7點陣
Enable();
P0=6; //文字不動,游標自動右移
Enable();
DS1302_Init();
TimeStart();
while(1)
{
ReadTime(); //讀取時間
LCDShow(); //顯示時間
if(DataBuf[0]!=0x20)
if(time[0]==alarm[0])
if(time[1]==alarm[1])
if(time[2]==0)
AlarmShow();
P2=0xff;
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1))
{
delay1ms(100); //延時0.1s去抖動
if((KEY1 == 1)||(KEY2 == 1)||(KEY3 == 1))
{
j=7;
TH0=TIME/256,TL0=TIME%256;
TR0=1;
if(KEY1 == 1)
{
SetTime();
}
else if(KEY2 == 1)
{
SetAlarm();
}
else if(KEY3 == 1)
{
TR0=0;
if(DataBuf[0]==FLAG)
DataBuf[0]=0x20;
else
DataBuf[0]=FLAG;
DS1302_Write(0xc4);
DS1302_Write(DataBuf[0]);
RST=0;
}
}
}
delay1ms(100);
}
}
④ 急求PROTUES實現萬年歷 單片機C語言程序做的 HEX文件 源程序和模擬圖
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit db=P2^7;
char i,sec,min,h,date,month,year,flag;
uchar j,k,m,n,o,p;
sbit la=P2^0;
sbit wela1=P2^1;
sbit wela2=P2^2;
sbit key_ch=P3^5;
sbit key_add=P3^6;
sbit key_minus=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init();
void delay(uint);
void second_display();
void minute_display();
void hour_display();
void date_display();
void month_display();
void year_display();
void control();
void time();
void main()
{
init();
while(1)
{
second_display();
minute_display();
hour_display();
date_display();
month_display();
year_display();
control();
}
}
void init()
{
db=0;
i=0;
sec=0;
min=0;
h=0;
date=1;
month=1;
year=1;
flag=0;
wela1=0;
wela2=0;
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void second_display()
{
int sec_shi,sec_ge;
sec_shi=sec/10;
sec_ge=sec%10;
if(flag==1&&j!=1)
j++;
else
{
j=0;
la=1;
P0=~table[sec_ge];
la=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x20;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[sec_shi];
la=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x10;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
}
}
void minute_display()
{
int min_shi,min_ge;
min_shi=min/10;
min_ge=min%10;
if(flag==2&&k!=1)
k++;
else
{
k=0;
la=1;
P0=~table[min_ge];
la=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x08;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[min_shi];
la=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x04;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
}
}
void hour_display()
{
int h_shi,h_ge;
h_shi=h/10;
h_ge=h%10;
if(flag==3&&m!=1)
m++;
else
{
m=0;
la=1;
P0=~table[h_ge];
la=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x02;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
delay(1);
la=1;
P0=~table[h_shi];
la=0;
wela1=1;
P1=0x00;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x01;
wela2=0;
delay(1);
la=1;
P0=0xff;
la=0;
wela2=0;
delay(1);
}
}
void date_display()
{
int date_shi,date_ge;
date_shi=date/10;
date_ge=date%10;
if(flag==4&&n!=1)
n++;
else
{
n=0;
la=1;
P0=~table[date_ge];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x80;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[date_shi];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x40;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
}
}
void month_display()
{
int month_shi,month_ge;
month_shi=month/10;
month_ge=month%10;
if(flag==5&&o!=1)
o++;
else
{
o=0;
la=1;
P0=~table[month_ge];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x20;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[month_shi];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x10;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
}
}
void year_display()
{
int year_qian,year_,year_shi,year_ge;
year_qian=year/1000;
year_=year%1000/100;
year_shi=year%1000%100/10;
year_ge=year%10;
if(flag==6&&p!=1)
p++;
else
{
p=0;
la=1;
P0=~table[year_ge];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x08;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[year_shi];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x04;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[year_];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x02;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
la=1;
P0=~table[2];
la=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x01;
wela1=0;
delay(1);
la=1;
P0=0xff;
la=0;
wela1=0;
}
}
void control()
{
if(!key_ch)
{
delay(5);
if(!key_ch)
{
flag++;
if(flag==7)
flag=0;
}
}
while(!key_ch);
if(flag==1&&key_add==0)
{
while(!key_add);
sec++;
if(sec==60)
sec=0;
}
if(flag==1&&key_minus==0)
{
while(!key_minus);
sec--;
if(sec==-1)
sec=59;
}
if(flag==2&&key_add==0)
{
while(!key_add);
min++;
if(min==60)
min=0;
}
if(flag==2&&key_minus==0)
{
while(!key_minus);
min--;
if(min==-1)
min=59;
}
if(flag==3&&key_add==0)
{
while(!key_add);
h++;
if(h==24)
h=0;
}
if(flag==3&&key_minus==0)
{
while(!key_minus);
h--;
if(h==-1)
h=23;
}
if(flag==4&&key_add==0)
{
while(!key_add);
date++;
if(date==29)
if((year%4!=0)&&(month==2))
date=1;
if(date==30)
if((year%4==0)&&(month==2))
date=1;
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
date=1;
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
date=1;
}
if(flag==5&&key_add==0)
{
while(!key_add);
month++;
if(month==13)
month=1;
}
if(flag==5&&key_minus==0)
{
while(!key_minus);
month--;
if(month==0)
month=12;
}
if(flag==6&&key_add==0)
{
while(!key_add);
year++;
if(year==99)
year=1;
}
if(flag==6&&key_minus==0)
{
while(!key_minus);
year--;
if(year==0)
year=99;
}
}
void T0_rpt() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
time();
}
void time()
{
if(i==20)
{
i=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
h++;
if(h==24)
{
h=0;
min=0;
sec=0;
date++;
if(date==29)
if((year%4!=0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==30)
if((year%4==0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
}
}
}
}
}
⑤ 求基於單片機的電子萬年歷設計的英文文獻
S.M.T.AlModarresi,N.M.White.
Calendarconversionforreal-timesystems[J].AdvancesinEngineeringSoftware,
2004,35(8):511–516
⑥ 帶農歷的萬年歷,英文顯示
我有2011年英文台歷,顯示了中國,歐洲,美國的各大小假期的。
⑦ 單片機萬年歷c語言
#include<stdio.h>
//判斷是否是閏年
int leapYear(int year)
{
if((year%4==0 && year%100!=0) || !(year%400))
return 1;
else
return 0;
}
//返回星期幾
int weekday(int year,int day_sum)
{
if(year<2012)
return (7-day_sum%7+1);
else
return (day_sum%7+1);
}
//年份之間相隔的天數
int year_sum(int year)
{
int yearSum=0;
if(year<=2011)
for(int i=year;i<2012;i++)
{
if(leapYear(i))
yearSum+=366;
else
yearSum+=365;
}
else if(year==2012 || year==2013)
return 0;
else if(year>2013)
for(int i=year;i>2013;i--)
{
if(leapYear(i-1))
yearSum+=366;
else
yearSum+=365;
}
return yearSum;
}
//某月的天數
int month_sum(int year,int month)
{
if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
return 31;
else if(month==2)
{
if(leapYear(year))
return 29;
else
return 28;
}
else
return 30;
}
//列印日歷
void print(int year)
{
FILE *p;
p=fopen("calendar.txt","a+");
fprintf(p,"輸入要列印日歷的年份:%d\n",year);
int cal[31];
int initWeek;
int totalDay=0;
int count=0;
if(year<2012)
totalDay=year_sum(year)+64;
else if(year==2012)
totalDay=year_sum(year)+62;
else
totalDay=year_sum(year)+302;
initWeek=weekday(year,totalDay);
for(int j=1;j<=12;j++)
{
printf("%d年%d月\n",year,j);
fprintf(p,"%d年%d月\n",year,j);
printf("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
fprintf(p,"星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
fprintf(p,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
int limit=month_sum(year,j);
if(j>=2)
{
initWeek=count%7;
count=0;
}
if(initWeek!=7)
{
for(int n=0;n<initWeek;n++)
{
printf("\t");
fprintf(p,"\t");
count++;
}
}
for(int i=0;i<limit;i++)
cal[i]=i+1;
for(i=0;i<limit;i++)
{
printf("%4d\t",cal[i]);
fprintf(p,"%4d\t",cal[i]);
count++;
if(count%7==0)
{
printf("\n");
fprintf(p,"\n");
}
}
printf("\n\n\n");
fprintf(p,"\n\n\n");
}
fclose(p);
}
int main()
{
int year;
printf("輸入要列印日歷的年份:");
while(scanf("%d",&year)!=EOF){
print(year);
}
return 0;
}
⑧ 設計一個基於單片機的萬年歷程序
#include<reg51.h>
#include"lcd.h"
#include"ds1302.h"
sbitK1=P3^1;
sbitK2=P3^0;
sbitK3=P3^2;
sbitK4=P3^3; //管腳接線
unsignedcharcharacter0[24]={0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02 ,
0x0F,0x09,0x0F,0x09,0x0F,0x09,0x13,0x00,//"月"代碼0x01
0x0F,0x09,0x09,0x0F,0x09,0x09,0x0F,0x00,//"日"代碼0x02
};//年
voidInt0Configuration();
voidLcdDisplay();
unsignedcharSetState,SetPlace;
voidDelay10ms(void);//誤差0us
/*******************************************************************************
*函數名:main
*函數功能 :主函數
*輸入:無
*輸出 :無
*******************************************************************************/
voidmain()
{
unsignedchari,h;
Int0Configuration();
LcdInit();
LcdWriteCom(0x40);
for(h=0;h<24;h++)
{
LcdWriteData(character0[h]);
}
LcdWriteCom(0x80);
// Ds1302Init();
while(1)
{
if(SetState==0)
{
Ds1302ReadTime();
}
else
{
if(K1==0) //檢測按鍵K1是否按下
{
Delay10ms(); //消除抖動
if(K1==0)
{
SetPlace++;
if(SetPlace>=7)
SetPlace=0;
}
while((i<50)&&(K1==0)) //檢測按鍵是否松開
{
Delay10ms();
i++;
}
i=0;
}
if(K2==0) //檢測按鍵K2是否按下
{
Delay10ms(); //消除抖動
if(K2==0)
{
TIME[SetPlace]++;
if((TIME[SetPlace]&0x0f)>9) //換成BCD碼。
{
TIME[SetPlace]=TIME[SetPlace]+6;
}
if((TIME[SetPlace]>=0x60)&&(SetPlace<2)) //分秒只能到59
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x24)&&(SetPlace==2)) //小時只能到23
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x32)&&(SetPlace==3)) //日只能到31
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x13)&&(SetPlace==4)) //月只能到12
{
TIME[SetPlace]=0;
}
if((TIME[SetPlace]>=0x7)&&(SetPlace==5)) //周只能到7
{
TIME[SetPlace]=1;
}
// if(SetPlace==5) //月只能到12
// {
// TIME[SetPlace]=;
// }
}
while((i<50)&&(K2==0)) //檢測按鍵是否松開
{
Delay10ms();
i++;
}
i=0;
}
}
LcdDisplay();
}
}
/*******************************************************************************
*函數名:LcdDisplay()
*函數功能 :顯示函數
*輸入:無
*輸出 :無
*******************************************************************************/
voidLcdDisplay()
{
LcdWriteCom(0x80+0X40);
LcdWriteCom(0x0f);
LcdWriteCom(0xc0|(2-0x40));
LcdWriteCom(0x0c);
Delay10ms();
LcdWriteData('0'+TIME[2]/16); //時
LcdWriteData('0'+(TIME[2]&0x0f));
LcdWriteData(':');
LcdWriteData('0'+TIME[1]/16); //分
LcdWriteData('0'+(TIME[1]&0x0f));
LcdWriteData(':');
LcdWriteData('0'+TIME[0]/16); //秒
LcdWriteData('0'+(TIME[0]&0x0f));
LcdWriteCom(0x80);
LcdWriteData('2');
LcdWriteData('0');
LcdWriteData('0'+TIME[6]/16); //年
LcdWriteData('0'+(TIME[6]&0x0f));
LcdWriteData(0x00);
LcdWriteData('0'+TIME[4]/16); //月
LcdWriteData('0'+(TIME[4]&0x0f));
LcdWriteData(0x01);
LcdWriteData('0'+TIME[3]/16); //日
LcdWriteData('0'+(TIME[3]&0x0f));
LcdWriteData(0x02);
LcdWriteCom(0x8D);
LcdWriteData('0'+(TIME[5]&0x07)-1); //星期
}
/*******************************************************************************
*函數名:Int0Configuration()
*函數功能 :配置外部中斷0
*輸入:無
*輸出 :無
*******************************************************************************/
voidInt0Configuration()
{
//設置INT0
IT0=1;//跳變沿出發方式(下降沿)
EX0=1;//打開INT0的中斷允許。
EA=1;//打開總中斷
}
/*******************************************************************************
*函數名:Int0()
*函數功能 :外部中斷0中斷函數
*輸入:無
*輸出 :無
*******************************************************************************/
voidInt0()interrupt0
{
Delay10ms();
if(K3==0)
{
SetState=~SetState;
SetPlace=0;
Ds1302Init();
}
}
/*******************************************************************************
*函數名:Delay10ms
*函數功能 :延時函數,延時10ms
*輸入:無
*輸出 :無
*******************************************************************************/
voidDelay10ms(void)//誤差0us
{
unsignedchara,b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
⑨ 基於51單片機,DS1302,1602實現萬年歷(年月日時分秒)及鬧鍾功能的C程序,不要顯示農歷和溫度,謝謝!!
【八】電子表、萬年歷系列
[1]單片機公交車環境監測及時間顯示系統
功能描述:
1、按鍵調時間
2、帶備用電池(斷電繼續走時)
3、監測雜訊和溫濕度並實時顯示
4、超過報警值蜂鳴器會響
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMTQ3OTMxMDUwMA==.html
[2]單片機語音報時電子表
功能描述:
1、按鍵調試設置鬧鍾
2、帶備用電池(斷電繼續走時)
3、整點語音報時
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMTQ3OTMwMjM0OA==.html
[3]單片機紅外遙控電子表語音報時語音播報溫濕度
功能描述:
1、紅外遙控調時間設定鬧鍾
2、帶備用電池(斷電繼續走時)
3、整點語音報時語音播報溫濕度
4、按鍵遙控語音報時語音播報溫濕度
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMTQ3OTMxMTUyOA==.html
[4]單片機紅外遙控電子表語音報時格林威治時間雙顯示
功能描述:
1、紅外遙控調時間設定鬧鍾
2、帶備用電池(斷電繼續走時)
3、整點語音報時語音播報溫濕度
4、按鍵遙控語音報時語音播報溫濕度
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMTQ3OTMxMTUyOA==.html
[5]單片機多功能萬年歷電子表系統節日提醒溫濕度顯示
功能描述:
1、按鍵調時間,設置鬧鍾
2、帶備用電池(斷電繼續走時)
3、陽歷、農歷節日提醒;可顯示上午、中午、晚上、午夜、深夜等時間段
4、溫濕度實時顯示(可替換其他感測器數據顯示)
5、功能擴展:語音播報萬年歷、溫濕度等。(此項功能為擴展功能,需要需補差價)
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMTU0MjI4OTExNg==.html
【二十】GPS授時定位系統系列
[1]GPS自動授時系統 語音報時/播報溫濕度
實現功能:
1.可設置授時模式為自動授時和手動更新
2.可脫離GPS數據利用本地時鍾晶元准確走時
3.可設置靜音模式、整點報時和自動語音播報溫濕度及其混合模式等四種語音工作模式
4.可以切換顯示本地時間和溫濕度數據和GPS衛星時間數據和定位數據
5.經過分析GPS數據,利用演算法縮短了解析時間在秒級時間內就能獲取到GPS時間數據(正常情況下,完成定位需要幾分鍾以上)
6.(亮點)利用演算法自動計算星期參數和農歷參數,程序內部演算法輸入任何陽歷日期數據即可得到准確的星期數據和農歷數據
7.利用12864串口工作模式,節省了8個IO
8.可根據需求進行功能定製
☆已作出的實物優酷視頻演示地址:
http://v.youku.com/v_show/id_XMjUzMzcyNTkyOA==.html
⑩ 52單片機的萬年歷語言,八位LED共陰數碼管動態顯示年月日 時分秒
你描述的不對
有些地方不很完善
什麼叫
萬年歷
語言,或許你想表達,編寫單片機的語言,一般用c語言啊
8個
數碼管
你要顯示「年月日時分秒」,這樣是顯示不夠的,比如年月日如:「13-06-21」,時分秒如:「11-28-05」,是這樣嗎
一般顯示用
lcd1602
的比較多
為什麼你要用8個按鍵呢,是調整日期嗎?其實三個就夠了啊,一個選擇要調整的對象,一個增加,一個減少
你說全部與p30連接,是什麼與他連接呢
可以交流
myID