It's ok something like this ?!
Code:
TrisA = %00000000
TrisB = %11110000
PortB = 0
Flag var bit
Q_New var Byte
Q_Old var byte
M_Count var byte [4]
P_Count var byte [4]
Q_Count var word
' ---------------------- Set variable value @ startup ----------------------
For Q_Old = 0 to 3
Read Q_Old,M_Count[Q_Old]
Read Q_Old + 4,P_Count[Q_Old]
Next Q_Old
Q_Count = 0
Q_New = 0
Q_Old = 0
Flag = 0
Goto Main_Loop
Encoder: '
Q_New = PortB.7 + PortB.6 + PortB.5 ' get port status
If M_Count[Q_Old] = Q_New then ' if M_Count code satisfied then minus
Q_Count = Q_Count - 1
Flag = 0 ' set flag for DOWN
goto Q_Skip
endif
If P_Count[Q_Old] = Q_New then ' if M_Count code satisfied then plus
Q_Count = Q_Count + 1
Flag = 1 ' set flag for UP
endif
Q_Skip:
Q_Old = Q_New ' update Q_Old Byte
Main_Loop:
if Flag = 1 then do command1
if Flag = 0 then do command2
goto Main_Loop
Bookmarks