51单片机按键控制LED灯的亮灭

    技术2022-07-10  108

    通过两个按键来控制2个lded的灭亮 按一下灯亮在按一下灯灭

    #include <reg52.h> //位绑定操作 sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; sbit LED1 = P0^0; sbit LED2 = P0^1; //按键绑定 sbit KEY1 = P2^4; sbit KEY2 = P2^5; sbit KEYOUT1 = P2^3; //主函数 void main() { ENLED = 0; ADDR3 =1; ADDR2 =1; ADDR1 =1; ADDR0 =0; //要把KEYOUT1设为底电平 KEYOUT1 = 0; while (1) { LED1 = KEY1; LED2 = KEY2; } }
    Processed: 0.097, SQL: 9