wallaby, This is a subroutine I use for the 6 channel repeater voter I designed. The A and B outputs from the rotary encoder are wired to port pins 0 and 1 respectively. The varaible KNOBLIM is used for a maximum rollover count ie(KNOBLIM to 0) and a underflow count ie(0 to KNOBLIM) and this variable can not be greater than 65535. The variable MULTIPLY is to be set for 1,10,100,1000,10000 to be used for incrementing or decrementing individual digits of the variable to be manipulated. The variable UPDOWN can be preloaded with a starting target value before calling the routine. As for the direction of the knob rotation as far as incrementing or decrementing the variable, just switch the A and B input wires of the encoder to adjust which input edge leads the other.
OFS VAR BYTE 'ENCODER + or - COUNT
TEMP1 VAR BYTE 'ENCODER SCRATCH VARIABLE
TEMP2 VAR BYTE 'ENCODER SCRATCH VARIABLE
KNOBLIM VAR WORD 'UP-DOWN COUNTER LIMIT
UP_DOWN VAR WORD 'COUNTER PASS VARIABLE
MULTIPLY VAR BYTE 'KNOB MULTIPLIER FOR SPEED
'************************************************* ********************
ENCOD: 'READ ROTARY ENCODER POSITION
'************************************************* ********************
TEMP2 = TEMP1 | (PORTD & %00000011)
LOOKUP TEMP2,[2,3,1,2,1,2,2,3,3,2,2,1,2,1,3,2],OFS
TEMP1 = (TEMP2 << 2) & %00001100
UP_DOWN = UP_DOWN + ((OFS * MULTIPLY) - (2 * MULTIPLY))
IF UP_DOWN = (KNOBLIM + MULTIPLY) THEN UP_DOWN = 0
IF UP_DOWN > KNOBLIM THEN UP_DOWN = KNOBLIM
MULTIPLY = 1
RETURN
Usage:
TEMP1 = (PORTD & %00000011) << 2 'only executed once to preload temp1
MODEX: 'SETUP KNOB TO SELECT WHICH ROUTINE
UP_DOWN = PROGRAM 'Preset for current porgram
KNOBLIM = 6 'SET PROGRAM NUMBER SELECTION LIMIT
GOSUB ENCOD 'READ ENCODER
PROGRAM = UP_DOWN
IF OLDPRG <> PROGRAM THEN 'IF THE SAME THEN DON'T RE-DISPLAY
OLDPRG = PROGRAM
GOSUB DSPSEL 'IF NEW SELECTION THEN DISPLAY IT
ENDIF
Dave Purola,
N8NTA




Bookmarks