Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] read optocoupler sensor using at89c55wd in assembly

Status
Not open for further replies.

fer_yana

Member level 1
Joined
Dec 16, 2011
Messages
38
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Indonesia
Activity points
1,505
I need to read optocoupler sensor using my controller at89c55wd. How can i do it in assembly?
 

what type of optocoupler?
if you use PC817 or similar, its just a LED and NPN phototransistor in a DIP4 package. if the led is shining to the phototransistor, the phototransistor conduct.
connect the phototransistor`s emitor to ground and collector to VCC via a pullup resistor. when the phototransistor conduct, you will see LOW on collector, and vice versa. connect this to external interrupt of the microcontroller to generate interrupt and execute the interrupt routine..hope this help
 

Can i connect optocoupler sensor into input port such as p0?
 

of course you can...just provide with pullup resistor so the pin dont floating and false triggering
 

well i`m no expert in assembly, but i will give you a hint
suppose you want a counter using optocoupler.

1. take output of optocoupler to micro pin. this is active low.
2. define a variable to store the count.
3. scan the pin associated with optocoupler to detect a transition from high to low.
4. when the pin change state from high to low add +1 to the variable.
5. back to point 3 to do the scan again.

or..

you can feed optocoupler output to external interrupt of microcontroller to interrupt the routine, and enter the interrupt service routine..

now its your part to translate it out into the assembly language...:D
 

can you give me example code in other language such as c,pascal or basic. So i can learn.
 

this is basic program, you can improve the program i.e store the count to eeprom, or send the counting value via rs232 or 485 etc etc

Code:
dim countvariable as word              'store the counting value

P0.0 = 1   'initializing the port0 pin 0

while true             'loop forever

if P0.0 = 0 then     'if the low transition from the optocoupler detected then
countvariable = countvariable + 1        'add +1 to the count variable
     do
     nop
     loop until P0.0 = 1   'make sure the countvariable is receive 1 pulse per count and wait until the pulse is high, if not the countvariable keep adding up as long as the pulse is low

end if

wend


end.
 
Last edited:

I have 2 optocouplers to read. Work like digital volume encoder and have 2 patterns for up dan down counting

Up counting pattern:
sensor1 sensor2
High Low
High High
Low High
Low Low

down counting pattern:
Low high
High High
High Low
Low Low

Can you give me some code example for it?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top