资源描述:
《LCD液晶万年历显示程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#includesbitRS=P2^6;sbitrw=P2^5;sbitLCDE=P2^7;unsignedcharn;unsignedcharshi,ge,fen,miao,count;unsignedintyear,yue,ri;//unsignedcharcodetable[]="2011-8-4MON";voiddelay(unsignedintxms){unsignedinti,j;for(i=xms;i>0;i--)for(j=110;j>0;j--);}voidwrite_com(unsignedcharcom
2、){RS=0;rw=0;LCDE=0;P0=com;delay(5);LCDE=1;delay(5);LCDE=0;}voidwrite_date(unsignedchardate){RS=1;rw=0;LCDE=0;P0=date;delay(5);LCDE=1;delay(5);LCDE=0;}voidwrite_sfm(unsignedcharadd,unsignedchardate){unsignedcharshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_dat
3、e(shi+0x30);write_date(ge+0x30);}voidwrite_n(unsignedintadd1,unsignedintdate1){unsignedintq,b,s,g;q=date1/1000;b=date1/100%10;s=date1/10%10;g=date1%10;write_com(0x80+add1);write_date(q+0x30);write_date(b+0x30);write_date(s+0x30);write_date(g+0x30);}voidwrite_yr(unsignedchar
4、add2,unsignedchardate2){unsignedchars1,g1;s1=date2/10;g1=date2%10;write_com(0x80+add2);write_date(s1+0x30);write_date(g1+0x30);}voidinit(){LCDE=0;fen=35;miao=34;shi=15;ri=4;yue=8;year=2011;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80+7);wri
5、te_date('-');delay(5);write_com(0x80+10);write_date('-');write_n(3,year);write_yr(8,yue);write_yr(11,ri);delay(5);write_com(0x80+0x40+6);write_date(':');delay(5);write_com(0x80+0x40+9);write_date(':');delay(5);write_sfm(10,miao);write_sfm(7,fen);write_sfm(4,shi);TMOD=0x01;T
6、H0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;TR0=1;ET0=1;}voidmain(){init();while(1);}voidtime0()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;count++;if(count==20){count=0;miao++;if(miao==60){miao=0;fen++;if(fen==60){fen=0;shi++;if(shi==24){shi=0;ri++;switch(yu
7、e){case1:case3:case5:case7:case8:case10:case12:if(ri==32){ri=1;yue++;}break;case4:case6:case9:case11:if(ri==31){ri=1;yue++;}break;case2:if(year%4==0){if(ri==30){ri=1;yue++;}}else{if(ri==29){ri=1;yue++;}}break;}if(yue==13){yue=1;year++;}write_n(3,year);write_yr(8,yue);}write
8、_yr(11,ri);}write_sfm(4,shi);}write_sfm(7,fen);}write_sfm(10,miao);}