51hei圖片20191216152652.png (66.68 KB, 下載次數: 14)
下載附件
2019-12-16 15:27 上傳
- #include<reg51.h>
- #include"LCD1602.h"
- #include"DS1302.h"
- #define uchar unsigned char
- #define uint unsigned int
- bit key_flag1=0,key_flag2=0;
- SYSTEMTIME adjusted;
- uchar sec_add=0,min_add=0,hou_add=0,day_add=0,mon_add=0,yea_add=0;
- uchar data_alarm[7]={0};
- int key_scan()
- {
- int i=0;
- uint temp;
- P1=0xf0;
- temp=P1;
- if(temp!=0xf0)
- {
- i=1;
- }
- else
- {
- i=0;
- }
- return i;
- }
- uchar key_value()
- {
- uint m=0,n=0,temp;
- uchar value;
- uchar v[4][3]={'2','1','0','5','4','3','8','7','6','b','a','9'};
- P1=0xfe;temp=P1;if(temp!=0xfe)m=0;
- P1=0xfd;temp=P1;if(temp!=0xfd)m=1;
- P1=0xfb;temp=P1;if(temp!=0xfb)m=2;
- P1=0xf7;temp=P1;if(temp!=0xf7)m=3;
- P1=0xef;temp=P1;if(temp!=0xef)m=0;
- P1=0xdf;temp=P1;if(temp!=0xdf)m=1;
- P1=0xbf;temp=P1;if(temp!=0xbf)m=2;
- value=v[m][n];
- return value;
- }
- void adjust(void)
- {
- if(key_scan()&&key_flag1)
- switch(key_value())
- {
- case'0':sec_add++;break;
- case'1':min_add++;break;
- case'2':hou_add++;break;
- case'3':day_add++;break;
- case'4':mon_add++;break;
- case'5':yea_add++;break;
- default:break;
- }
- adjusted.Second+=sec_add;
- adjusted.Minute+=min_add;
- adjusted.Hour+=hou_add;
- adjusted.Day+=day_add;
- adjusted.Month+=mon_add;
- adjusted.Year+=yea_add;
- if(adjusted.Second>59)
- {
- adjusted.Second=adjusted.Second%60;
- adjusted.Minute++;
- }
- if(adjusted.Minute>59)
- {
- adjusted.Minute=adjusted.Minute%60;
- adjusted.Hour++;
- }
- if(adjusted.Hour>23)
- {
- adjusted.Hour=adjusted.Hour%24;
- adjusted.Day++;
- }
- if(adjusted.Day>31)adjusted.Day=adjusted.Day%31;
- if(adjusted.Month>12)adjusted.Month=adjusted.Month%12;
- if(adjusted.Year>100)adjusted.Year=adjusted.Year%100;
- }
- void changing(void)interrupt 0 using 0
- {
- if(key_flag1)
- key_flag1=0;
- if(key_flag1)
- key_flag1=1;
- }
- main()
- {
- uint i;
- uchar p1[]="D;",p2[]="T:";
- SYSTEMTIME T;
- EA=1;
- EX0=1;
- IT0=1;
- EA=1;
- EX1=1;
- IT1=1;
- init1602();
- Initial_DS1302();
- while(1)
- {
- write_com(0x80);
- write_string(p1,2);
- write_com(0xc0);
- write_string(p2,2);
- DS1302_GetTime(&T);
- adjusted.Second=T.Second;
- adjusted.Minute=T.Minute;
- adjusted.Hour=T.Hour;
- adjusted.Week=T.Week;
- adjusted.Day=T.Day;
- adjusted.Month=T.Month;
- adjusted.Year=T.Year;
- for(i=0;i<9;i++)
- {
- adjusted.DateString[i]=T.DateString[i];
- adjusted.TimeString[i]=T.TimeString[i];
- }
- adjust();
- DateToStr(&adjusted);
- TimeToStr(&adjusted);
- write_com(0x82);
- write_string(adjusted.DateString,8);
- write_com(0xc2);
- write_string(adjusted.TimeString,8);
- delay(10);
- }
- }
復制代碼
|