×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Look-up-table in the Microchip PIC 16F84

Look-up-table in the Microchip PIC 16F84

Look-up-table in the Microchip PIC 16F84

(OP)
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.

RE: Look-up-table in the Microchip PIC 16F84

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!

RE: Look-up-table in the Microchip PIC 16F84

      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

RE: Look-up-table in the Microchip PIC 16F84

(OP)
Thanks all, you’ll be hearing from me if it all works out!

RE: Look-up-table in the Microchip PIC 16F84

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  
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources