【51单片机】按钮开关控制实验代码

2019-04-15 19:00发布

//按钮开关控制实验 #include sbit PB1 = P3^1; sbit PB2 = P3^0; sbit LED = P2^0; void main() { LED = 1; //关闭LED灯 PB1 = PB2 = 1; //设置按钮初始值 while(1) { if (PB1 == 0) LED = 0; //按下PB1开灯 else if (PB2 == 0) LED = 1; //按下PB2关灯 } }