Hello mister_e
Thanks for the nice code.... and comments also
I think I found my way of how to use these evil rotary encoders...
Now, I don't know how to explain this very well, but I think the code will do..
Code:
@ DEVICE PIC16F84A, XT_OSC, PWRT_ON, PROTECT_OFF, WDT_ON
TRISA = 3
TRISB = 0
PORTA = 0
PORTB = 0
NEW VAR BYTE
OLD VAR BYTE
TEMP VAR BYTE
DIRECTION VAR BIT
INIT:
TEMP = PORTA
NEW = TEMP & 3 ' PortA<1,0> only required as inputs<B,A>
START:
OLD = NEW
BEGIN:
TEMP = PORTA ' Read the new value to see if changed
NEW = TEMP & 3
IF NEW == OLD THEN BEGIN ' If not changed, keep reading
DIRECTION = NEW.1 ^ OLD.0 ' XOR left bit of new and right bit of old
IF DIRECTION = 1 THEN CLOCKWISE
COUNTERCLOCKWISE:
'
'
GOTO START
CLOCKWISE:
'
'
GOTO START
I tested this code with a mouse wheel, and it worked perfectly without any problems, I used 7 segment display to monitor the results. Tomorrow I will order the rotary encoder, and see if it also works as I intended...
This method prevents double stepping each time the nob is rotated, try it guys, and tell me what is your experience like...





Bookmarks