i use at89c2051 micro controller there is a problem with reading the pin value after declaring pin 1(input pin)......controller gives wrong execution...
i already declare pin as a input pin i also place meaningfull part of code..
i also do simulation for same in proteus it work ok but it is not work in real hardware,also there is not any problem in hardware please suggest what to do....
the problem is that both part is executed in superloop (while(1)) here auto is switch
#define ON 0 #define OFF 1 sbit AUTO=P3^4; sbit LED1=P1^0; sbit LED2=P1^1; void main() { unsigned char event,mevent; AUTO=1;LED1=0;LED2=0; if(AUTO==ON) {event=0;} else if(AUTO==OFF) {event=1;} while(1) { if(AUTO==ON) {LED1=ON;} else if(AUTO==OFF) {LED2=ON;} } }
Very simple code. You could try it in the uVision simulator.
I don't much like code that can turn on a LED but not turn it off. Or who can turn off a LED but not turn it on.
Somehow, I feel there is a logic error introduced somewhere in the thought process.
yes per, i also not like such a code...which only turn on led......and also not like code which turn on led wrongly without taking care of pin reading value.....and that's why i posted a problem.