资源描述:
《基于51单片机的简易电子表》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、基于51单片机的简易电子表/*****************************************************************阿斌独家制作:电子表1602液晶显示带有闹钟功能每天到指定时间后闹钟提醒闹钟响后按s4键关闭闹钟如果闹钟响后大约20秒未检测到s4键按下,则闹钟自动关闭******************************************************************/主程序:#include#defineucharunsignedchar#defineuintunsi
2、gnedintsbitlcden=P2^2;sbitlcdrw=P2^1;sbitlcdrs=P2^0;sbits1=P3^0;sbits2=P3^1;sbits3=P3^2;sbits4=P3^3;sbitrd=P3^7;sbitbeep=P1^2;uintnian,a;ucharcount,s1num,i,xq,ri,yue,flag;charshi,fen,miao,shia,fena,miaoa;ucharcodetable[]="2012-11-19MON";ucharcodetable1[]="00:00:00";ucharcodexq1[]="
3、MON";ucharcodexq2[]="TUE";ucharcodexq3[]="WED";ucharcodexq4[]="THU";ucharcodexq5[]="FRI";ucharcodexq6[]="SAT";ucharcodexq7[]="SUN";voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voiddidi(){beep=1;delay(5);beep=0;delay(5);beep=1;delay(5);beep=0;delay(5);}voidwrite_com(
4、ucharcom){lcdrs=0;lcden=0;lcdrw=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_date(uchardate){lcdrs=1;lcden=0;lcdrw=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;}voidinit(){ucharnum;lcden=0;xq=1;ri=19;yue=11;nian=2012;a=1000;flag=0;shia=00;fena=00;miaoa=05;write_com(0x38);wr
5、ite_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);for(num=0;num<16;num++){write_date(table[num]);delay(5);}write_com(0x80+0x40);for(num=0;num<12;num++){write_date(table1[num]);delay(5);}TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;}voidwrite_sf
6、m2(ucharadd,uintdate){ucharqian,bai,shi,ge;qian=date/1000;bai=date%1000/100;shi=date%100/10;ge=date%10;write_com(0x80+add);write_date(0x30+qian);write_date(0x30+bai);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_sfm1(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date%10;writ
7、e_com(0x80+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_sfm(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_xq(){write_com(0x80+13);switch(xq){case1:for(i=0;i<3;i++){write_date(xq1[i]);d
8、elay(5);}break;case2:for(i