第1个回答 2014-10-27
#include<reg51.h>
#define uchar unsigned char
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
uchar LED=0xfe;
void delay(uchar a)
{
uchar i,j;
for(i=0;i<a;i++)
for(j=0;j<120;j++);
}
main()
{
P0=0xff;
while(1)
{
while(key1==0){P0=0x00;delay(200);P0=0xff;delay(200)}
while(key2==0){P0=0xff;}
while(key3==0){P0=LED;LED=(LED<<1)|0x01;if(LED==0xff)LED=0xfe;delay(200);}
while(key4==0){P0=LED;LED=(LED>>1)|0x80;if(LED==0xff)LED=0x7f;delay(200);}
}
}本回答被网友采纳