预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

51单片机时钟代码(带秒表闹钟功能)#include#include#defineucharunignedchar#defineuintunignedintbitbeep=P1^5;//蜂鸣器灯使能端bitr=P2八6;//1602bitrw=P2八5;//1602bit0二P3八4;//停止闹铃和小灯bit1二P3八5;//功能键bit2二P3飞;//增大键bit3二P3X;//减小键bit4二P3「;//bit5=P3^2;bit6二P3八3;bit7=P3^0;uchar1num,4num,count,count1,judge=0;charec,min,hour,miao,fen,hi,ec1,min1,diwei;voiddelay(uintz){uint某,y;for(某二z;某〉0;某--)for(y=100;y〉0;y—);}voiddi(){beep=0;delay(50);beep=1;}bitlcd_bz()//测试LCD忙碌状态{bitreult;r=0;rw=1;ep=1;_nop_();_nop_();_nop_();_nop_();reult=(bit)(P0&0某80);ep=0;returnreult;}_nop_();_nop_();_nop_();ep=1;_nop_();_nop_();_nop_();_nop_();ep=0;}voidwrite_data(uchardat)//写入字符显示数据到LCD{while(lcd_bz());//等待LCD空闲r=1;rw=0;ep=0;P0=dat;_nop_();_nop_();_nop_();_nop_();ep=1;_nop_();_nop_();_nop_();_nop_();ep=0;}ucharhi,ge;hi=dat/10;ge=dat;write_data(0某30+hi);write_data(0某30+ge);}voidwrite_alarm(ucharadd,uchardat){ucharhi1,ge1;hi1=dat/10;ge1=dat;count=0;//clearwrite_data('A');delay(5);hi=17;voidkeycan()//按键扫描{if(l==0){delay(5);if(1==0){1num++;while(!1);di();if(1num==1){TR0=0;if(1num==2){if(1num==3){if(1num==4){1num=0;if(1num!=0){if(2==0){delay(5);if(2==0){while(!2);di();if(1num==1){ec++;if(ec==60)ec=0;if(1num==2){min++;if(min==60)min=0;if(1num==3){hour++;if(hour==24)hour=0;delay(5);if(3==0){while(!3);di();if(1num==1){ec--;if(ec<0)ec=59;if(1num==2){min--;if(min<0)min=59;hour--;if(hour<0)hour=23;}voidkeycan1(){if(4==0){delay(5);if(4==0){4num++;while(!4);di();if(4num==1){TR0=0;if(4num==2){if(4num==3){if(4num==4){if(4num!=0){if(5==0){delay(5);if(5==0){while(!5);di();if(4num==1){miao++;if(miao==60)miao=0;write_alarm(10,miao);if(4num==2){fen++;if(fen==60)fen=0;if(4num==3){hi++;if(hi==24)hi=0;write_alarm(4,hi);if(6==0){delay(5);if(6==0){while(!6);di();if(4num==1){miao--;if(miao<0)miao=59;if(4num==2){fen--;if(fen<0)fen=59;write_alarm(7,fen);if(4num==3){hi--;if(hi<0)hi=23;}}if(7==0){delay(5);if(7==0){while(!7)di();judge++;}}if(judge==2){TL0=0某b0;TH0=0某3c;{ec=0;min++;if(min==60){min=0;hour++;if(hour==24){hour=0;}}}}}if(judge==3){judge=0;ec1=0;mi