资源描述:
《单片机设计的电子日历.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、电子日历程序#include#defineucharunsignedchar#defineuintunsignedint#defineshujuP0sbitrs=P2^0;sbitrw=P2^1;sbiten=P2^2;sbitstop=P3^0;//暂停继续sbitjia=P3^1;//加计数sbitjian=P3^2;//减计数ucharci,num,shi,fen,miao,num20,nian=13,yue=12,ri=2,week,t;ucharcodetable1[]="2013-12-02Mon";ucharcodetable2[]="
2、00:00:00";ucharcodexingqi[]="MonTusWedThuFriSatSun";voiddelay(uintz);voidxieins(ucharins);voidxieda(ucharda);voidchushi();voiddisplay(ucharadd,uchardat);voidkeyscan();voidxieweek();voidmain(){chushi();while(1){keyscan();}}voiddelay(uintz)//延时1ms{uintx,y;for(x=z;x>0;x--)for(y=115;y>0;y--
3、);}voidxieins(ucharins)//写指令{rs=0;rw=0;shuju=ins;en=0;delay(5);en=1;delay(5);en=0;}voidxieda(ucharda)//写数据{rs=1;rw=0;shuju=da;en=0;delay(5);en=1;delay(5);en=0;}voidchushi(){xieins(0x38);//功能设置8位数据接口双行显示xieins(0x0c);//显示设置开启显示屏关闭光标光标不闪烁xieins(0x06);//输入模式设置光标右移一格且地址数加1xieins(0x01);//清屏TM
4、OD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;//开定时器0xieins(0x80);for(num=0;num<16;num++){xieda(table1[num]);//显示第一行delay(5);}xieins(0xc4);for(num=0;num<8;num++){xieda(table2[num]);//显示第二行delay(5);}}voiddisplay(ucharadd,uchardat)//地址数据{ucharshi,ge;shi=dat/10;ge=da
5、t%10;xieins(add);delay(5);xieda(shi+0x30);delay(5);xieda(ge+0x30);delay(5);}voidtimer0()interrupt1{num20++;TH0=(65536-50000)/256;TL0=(65536-50000)%256;if(num20==20){num20=0;miao++;if(miao==60){miao=0;fen++;if(fen==60){fen=0;shi++;if(shi==24){shi=0;ri++;xieweek();//week++;if(ri==31)//可定意
6、义变量{ri=1;yue++;if(yue==13){yue=1;nian++;display(0x82,nian);}display(0x85,yue);}display(0x88,ri);}display(0xc4,shi);}display(0xc7,fen);}display(0xca,miao);}}voidkeyscan(){if(stop==0){delay(10);if(stop==0){while(!stop);TR0=0;ci++;xieins(0x0f);//显示光标光标闪烁if(ci==1){xieins(0xcb);}if(ci==2){xi
7、eins(0xc8);}if(ci==3){xieins(0xc5);}if(ci==4){xieins(0x8d);}if(ci==5){xieins(0x89);}if(ci==6){xieins(0x86);}if(ci==7){xieins(0x83);}if(ci==8){ci==0;xieins(0x0c);TR0=1;}}}if(jia==0){delay(10);if(jia==0){while(!jia);if(ci==1){miao++;if(miao==60)miao=0;display(0xca,miao);xieins(0x