欢迎来到天天文库
浏览记录
ID:48120920
大小:33.50 KB
页数:6页
时间:2020-01-21
《基于51单片机蓝球比赛计时器程序设计.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、基于51单片机蓝球比赛计时器程序设计#includetypedefunsignedcharUINT8;typedefunsignedintUINT16;#defineS10x0e#defineS20x0d#defineS30x0b#defineS40x07UINT8miao_01s=0,Daojishi_24s=24,i=1,j=0,Daojishi_01s=0;UINT8L_C=0,R_C=0,Add=0,Jian=3;UINT16miao=720;sbitSheng=P3^5;bitFlag_over=
2、0;bitFlag_24s=0;UINT8codeSEGMENT[13]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xf6,0xff};UINT8codeSELECT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};voidDelay(UINT16t){UINT16i,j;for(i=0;i3、0x0f)==0x0f)return(0xff);Delay(10);if((P3&0x0f)==0x0f)return(0xff);key=P3&0x0f;while((P3&0x0f)!=0x0f);return(key);}voidBaojing(){UINT8a;for(a=0;a<15;a++){Sheng=0;P1=0xaa;Delay(100);P1=0x55;Delay(100);P3=0xff;P1=0xff;}}voidSystem_init(void){TMOD=0x11;TH0=0x3c;TL0=0x4、b0;TH1=0Xf8;TL1=0X30;TR1=1;IE=0x8a;}voidS_2(){switch(i){case1:TR0=!TR0;Flag_24s=1;break;case2:Add++;Add%=4;break;case3:Jian--;if(Jian==0)Jian=3;break;}}voidS_3(){switch(i){case1:if(j==0){Daojishi_24s=24;Daojishi_01s=0;}elseif(j==1){Daojishi_24s=23;Daojishi_01s=0;Fl5、ag_24s=1;TR0=1;}j++;j%=2;break;case2:L_C+=Add;Add=0;L_C%=1000;break;case3:if((L_C/Jian)>0){L_C-=Jian;Jian=3;L_C%=1000;}break;}}voidS_4(){switch(i){case1:Daojishi_24s=23;Daojishi_01s=9;break;case2:R_C+=Add;Add=0;R_C%=1000;break;case3:if((R_C/Jian)>0){R_C-=Jian;Jian=6、3;}R_C%=1000;break;}}voidmain(){UINT8key;System_init();while(1){key=Scankey();switch(key){caseS1:i++;if(i==4)i=1;break;caseS2:S_2();break;caseS3:S_3();break;caseS4:S_4();break;}if(Flag_over){Baojing();Flag_over=0;}}}voidDisplay(){staticUINT8num=0;UINT8B,D0,D1,D2,D37、,D4,D5,D6,D7;P2=0xff;if(i==1){B=0x7f;D0=Daojishi_01s%10;D1=Daojishi_24s%10;D2=Daojishi_24s/10;D3=12;D4=miao_01s%10;D5=miao%10;D6=miao%100/10;D7=miao/100;}if(i==2){D0=Add;D1=R_C%10;D2=R_C%100/10;D3=R_C/100;D4=10;D5=L_C%10;D6=L_C%100/10;D7=L_C/100;B=0x7f;}if(i==3){D08、=Jian;D1=R_C%10;D2=R_C%100/10;D3=R_C/100;D4=10;D5=L_C%10;D6=L_C%100/10;D7=L_C/100;B=0x7f;}switch(num){case0:P0=SEGMENT[D0];break;case1:P0=SEGMENT
3、0x0f)==0x0f)return(0xff);Delay(10);if((P3&0x0f)==0x0f)return(0xff);key=P3&0x0f;while((P3&0x0f)!=0x0f);return(key);}voidBaojing(){UINT8a;for(a=0;a<15;a++){Sheng=0;P1=0xaa;Delay(100);P1=0x55;Delay(100);P3=0xff;P1=0xff;}}voidSystem_init(void){TMOD=0x11;TH0=0x3c;TL0=0x
4、b0;TH1=0Xf8;TL1=0X30;TR1=1;IE=0x8a;}voidS_2(){switch(i){case1:TR0=!TR0;Flag_24s=1;break;case2:Add++;Add%=4;break;case3:Jian--;if(Jian==0)Jian=3;break;}}voidS_3(){switch(i){case1:if(j==0){Daojishi_24s=24;Daojishi_01s=0;}elseif(j==1){Daojishi_24s=23;Daojishi_01s=0;Fl
5、ag_24s=1;TR0=1;}j++;j%=2;break;case2:L_C+=Add;Add=0;L_C%=1000;break;case3:if((L_C/Jian)>0){L_C-=Jian;Jian=3;L_C%=1000;}break;}}voidS_4(){switch(i){case1:Daojishi_24s=23;Daojishi_01s=9;break;case2:R_C+=Add;Add=0;R_C%=1000;break;case3:if((R_C/Jian)>0){R_C-=Jian;Jian=
6、3;}R_C%=1000;break;}}voidmain(){UINT8key;System_init();while(1){key=Scankey();switch(key){caseS1:i++;if(i==4)i=1;break;caseS2:S_2();break;caseS3:S_3();break;caseS4:S_4();break;}if(Flag_over){Baojing();Flag_over=0;}}}voidDisplay(){staticUINT8num=0;UINT8B,D0,D1,D2,D3
7、,D4,D5,D6,D7;P2=0xff;if(i==1){B=0x7f;D0=Daojishi_01s%10;D1=Daojishi_24s%10;D2=Daojishi_24s/10;D3=12;D4=miao_01s%10;D5=miao%10;D6=miao%100/10;D7=miao/100;}if(i==2){D0=Add;D1=R_C%10;D2=R_C%100/10;D3=R_C/100;D4=10;D5=L_C%10;D6=L_C%100/10;D7=L_C/100;B=0x7f;}if(i==3){D0
8、=Jian;D1=R_C%10;D2=R_C%100/10;D3=R_C/100;D4=10;D5=L_C%10;D6=L_C%100/10;D7=L_C/100;B=0x7f;}switch(num){case0:P0=SEGMENT[D0];break;case1:P0=SEGMENT
此文档下载收益归作者所有