電路功能:電路可實(shí)現(xiàn)9路搶答器功能,一人按下后,其他人再按無效,需復(fù)位后方可重新?lián)尨稹?/p>本文引用地址:http://m.butianyuan.cn/article/201611/320569.htm
下圖為Proteus仿真圖:
下圖為原理圖:
下圖為PCB圖:
下圖為實(shí)物圖,手機(jī)拍攝 ,不是很清晰
以下為源程序:
#include
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={ //不帶小數(shù)點(diǎn)的數(shù)碼管編碼
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90};
uchar num;
sbit beep=P3^6;
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 k9=P3^0;
void keyscan();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=5000;y>0;y--);
}
void main()
{
while(1)
{
keyscan();
}
}
void keyscan()
{
P0=0xc0;
P2=0xfe;
if(k1==0)
{
beep=0;
delay(5);
beep=1;
P0=table[1];
delay(10000);
}
else if(k2==0)
{
beep=0;
delay(5);
beep=1;
P0=table[2];
delay(10000);
}
else if(k3==0)
{
beep=0;
delay(5);
beep=1;
P0=table[3];
delay(10000);
}
else if(k4==0)
{
beep=0;
delay(5);
beep=1;
P0=table[4];
delay(10000);
}
else if(k5==0)
{
beep=0;
delay(5);
beep=1;
P0=table[5];
delay(10000);
}
else if(k6==0)
{
beep=0;
delay(5);
beep=1;
P0=table[6];
delay(10000);
}
else if(k7==0)
{
beep=0;
delay(5);
beep=1;
P0=table[7];
delay(10000);
}
else if(k8==0)
{
beep=0;
delay(5);
beep=1;
P0=table[8];
delay(10000);
}
else if(k9==0)
{
beep=0;
delay(5);
beep=1;
P0=table[9];
delay(10000);
}
}
評(píng)論