Define CONF_WORD = 0x31c4
Dim op As Byte 'current state
Dim lastop As Byte 'last state
TRISIO = 0x7 'one side inputs other outputs
CMCON = 7
ANSEL = 0 'no adc
WPU = 0x30
op = GPIO And 3 'for miscount on startup
main:
lastop = ShiftLeft(op, 2) 'move state to last state position
op = GPIO And 3 'read GPIO.0 and GPIO.1 only
lastop = lastop + op 'add new state
Select Case lastop 'only 16 state combinations
Case 1, 7, 8, 14 'seqence above
Goto down
Case 2, 4, 11, 13 'sequence above
Goto up
Case Else 'stopped or invalid
Goto main 'do nothing
EndSelect
down: 'set direction down
GPIO.5 = 0
WaitUs 100
Goto clock
up: 'set direction up
GPIO.5 = 1
WaitUs 100
Goto clock
clock: 'clock direction
GPIO.4 = 1
WaitUs 100
GPIO.4 = 0
Goto main 'go again
End