kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,482
Hello guys
I'm have a rotary encoder hooked up to an Arduino UNO and trying to write a code to turn on a led1 if it turns clockwise, otherwise a led2 if it turns counterclockwise.
I'm found a lot of c code online to make this work, but I want to implement it first in assembly, so I can understand how it works fully (so please no negative comment why I'm using assembly in 2021)
This is my code, and my problem is I'm getting only one direction.
The idea behind my code is:
When I rotate the RE it sends an interrupt to PD2 Pin on a falling edge, then in the ISR, I check the signal B (PD3 pin), if it's high, it means that the RE is turned clockwise, otherwise it is turned counterclockwise.
I know I'm missing something, and I would appreciate if someone can help me to fix this code!
Thank you in advance!
I'm have a rotary encoder hooked up to an Arduino UNO and trying to write a code to turn on a led1 if it turns clockwise, otherwise a led2 if it turns counterclockwise.
I'm found a lot of c code online to make this work, but I want to implement it first in assembly, so I can understand how it works fully (so please no negative comment why I'm using assembly in 2021)
This is my code, and my problem is I'm getting only one direction.
The idea behind my code is:
When I rotate the RE it sends an interrupt to PD2 Pin on a falling edge, then in the ISR, I check the signal B (PD3 pin), if it's high, it means that the RE is turned clockwise, otherwise it is turned counterclockwise.
I know I'm missing something, and I would appreciate if someone can help me to fix this code!
Thank you in advance!
Code:
;Rotary encoder hoocked up to an Arduino Uno.Signal A is going to pin INt0 and signal B is going to pin pd3.If the Rotary encoder is turned clock wise, Led 1 ( PC0) is turned ON, if turned CCW then led 2 ( PC1) is turn on.
.device Atmega328P
.org 0x0
jmp main
.org 0x002
jmp int0_isr
main:
sbi ddrc,0
sbi ddrc,1
sbi portd,2 ; pull up resistor on Pd2
sbi portd,3; pull up resistor on Pd3 ; B signal
cbi ddrd,3
cbi ddrd,2
ldi r16,0x01 ;Int0 enabled
out eimsk,r16
ldi r16,0x02 ; falling edge
sts eicra,r16
sei
loop:
rjmp loop
.org 0x100
int0_isr:
sbis portd,3
rjmp ccw
sbi portc,1
cbi portc,0
rjmp exit
ccw:
sbi portc,0
cbi portc,1
exit:
reti