#include<reg51.h>
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f}
sbit rstkey=P2^2
sbit speaker=P2^0
void delay()//延时约400毫秒
{
uchar i,j
for(i=0i<200i++)
for(j=0j<250j++)
}
main()
{
uchar i,key
P2=0xff
while(1)
{
i=0
P1=table[i]
while(1)
{
key=P3
if(key!=0)break
}
switch(key)
{
case 0x01:i=1break
case 0x02:i=2break
case 0x04:i=3break
case 0x08:i=4break
case 0x10:i=5break
case 0x20:i=6break
case 0x40:i=7break
case 0x80:i=8break
default:break
}
P0=key//显示按下键号的LED
while(1)
{
if(rstkey==0)break//主持人按下复位键则重新开始
speaker=~speaker//否则蜂鸣器报警
delay()
}
}
}
#include<reg52.h>#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f}
sbit rstkey=P3^7
main()
{
uchar i,key
while(1)
{
P2=0xff
i=0
P0=table[i]
while(1)
{
key=P1
if(key!=0xff)break
}
switch(~key)
{
case 0x01:i=1break
case 0x02:i=2break
case 0x04:i=3break
case 0x08:i=4break
case 0x10:i=5break
case 0x20:i=6break
case 0x40:i=7break
case 0x80:i=8break
default:break
}
P0=table[i]//显示按下抢答器的号
P2=key//显示按下键号的LED
while(1)
{
if(rstkey==0)break//主持人按下复位键则重新开始
}
}
}
就是一个逻辑问题了if qiangda==1 then
count--
if count<5
moudeng=1
fi
if !first||!second&&||!third||..
tingzhidaojishi=1
关闭中断
查询端口看看谁按的键
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)