#include
#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=0;i<200;i++)
for(j=0;j<250;j++);
}
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=1;break;
case 0x02:i=2;break;
case 0x04:i=3;break;
case 0x08:i=4;break;
case 0x10:i=5;break;
case 0x20:i=6;break;
case 0x40:i=7;break;
case 0x80:i=8;break;
default:break;
}
P1=table[i];//显示按下抢答器的号
P0=key;//显示按下键号的LED
while(1)
{
if(rstkey==0)break;//主持人按下复位键则重新开始
speaker=~speaker;//否则蜂鸣器报警
delay();
}
}
}
你好!是仿真实现效果吗?程序什么时间要?