这是原代码?希望各位大神帮我修改,解决问题- #include <reg51.H>
- sbit k1=P1^0;
- sbit k2=P1^1;
- sbit k3=P1^2;
- sbit k4=P1^3;
- sbit k5=P1^4;
- sbit k6=P1^5;
- sbit k7=P1^6;
- sbit k8=P1^7;
- sbit k_1=P3^0;
- sbit k_2=P3^1;
- sbit k_3=P3^2;
- sbit k_4=P3^3;
- sbit beep=P3^7;
- unsigned int ms; //毫秒
- unsigned int s,t0; //显示值
- unsigned char biaozhi,buzhou=0; //抢答标志,步骤
- unsigned char led[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
- void delay(unsigned int t)//延时
- {
- unsigned int i,j;
- for(i=0;i<t;i++)
- for(j=0;j<110;j++);
- }
- void disp()//显示
- {
- unsigned int ge,shi;
- ge=s%10; //提取个位
- shi=s/10; //提取十位
- P2=0xfe;
- P0=led[ge]; //显示个位
- delay(5);
- P2=0xfd;
- P0=led[shi]; //显示十位
- delay(5);
- }
- void ea()//显示开机界面
- {
- unsigned char ci;
- while(ci<200)//循环200次(持续一段时间)
- {
- P2=0xfe;
- P0=0x77; //显示A
- delay(5);
- P2=0xfd;
- P0=0x79; //显示E
- delay(5);
- ci++;
- }
- }
- void keys() //抢答按键
- { /*抢答之后显示数值,改变标志终止抢答*/
- if(k1==0&&biaozhi==0){s=1;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k2==0&&biaozhi==0){s=2;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k3==0&&biaozhi==0){s=3;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k4==0&&biaozhi==0){s=4;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k5==0&&biaozhi==0){s=5;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k6==0&&biaozhi==0){s=6;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k7==0&&biaozhi==0){s=7;biaozhi=1;beep=0;delay(500);beep=1;}
- if(k8==0&&biaozhi==0){s=8;biaozhi=1;beep=0;delay(500);beep=1;}
- }
- void set_time() //设置时间,一次5秒
- {
- if(k_2==0&&biaozhi==0&&s>0)
- {
- while(k_2==0);
- s-=5;
- }
- if(k_3==0&&biaozhi==0&&s<95)
- {
- while(k_3==0);
- s+=5;
- }
- }
- void main()
- {
- /*配置定时器*/
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- ea();//开机显示EA
- while(1)
- {
- if(buzhou==0) set_time();
- if(k_1==0&&biaozhi==0&&P1==0xff&&s!=0)//开始抢答
- {
- while(k_1==0);
- for(t0=3;t0>0;t0--)
- {
- P2=0xfe;
- P0=led[t0]; //3秒倒计时
- beep=0;delay(80);beep=1;
- delay(1000);
- }
- P2=0xfc;
- P0=0x40;
- beep=0;delay(1000);beep=1;
- buzhou=1;
- TR0=1; //打开定时器开关
- }
- if(P1!=0xff&&buzhou==1&&t0==0) //抢答
- {
- TR0=0;//关闭定时器开关
- keys();
- buzhou=3;
- }
- if(k_4==0) //清除
- {
- beep=k_4;
- while(k_4==0);
- TR0=0;
- s=0;
- biaozhi=0;
- buzhou=0;
- beep=1;
- }
- disp(); //显示
- }
- }
- void zhongduan() interrupt 1
- { /*启动定时器*/
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;//50000=50毫秒
- ms++;
- if(ms==20&&s>0)//50毫秒x20次=1秒
- {
- ms=0;
- s--; //倒计时
- if(s==0)
- {
- TR0=0;
- biaozhi=0;
- buzhou=0;
- beep=0;
- }
- }
- }
复制代码 |