html抢答器代码,单片机八路抢答器代码+Proteus仿真
#include
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
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;
}
}
}
總結
以上是生活随笔為你收集整理的html抢答器代码,单片机八路抢答器代码+Proteus仿真的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “import gaminet”,出现报
- 下一篇: 【Bug】AttributeError: