c51八路抢答器代码
时间: 2023-11-12 20:57:23 浏览: 93
以下是c51八路抢答器的代码:
```c
#include <reg52.h>
sbit KEY1 = P3^2;
sbit KEY2 = P3^3;
sbit KEY3 = P3^4;
sbit KEY4 = P3^5;
sbit KEY5 = P3^6;
sbit KEY6 = P3^7;
sbit KEY7 = P2^0;
sbit KEY8 = P2^1;
unsigned char code table[] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
void delay(unsigned int i)
{
while(i--);
}
void main()
{
unsigned char i = 0;
while(1)
{
if(KEY1 == 0)
{
delay(1000);
if(KEY1 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY1);
}
if(KEY2 == 0)
{
delay(1000);
if(KEY2 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY2);
}
if(KEY3 == 0)
{
delay(1000);
if(KEY3 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY3);
}
if(KEY4 == 0)
{
delay(1000);
if(KEY4 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY4);
}
if(KEY5 == 0)
{
delay(1000);
if(KEY5 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY5);
}
if(KEY6 == 0)
{
delay(1000);
if(KEY6 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY6);
}
if(KEY7 == 0)
{
delay(1000);
if(KEY7 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY7);
}
if(KEY8 == 0)
{
delay(1000);
if(KEY8 == 0)
{
P1 = table[i];
i++;
if(i == 8)
{
i = 0;
}
}
while(!KEY8);
}
}
}
```
阅读全文