Maker Pro
Maker Pro

I need to PIC your knowledge. Please read.

M

Me

Jan 1, 1970
0
Hi all,

Firstly: Thank you all for your help.
Secondly:
I'm having trouble trying to use a lookup table.
I have found a tutorial that shows how, but the test for validity is for a 16 line table.
Thats easy, AND the variable with 16, but what if I only have 9 lines in my table?
ANDing my variable with 9 is not going to give me the wanted result is it?
Or an I missing something?

Thanks.
 
R

Randy Day

Jan 1, 1970
0
Me said:
Hi all,

Firstly: Thank you all for your help.
Secondly:
I'm having trouble trying to use a lookup table.
I have found a tutorial that shows how, but the test for validity is for a 16 line table.
Thats easy, AND the variable with 16, but what if I only have 9 lines in my table?
ANDing my variable with 9 is not going to give me the wanted result is it?


You're right, it won't.


; air code - I *may* have the values
; backwards for setting up the subtraction.
; run thru Sim before use

MOVLW
0x09
MOVWF
TEMPREGISTER
; save '9' to memory
MOVF
TABLEINDEX, 0 ; get your table index into W
SUBWF
TEMPREGISTER, 1 ; subtract your index from 9
BTFSS
STATUS, 0 ; if CARRY/BORROW set, index>9, skip

CALL GET_FROM_TABLE ; if number<=9, subroutine

; is called, index is in W
 
P

Paul E. Schoen

Jan 1, 1970
0
Randy Day said:
You're right, it won't.


; air code - I *may* have the values
; backwards for setting up the subtraction.
; run thru Sim before use

MOVLW 0x09
MOVWF TEMPREGISTER ; save '9' to memory
MOVF TABLEINDEX, 0 ; get your table index into W
SUBWF TEMPREGISTER, 1 ; subtract your index from 9
BTFSS STATUS, 0 ; if CARRY/BORROW set, index>9, skip

CALL GET_FROM_TABLE ; if number<=9, subroutine

; is called, index is in W

Depending on the PIC, you may need to watch out for crossing page
boundaries. You can check for address overflow, and adjust PCLATH. You can
also use ORG to set the table at a memory location that does not cross a
page boundary.

See AN556 for Table Read.

Paul
 
Top