第1个回答 2013-06-08
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint z);
void main()
{
uchar a;
a=0x00;
P0=0x00;//P0输出; led共阴接法 P1输入按键另一端接地 P0加上拉电阻
P1=0xff;
while(1)
{
P0=0x00;
if(P1!=0xff)
{
a=P1;
switch(a)
{
case 0xfe: P0=0x01;delay(3000);break;
case 0xfd: P0=0x02;delay(3000);break;
case 0xfb: P0=0x04;delay(3000);break;
case 0xf7: P0=0x08;delay(3000);break;
case 0xef: P0=0x10;delay(3000);break;
case 0xdf: P0=0x20;delay(3000);break;
case 0xbf: P0=0x40;delay(3000);break;
case 0x7f: P0=0x80;delay(3000);break;
}
}
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}