Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Look-up-table in the Microchip PIC 16F84

Status
Not open for further replies.

spiraal

Industrial
Apr 11, 2002
6
I would like to program some sort of a look up table for the 16F84 PIC microcontroller.
Does anybody has an example of how it’s done and if it can be done period.
It should work like this: …..
when count is 125 -> var…->var 2 is…etc.
when count is 126-> var1…->var2…..etc.
and this for 0 till 150.
 
Replies continue below

Recommended for you

Use the value as an offest into the table. I.e, base table address =1000h, and table length is 150. Store base address into a register, add the register plus offset, and do a register indirect read / write to / from memory. There is a more dangerous / tricky way, but I would not suggest doing it unless you absolutely need to!

Good Luck and keep us posted!
 
CALL TABLE ; W REG must allready contain talbe offset
. ; W reg will now have table value
.
.
.

TABLE ADDWF PC ;W = offset
RETLW k1 ; first table value
RETLW k2 ; second table value
.
.
RETLW kn ; last table value
 
Thanks all, you’ll be hearing from me if it all works out!
 
Hi Spiraal,

There is a problem with call up tables on all pics and that is if the table is in a different bank to the program call, the program will crash

I have used the following code with several very large tables in the same program without problems and I now use it as a standard.

clrf pclath
movf number,w ; program will jump to number
addwf pcl,f

retlw 000 ; number = 0
retlw 100 ; number = 1
retlw 200 ; number = 2
etc etc
Good luck,
Regards,
G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor