hi I am pretty much new with the 89C51 (atmel 89C51). I am trying to turn on LED with the switch. I can turn on one LED but when i try to turn on two LED it does not work. Right now both the LED turns on with the same switch. But i want to turn on the two LED with two different switch. my program is as follows sbit DIPswitch1=P1^4; sbit DIPswitch2=P1^3; sbit greenLED1=P1^5; sbit greenLED2=P1^6; void main(void) { while(1) { if (DIPswitch1==1) greenLED1=0; else greenLED1=1; } { if (DIPswitch2==1) greenLED2=0; else greenLED2=1; } Any help will be appreciated thanx
Try this:
sbit DIPswitch1=P1^4; sbit DIPswitch2=P1^3; sbit greenLED1=P1^5; sbit greenLED2=P1^6; void main(void) { while(1) { if (DIPswitch1==1) greenLED1=0; else greenLED1=1; if (DIPswitch2==1) greenLED2=0; else greenLED2=1; }
When posting code, please follow the instructions given when you create the post: "Place source code source code between <pre> and </pre>" Then the layout of your code will be preserved, and your problem becomes obvious:
sbit DIPswitch1=P1^4; sbit DIPswitch2=P1^3; sbit greenLED1=P1^5; sbit greenLED2=P1^6; void main(void) { while(1) { if (DIPswitch1==1) greenLED1=0; else greenLED1=1; } // This brace closes the 'while'!! { if (DIPswitch2==1) greenLED2=0; else greenLED2=1; }
while(1) { greenLED1 = !DIPswitch1; greenLED2 = !DIPswitch2; }