在51单片机的p1口上面接8个独立按键,咱们能够依照如下的思路来检测按键.
#include
main()
{
unsigned char sw;
//unsigned char P1;
//unsigned char P3;
unsigned int t;
while(1)
{
sw=P3|0xf0;
switch(sw)
{
case 0xfe:P1=0xfe;
break ;
for (t=0;t<<60000;t++);
case 0xfd:P1=0xf9;
for (t=0;t<<60000;t++);
break;
case 0xfb:P1=0xc7;
break;
case 0xf7:P1=0x0f;
for (t=0;t<<60000;t++);
break;
default: P1=0xff;
for (t=0;t<<60000;t++);
break;
}
}
}