# Assembly code for switching led using comparator

Status
Not open for further replies.

#### giordano

##### Newbie level 5
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

Code:
	ORG 0H
START:
MOV A,P1
CJNE A,#0FEH,LED_OFF
LED_ON:
CLR P3.0
SJMP START
LED_OFF:
SETB P3.0
SJMP START
END

#### internetuser2k12

##### Banned
Where is the infrared input to the comparator?

O/P from comparator is low and led is on. How are you making O/P of comparator high without infrared input.

#### jjeevan007

##### Full Member level 5
i think u should use the push button in parallel with capacitor in reset circuit, so that reset can occur and starts executing properly.........

#### giordano

##### Newbie level 5
Where is the infrared input to the comparator?

O/P from comparator is low and led is on. How are you making O/P of comparator high without infrared input.
I already show it in the picture, corner left side

- - - Updated - - -

i think u should use the push button in parallel with capacitor in reset circuit, so that reset can occur and starts executing properly.........
It means I have to push the button frequently. I want to reset it only once

#### jjeevan007

##### Full Member level 5
only once to start the operation................

#### ark5230

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.

V
points: 2

#### giordano

##### Newbie level 5
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.