资源描述:
《基于51单片机的1602液晶时钟设计的C程序(闰年补偿,月份调整)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintucharcodetable[]="2012-02-29MON";ucharcodetable1[]="23:59:55";ucharnum,count,shi,fen,miao,nian,yue,ri,xingqi,s1num,flag;sbitlcden=P2^5;sbitlcdrs=P1^0;sbitlcdrw=P1^1;sbits1=P3^0;sbits2=P3^1;s
2、bits3=P3^2;sbits4=P3^3;sbitfeng=P2^3;/***************延迟函数***************/voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}/**********写命令***************/voidwrite_com(ucharcom){lcdrs=0;lcdrw=0;P0=com;lcden=1;delay(5);lcden=0;}/**************写
3、数据****************/voidwrite_data(uchardate){lcdrs=1;lcdrw=0;P0=date;lcden=1;delay(5);lcden=0;}/*************时分秒调节函数********************/voidwrite_sfm(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_data(0x30+shi);w
4、rite_data(0x30+ge);}/****************年月日调节函数***************/voidwrite_nyr(ucharad,uchardat){ucharshi,ge;shi=dat/10;ge=dat%10;write_com(0x80+0x00+ad);write_data(0x30+shi);write_data(0x30+ge);}/**************************星期显示函数*****************/voiddisplay
5、_week(){switch(xingqi){case1:write_data('M');write_data('O');write_data('N');write_com(0x80+0x00+14);break;case2:write_data('T');write_data('U');write_data('E');write_com(0x80+0x00+14);break;case3:write_data('W');write_data('E');write_data('D');write_co
6、m(0x80+0x00+14);break;case4:write_data('T');write_data('H');write_data('U');write_com(0x80+0x00+14);break;case5:write_data('F');write_data('R');write_data('I');write_com(0x80+0x00+14);break;case6:write_data('S');write_data('A');write_data('T');write_com
7、(0x80+0x00+14);break;case7:write_data('S');write_data('U');write_data('N');write_com(0x80+0x00+14);break;}}voidkeycan(){/****************光标左移***************/if(s1==0){delay(5);if(s1==0){s1num++;while(!s1);if(s1num==1){TR0=0;write_com(0x80+0x40+11);write
8、_data('<');write_com(0x80+0x40+10);//光标重新回到闪烁点,写光标地址同样加一write_com(0x0f);//光标闪烁}if(s1num==2){write_com(0x80+0x40+11);write_data('');write_com(0x80+0x40+8);write_data('<');write_com(0x80+0x40+7);}if(s1num==3){write_com(0x80+0x40+8)