I have build a project using AT89S51 and comparator LM324. The input to uC is from comparator that the inverting input is connected to infrared sensor and the non-inverting input set as the voltage reference (Vr). For certain distance the output voltage from infrared sensor is higher than the Vr so that the output from comparator is low and otherwise. This output is connected to P1.0, and a led is connected to P3.0. My intention is to make the led on when the output from comparator is low and led off when the output from comparator is high. However, when I test it the led is only on or off for once after I power on my uC even I already made loop in source code. Can anybody help me to fix this problem?
The circuit is
The port pin P1.0 has to be configured as input first. SETB P1.0 will make it high and configure it as input port pin. Try this. This should go in the beginning.
Ya, it works after I set P1.0 high in the beginning. Thanks for the suggestions.
- - - Updated - - -
It works when I use power supply as inverting input to comparator. The led is on and off every time I vary the input voltage lower or higher than voltage reference. However, when the inverting input is from infrared sensor the led is always on and never off even though the output voltage from comparator is low. I use infrared sensor from sh*rp.