各位大佬,这是8位抢答器
目前能实现的功能是:1.按下开始键,开始倒计时10秒(倒计时时间暂停)
2.若有人抢到,蜂鸣器响一声,然后开始20秒答题倒计时
3.倒计时5秒钟蜂鸣器响
4.若选手答对,则按加键给选手加分
5.若选手答错,则主持人按继续键,选手们继续抢答
红色字体部分就是我目前遇到的困难,恳请各位大佬帮忙出出招。
感谢!感谢!万分感谢!
单片机程序如下: #include<reg51.h>
sbit key1=P0^0;
sbit key2=P0^1;
sbit key3=P0^2;
sbit key4=P0^3;
sbit key5=P0^4;
sbit key6=P0^5;
sbit key7=P0^6;
sbit key8=P0^7;
sbit k1=P3^6;
sbit k2=P3^7;
sbit k3=P3^3;
sbit wy=P3^4;
sbit wk_key=P3^5;
sbit ghr_key=P3^2;
bit qd_hd,speaker_permit;
bit grade_hxj;
unsigned char duanma[13]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char fenshu[10]={0,0,0,0,0,0,0,0,0,0};
unsigned char weima[6]={0x01,0x02,0x04,0x08,0x10,0x20};
unsigned char xianshi[6]={0,0,0,0,0,0};
unsigned char saomiao_jishu,jishu2,zuhao=0,f_speaker;
unsigned char miao,fen;
void chushihua (void)
{
zuhao=0; //组号 显示 0,
TMOD=0X11;
EA=1; //设置初值;计时为0。
ET1=1;TR1=1;
ET0=1;TR0=1;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
jishu2=0;
grade_hxj=0;
qd_hd=0;
speaker_permit=1;
}
void dtsm(void) //动态扫描子程序
{
fen=fenshu[zuhao] ;
xianshi[0]=duanma[zuhao/10];
xianshi[1]=duanma[zuhao%10];
xianshi[2]=duanma[miao/10];
xianshi[3]=duanma[miao%10];
xianshi[4]=duanma[fen/10];
xianshi[5]=duanma[fen%10];
saomiao_jishu++;
if(saomiao_jishu==6)
{
saomiao_jishu=0;
}
P2= weima[saomiao_jishu];//位码
P1=xianshi[saomiao_jishu];//段码
}
void preemptive_answer(void) //抢答子程序
{
if(qd_hd==0) //允 许 抢 答
{
if(key1==0)
{
zuhao=1; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key2==0)
{
zuhao=2; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key3==0)
{
zuhao=3; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key4==0)
{
zuhao=4; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key5==0)
{
zuhao=5; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key6==0)
{
zuhao=6; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key7==0)
{
zuhao=7; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
if(key8==0)
{
zuhao=8; miao=20;qd_hd=1;
speaker_permit=0;grade_hxj=1;
}
}
if(k3==0) //按下开始键
{
miao=10;qd_hd=0 ;
}
if(qd_hd==1) //计 数
{
jishu2++;
if(jishu2==100)
{
jishu2=0;
miao--;
if((miao<=19)&&(miao>=6))
{
speaker_permit=1;
}
if((miao<=5)&&(miao>=1))speaker_permit=0;
if(miao==0xff)
{miao=0;
speaker_permit=1;}
}
}
if(wk_key==0) //复 位
{
zuhao=0;
miao=0;
qd_hd=0;
fen=0;
grade_hxj=0;
}
if(grade_hxj==1)
{
if(k1==0) //加 分
{
fenshu[zuhao]=fenshu[zuhao]+1;
fen=fenshu[zuhao];
while(k1==0);
}
}
}
void zd(void) interrupt 3 //蜂鸣 (中断)
{
TH1=(65536-8000)/256;
TL1=(65536-8000)%256;
jishu2++;
if(jishu2==100)
{
jishu2=0;
miao--;
if(miao==0xff)miao=0;
}
if(miao==0)qd_hd=1;
dtsm();
preemptive_answer();
}
void zd1(void) interrupt 1 //蜂鸣(中断)
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
if(speaker_permit==0)
{
ghr_key=~ghr_key;
}
if(wy==0)
{
zuhao++;
if(zuhao==9)
{
zuhao=0;
fen=fenshu[zuhao] ;
}
while(wy==0);
}
}
void main(void)
{
chushihua();
while(1);
}
|