i don't know if will be handy but here's a snip of my encoder routine
Code:
GetEncoder:
'
OldPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
NewPos = OldPos
' see if encoder has move
'
while ((NewPos==0) or (NewPos==3))
NewPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
wend
pause 20 ' debounce delay
' Get encoder movement
' --------------------
'
' Rotary encoder output table (clockWise rotation):
' -------------------------------------------------
' 00
' 01 between move (half detent)
' 11
' 10 between move (half detent)
'
' Using XOR
'
' OldPOS : 0 0 3 3
' NewPos : 1 2 1 2
' movement : CW CCW CCW CW
' XOR -------------------------------
' 1 2 2 1
'
' So, if NewPos XOR OldPos = 1 => increment
' Newpos XOR OldPos = 2 => Decrement
'
Newpos=newpos ^ oldpos
select case newpos
case 1
Menupointer=menupointer+1
case 2
Menupointer=menupointer-1
end select
Yeah i know, more comments than code but.. i like it
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks