|
代码如下:
#include<reg52.h>
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;
sbit key1=P2^4;
sbit key2=P2^5;
sbit key3=P2^6;
sbit key4=P2^7;
sbit LED1=P0^0;
sbit LED2=P0^1;
sbit LED3=P0^2;
sbit LED4=P0^3;
int main()
{
ENLED=0;
ADDR3=1;
ADDR0=0;
ADDR1=0;
ADDR2=0;
P2=0xFE;
while(1){
LED1=key1;
LED2=key2;
LED3=key3;
LED4=key4;
}
return 0;
}
问题就是:按下k1,k2,k3,k4,并不能控制灯的亮和灭。只有把keyout1端口直接接地,keyout2~4端口接上5V电源才正常。我把照片和附件附上,麻烦各位帮我看看。
|
|