资源描述:
《单片机电子钟的完整源程序12m晶振》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintsbitkey11=P3^3;sbitkey12=P3^4;sbitkey13=P3^5;sbitled14=P1^4;sbitled15=P1^5;unsignedcharcodetable[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x
2、00,0x10};//unsignedcharcodetable[]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60,008H,05EH,082H,042H,054H,041H,001H,05AH,000H,040H};//我自己板子的字库ucharhou1,hou2,min1,min2,flag;uchari,j,k,l;uinttt,tt2;voidinit();voidkeyscan();voidcount();voiddisplay(uchar,u
3、char,uchar,uchar);voiddelay(uint);main(){init();while(1){while(flag==0)//时钟运行状态{keyscan();count();display(hou1,hou2,min1,min2);if(i==k&&j==l){led14=0;}if(tt%20==15)led15=0;if(tt%20==19)led15=1;}while(flag==1)//时钟分钟设定状态{TR0=0;keyscan();count();display(hou1,h
4、ou2,min1,min2);}while(flag==2)//时钟小时设定状态{keyscan();count();display(hou1,hou2,min1,min2);}while(flag==3)//闹钟分钟设定状态{keyscan();count();display(hou1,hou2,min1,min2);}while(flag==4)//闹钟小时设定状态{keyscan();count();display(hou1,hou2,min1,min2);}}}voidinit(){i=12;j=0;
5、k=6;l=0;hou1=1;hou2=2;min1=0;min2=0;flag=0;TMOD=0X11;//定时器01设置方式1一次时间0.05s .01sTH0=(65536-50000)/256;TL0=(65535-50000)%256;TH1=(65536-20000)/256;TL1=(65535-20000)%256;EA=1;//开总中断ET0=1;//开定时器0中断ET1=1;//开定时器1中断EX0=1;//开外部中断0TR0=1;//定时器0开始工作TR1=1;//定时器1开始工作I
6、T0=1;//外部中断下降沿触发}voidkeyscan()//扫描独立键盘{if(key11==0){delay(1);if(key11==0)//消抖{flag++;if(flag==5){flag=0;TR0=1;}while(!key11)//等待按键释放{count();display(hou1,hou2,min1,min2);}}}if(flag==1)//此后为时钟设定分钟扫描{if(key12==0){delay(1);if(key12==0)//消抖{j++;while(!key12)//等
7、待按键释放{count();display(hou1,hou2,min1,min2);}}}if(key13==0){delay(1);if(key13==0)//消抖{j--;while(!key13)//等待按键释放{count();display(hou1,hou2,min1,min2);}}}}if(flag==2)//此后为时钟设定小时扫描{if(key12==0){delay(1);if(key12==0)//消抖{i++;while(!key12)//等待按键释放{count();display
8、(hou1,hou2,min1,min2);}}}if(key13==0){delay(1);if(key13==0)//消抖{i--;while(!key13)//等待按键释放{count();display(hou1,hou2,min1,min2);}}}}if(flag==3)//此后为闹钟设定分钟扫描{if(key12==0){delay(1);if(key12==0)//消抖{l++;wh