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
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...
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.