资源描述:
《新手写的多功能电子钟》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、[原创][分享]新手写的多功能电子钟 PostBy:2009-5-2720:33:15刚学的单片机,下面的程序是在学习中断和定时器时写的,已调试通过,多功能电子钟有如下功能:1,可以用来做电子钟2,可以用做报警器(按P3.2时,用做报警)3,可以用做闹钟(按P1.6时,用做闹钟)4,可以显示星期程度当中还有好多的不妥之处,还请高手门帮忙指正.程序如下:(由于注解太多,所以没有能写出来,请见谅!!),制作成功后的图片如附件.内容如下:以下内容只有回复后才可以浏览#include#defineucharunsignedchar#defineuintuns
2、ignedintucharcodedispcode[]={0x81,0x9f,0xa4,0x8c,0x9a,0xc8,0xc0,0x9d,0x80,0x88};ucharcodeDATA[]={0xfc,0x92,0x98,0xac,0x89,0x01,0x5c,0x80,0x88};uchardispbitcode[]={0xfe,0xfd,0xfb,0xf7};uchardispbuf[8]={0,0,0,0};uchardispbitcnt;ucharsecond,minite,hour,day;ucharclockhour,clockminite;uinttcnt;
3、ucharmstcnt;uchart;uinta;//上面的是定义各个变量和数码管缓存voidyanshi(uintt){for(;t>0;t--);}//延时子程序voidbeep(){while(hour4、r(a=0;a<1000;a++){yanshi(5);P1_4=~P1_4;}for(a=0;a<1000;a++){yanshi(5);P1_4=~P1_4;}for(a=0;a<5000;a++){yanshi(6);P1_4=~P1_4;}if(P3_6==0){break;}}}//报警子程序(P1.4接的是BEEP,P3.6为O时跳出)voidbaojing(){if(P1_7==0){yanshi(500);if(P1_7==0){while(1){if(P1_7==1){while(1){beep();if(P3_6==0){break;}}}if(P3_6
5、==0){break;}}}}}//报警执行子程序(用P1.7做信号检测脚,同样当P3.6为0时跳出)voidclock(){if(P3_3==0){yanshi(500);if(P3_3==0){clockminite++;if(clockminite==60){clockminite=0;}dispbuf[3]=clockminite%10;dispbuf[2]=clockminite/10; while(P3_3==0);}}if(P3_6==0){yanshi(500);if(P3_6==0){clockhour++;if(clockhour
6、==24){clockhour=0;}dispbuf[1]=clockhour%10;dispbuf[0]=clockhour/10;while(P3_6==0);}}}//设定闹钟子程序voidkey(){if(P3_6==0){yanshi(500);if(P3_6==0){second++;if(second==60){second=0;} while(P3_6==0);}}if(P3_5==0){yanshi(1000);if(P3_5==0){minite++;if(minite==60){minite=0;}dispbuf[3]=minite
7、%10;dispbuf[2]=minite/10;while(P3_5==0);}}if(P3_7==0){yanshi(500);if(P3_7==0){hour++;if(hour==24){hour=0;}dispbuf[1]=hour%10;dispbuf[0]=hour/10;while(P3_7==0);}}if(P3_4==0){yanshi(500);if(P3_4==0){day++;if(day==7){day=0;}P2=DATA[day];while(P3_4==0);}}}//设定时间子程