模拟开关灯实验:编程实现2个开关控制1个灯的亮,灭,C语言

2025-03-18 12:51:41
推荐回答(1个)
回答1:

sbit B1=P2^0;
sbit B2=P2^1;
sbit LED=P1^1;
void delay(){
unsigned int a=3000;
while(a--){
;
}
}
void delay1(){
unsigned int a=2000;
while(a--){
;
}
}
main(){

while(1){
if(B1==0){
delay1();
if(B1==0){
LED=1;
}
}

if(B2==0){
delay1();
if(B2==0){
LED=0;
}
}

}
}