51单片机时钟程序_第1页
51单片机时钟程序_第2页
51单片机时钟程序_第3页
51单片机时钟程序_第4页
51单片机时钟程序_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include#includesbit P32=P32;sbit P23=P23;sbit P22=P22;sbit P21=P21;sbit P20=P20;unsigned char x;unsigned char DisBuf8=0,0,0,0,0,0,0,0;unsigned char DisBuf18=0,0,0,0,0,0,0,0;code unsigned char Tab10=0x81,0xed,0x43,0x49,0x2d,0x19,0x11,0xcd,0x01,0x09;unsigned char timer0_count1=0,t1=0;/unsigned char timer0_count3=0,t3=0;unsigned char timer0_count2=0;unsigned char Second=0,Minute=0;unsigned int Year=17;unsigned int Month=01;unsigned int Day=02;unsigned int Hour=14;unsigned char a1=0;unsigned int mond=1;/显示模式unsigned int a=9;/倒计时初试时间unsigned int b=60;void mDelay(unsigned int delay) unsigned char i; for(;delay0;delay-) for(i=0;i1000) P32=!P32; timer0_count2=0; if(mond=4) b-; if(b59) Second=0; Minute+; if(Minute59) Minute=0; Hour+; if(Hour24) Hour=0; Day+; if(Day30) Day=0; Month+; if(Month12) Month=0; Year+; DisBuf0=Minute/10; DisBuf1=Minute%10; DisBuf2=Second/10; DisBuf3=Second%10; DisBuf4=Day/10; DisBuf5=Day%10; DisBuf6=Hour/10; DisBuf7=Hour%10; DisBuf10=Year/10; DisBuf11=Year%10; DisBuf12=Month/10; DisBuf13=Month%10; DisBuf14=a/10; DisBuf15=a%10; DisBuf16=b/10; DisBuf17=b%10; if(mond=1)/分秒显示 timer0_count1+;if(timer0_count15) timer0_count1=0; t1+; if(t13) t1=0; switch(t1) case0:P0=TabDisBuf0; P2=P2|0x80;P2=P2&0x8f; break; case1:P0=TabDisBuf1; P2=P2|0x40;P2=P2&0x4f; break; case2:P0=TabDisBuf2; P2=P2|0x20;P2=P2&0x2f; break; case3:P0=TabDisBuf3; P2=P2|0x10;P2=P2&0x1f; break; default: break; else if(mond=2)/天时显示 timer0_count1+;if(timer0_count15) timer0_count1=0; t1+; if(t13) t1=0; switch(t1) case0: P0=TabDisBuf4; P2=P2|0x80;P2=P2&0x8f; break; case1:P0=TabDisBuf5; P2=P2|0x40;P2=P2&0x4f; break; case2:P0=TabDisBuf6; P2=P2|0x20;P2=P2&0x2f; break; case3:P0=TabDisBuf7; P2=P2|0x10;P2=P2&0x1f; break; default: break; else if(mond=3)/年月显示 timer0_count1+;if(timer0_count15) timer0_count1=0; t1+; if(t13) t1=0; switch(t1) case0:P0=TabDisBuf10; P2=P2|0x80;P2=P2&0x8f; break; case1:P0=TabDisBuf11; P2=P2|0x40;P2=P2&0x4f; break; case2:P0=TabDisBuf12; P2=P2|0x20;P2=P2&0x2f; break; case3:P0=TabDisBuf13; P2=P2|0x10;P2=P2&0x1f; break; default: break; else if(mond=4)/倒计时 timer0_count1+;if(timer0_count15) timer0_count1=0; t1+; if(t13) t1=0; switch(t1) case0:P0=TabDisBuf14; P2=P2|0x80;P2=P2&0x8f; break; case1:P0=TabDisBuf15; P2=P2|0x40;P2=P2&0x4f; break; case2:P0=TabDisBuf16; P2=P2|0x20;P2=P2&0x2f; break; case3:P0=TabDisBuf17; P2=P2|0x10;P2=P2&0x1f; break; default: break; void main() unsigned char Keynumber=0,Keytemp=0; TMOD=0x01; TH0=0xfc;TL0=0x66; TR0=1; IE=0x82; while(1) P1&=0x0f;if(P2&0x0f)!=0x0f)/有键按下 mDelay(5); if(!P23) P1&=0x7f;P1|=0x70; if(!P23)Keynumber=1; else P1&=0xbf;P1|=0xb0; if(!P23)Keynumber=2; else P1&=0xdf;P1|=0xd0; if(!P23)Keynumber=3; else P1&=0xef;P1|=0xe0; if(!P23)Keynumber=4; else Keynumber=20; else if(!P22) P1&=0x7f;P1|=0x70; if(!P22)Keynumber=5; else P1&=0xbf;P1|=0xb0; if(!P22)Keynumber=6; else P1&=0xdf;P1|=0xd0; if(!P22)Keynumber=7; else P1&=0xef;P1|=0xe0; if(!P22)Keynumber=8; else Keynumber=20; else if(!P21) P1&=0x7f;P1|=0x70; if(!P21)Keynumber=9; else P1&=0xbf;P1|=0xb0; if(!P21)Keynumber=10; else P1&=0xdf;P1|=0xd0; if(!P21)Keynumber=11; else P1&=0xef;P1|=0xe0; if(!P21)Keynumber=12; else Keynumber=20; else if(!P20) P1&=0x7f;P1|=0x70; if(!P20)Keynumber=13; else P1&=0xbf;P1|=0xb0; if(!P20)Keynumber=14; else P1&=0xdf;P1|=0xd0; if(!P20)Keynumber=1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论