欢迎来到天天文库
浏览记录
ID:40453092
大小:39.00 KB
页数:5页
时间:2019-08-03
《1602电子时钟》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、2021-10-8电子时钟#include#defineucharunsignedchar#defineuintunsignedintsbitrs=P2^6;sbitlcden=P2^7;sbitrw=P2^5;sbits1=P1^0;sbits2=P1^1;sbits3=P1^2;//sbits4=P1^3;ucharcount,s1num;charshi,fen,miao;ucharcodetable[]="2010-7-30MON";ucharcodetable1[]="00:0
2、0:00";voiddelay(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voidwrite_com(ucharcom)//lcd写指令{rs=0;//指令0rw=0;lcden=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}voidwrite_date(uchardate)//lcd写数据{rs=1;//数据1rw=0;lcden=0;P0=date;delay(5);lcden=1;delay(5)
3、;lcden=0;}52021-10-8voidinit()//初始化{ucharnum;lcden=0;//miao=54;//fen=59;//shi=23;write_com(0x38);//显示设置write_com(0x0c);//不显示光标write_com(0x06);//指针+1write_com(0x01);//刷新delay(1);write_com(0x80);for(num=0;num<15;num++)//装数据{write_date(table[num]);delay(2);
4、}write_com(0x80+0x40);//换行for(num=0;num<12;num++){write_date(table1[num]);delay(2);}TMOD=0x01;//timer1TH0=(65536-50000)/256;//12M晶振为1msTL0=(65536-50000)%256;EA=1;//opentatalinterruptET0=1;//openziinterruptTR0=1;//opentimer}voidwrite_sfm(ucharadd,uchardat
5、e)//时间子程序{ucharshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_date(0x30+shi);write_date(0x30+ge);}voidkeyscan()//按键子程序{//扫描if(s1==0){52021-10-8delay(5);//去抖if(s1==0){s1num++;while(!s1);//松手检测if(s1num==1){TR0=0;//TIMESTOPwrite_com(0x80+0x40+
6、10);//指针到miaowrite_com(0x0f);//显示光标}if(s1num==2){write_com(0x80+0x40+7);}if(s1num==3){write_com(0x80+0x40+4);}if(s1num==4){s1num=0;write_com(0x0c);//去光标TR0=1;}}}if(s1num!=0){if(s2==0){delay(5);if(s2==0){while(!s2);//check松手if(s1num==1)//sureatmiao{miao++
7、;if(miao==60)miao=0;write_sfm(10,miao);write_com(0x80+0x40+10);}if(s1num==2)//atfen52021-10-8{fen++;if(fen==60)fen=0;write_sfm(7,fen);write_com(0x80+0x40+7);}if(s1num==3)//atshi{shi++;if(shi==24)shi=0;write_sfm(4,shi);write_com(0x80+0x40+4);}}}if(s3==0){
8、delay(5);if(s3==0){while(!s3);if(s1num==1){miao--;if(miao==-1)miao=59;write_sfm(10,miao);write_com(0x80+0x40+10);}if(s1num==2){fen--;if(fen==-1)fen=59;write_sfm(7,fen);write_com(0x80+0x40+7);}if(s1num==3){shi--;if(shi==-1)
此文档下载收益归作者所有