Update code :
Code:
Main_Loop:
gosub keypadscan
newState = (PortB & %00000111)
gosub encoder
gosub check
goto main_loop
Check :
if dir = up then
porta.0 = 0
porta.1 = 1
endif
if dir = dn then
porta.0 = 1
porta.1 = 0
endif
return
encoder:
If newState <> 0 THEN
If newState <> oldState THEN ' Changed from last time?
Select Case oldState
Case 32
If NewState = 128 THEN ' Was 1 now 4 = Up
Q_Count = Q_Count + 1
DIR = UP
ELSE ' Was 1 now 2 = Down
Q_Count = Q_Count - 1
DIR = DN
ENDIF
Case 64
If NewState = 32 THEN ' Was 2 now 1 = Up
Q_Count = Q_Count + 1
DIR = UP
ELSE ' Was 2 now 4 = Down
Q_Count = Q_Count - 1
DIR = DN
ENDIF
Case 128
If NewState = 64 THEN ' Was 4 now 2 = Up
Q_Count = Q_Count + 1
DIR = UP
ELSE ' Was 4 now 1 = Down
Q_Count = Q_Count - 1
DIR = DN
ENDIF
END SELECT
oldState = NewState
ENDIF
ENDIF
Return
but no matter what M (1,2 or 3) I push, porta.0 goes high and stay so.
Bookmarks