欢迎来到天天文库
浏览记录
ID:40722142
大小:39.00 KB
页数:6页
时间:2019-08-06
《电子钟的源程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#includeunsignedcharcodechangled[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f};unsignedcharled[6];unsignedcharpresent_time[3];unsignedcharflash=0;unsignedchartimemeasure=0;unsignedcharflash_cs=0;unsignedchartiaozheng=0;bitenablebit
2、=0;unsignedintenabletime=0;sbitP1_0=P1^0;sbitP1_1=P1^1;sbitP1_2=P1^2;sbitP1_3=P1^3;voidchange_data()//调整时间{unsignedcharx,change;x=present_time[0];change=x/100;x=present_time[0];led[0]=x/10-change*10;x=present_time[0];led[1]=(unsignedchar)(x-change*10
3、0-led[0]*10);x=present_time[1];change=x/100;x=present_time[1];led[2]=x/10-change*10;x=present_time[1];led[3]=(unsignedchar)(x-change*100-led[2]*10);x=present_time[2];change=x/100;x=present_time[2];led[4]=x/10-change*10;x=present_time[2];led[5]=(unsig
4、nedchar)(x-change*100-led[4]*10);}voidinit(){present_time[0]=12;present_time[1]=00;//默认时间present_time[2]=00;xiao[0]=23;xiao[1]=00;//亮一半时间xiao[2]=00;}T0_in()interrupt1using3{unsignedcharbb;flash++;enabletime++;if(flash==15){flash=0;if(flash_cs==0)P2=2
5、54;if(flash_cs==1)P2=253;if(flash_cs==2)P2=251;if(flash_cs==3)P2=247;if(flash_cs==4)P2=239;if(flash_cs==5)P2=223;bb=led[flash_cs];P0=changled[bb];if(flash_cs!=5)flash_cs++;elseflash_cs=0;}if(enabletime==555){enabletime=0;enablebit=1;}}T1_in()interrup
6、t3using3{TH1=(65535-40000)/256;TL1=(65536-40000)%256;TR1=1;timemeasure++;if(timemeasure==25){timemeasure=0;if(present_time[2]<59){present_time[2]++;}else{present_time[2]=0;if(present_time[1]<59)present_time[1]++;else{present_time[1]=0;if(present_time
7、[0]<23)present_time[0]++;elsepresent_time[0]=0;}}if(tiaozheng<=3){change_data();}}}main(){unsignedchardengstate=0;P3=0;ET0=1;ET1=1;TMOD=0x12;TH0=0;TL0=0;TR0=1;TH1=(65535-40000)/256;TL1=(65536-40000)%256;TR1=1;EA=1;while(1){if(P1_0==0)if(enablebit==1)
8、{enablebit=0;enabletime=0;tiaozheng++;if(tiaozheng>0)if(tiaozheng<=3)change_data();if(tiaozheng==10){tiaozheng=0;P3=0;}if(P1_2==0)if(enablebit==1){enablebit=0;enabletime=0;if(tiaozheng==1){if(present_time[0]<23)present_time[0]++;elsepresent_time[0]=0
此文档下载收益归作者所有