单片机编程设计要求如下:在单片机的P0口接有8个发光二极管作为指示灯,P1.0~P1.3接有4个按键

2024-12-12 19:32:37
推荐回答(3个)
回答1:

#include
#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;ifor(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);}

}

}

回答2:

上图,没图不好写。

回答3:

给你做proteus仿真吗?
还是要实物?