Searching \ for '[PIC]: 16f873 large lookup table in page1 problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/memory.htm?key=table
Search entire site for: '16f873 large lookup table in page1 problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 16f873 large lookup table in page1 problem'
2003\09\04@190653 by Kevinhoward

picon face
Hi all!
               Had a look at the piclist memory method big lookup tables and
AN556 implementing table read now I am confused!!




                I am trying to get data from a large lookup table in Page 1
of 16f873- (similar table in page0 seems to work fine) This is the first time
I have used anything larger than a 16f628 so I think I may have messed up with
Page selecting and clearing.


Any help greatly appreciated in semi newbie format!!!

I have written code as follows:

;this routine in page 0

     movlw 0x08
   movwf   pclath               ;point to page 1
   movf    overflow,w          ;offset (max 0x04 min 0x00)
   addwf   pclath              ;added to pclath
   movf    fine,w              ;move this number to table to return final
value -retlw

   call           table1           ; table starts at 800h -1021 lines long
   bcf        pclath,3
     bcf         pclath,4                 ;back to page 0

   movwf   newval          ;new value from table stored here

   return

    ;  rest of routine in page 0

;;;;;;;;;;;Table:::::::::::::::::::::::
      org      800h                 ;page1

Table1
      movf     pcl,f               ;using this seems to rollover at every
256th value
      retlw     .1
      retlw     .5
      retlw     .2
      retlw     .12
      retlw      .6

      ;etc                     ;to 0xbd   .3069
;.------------------------------------------------------------------

Using addwf pcl at the start of Table1 causes program to crash about 3/4 up
the table!
Using movf   pcl,f seems to rollover at every 256th value instead of reading
the full table.

I may have commented lines with the obvious - sorry! it helps me on the
learning curve and if I have got it wrong help is appreciated.

Thanks in advance for your help

Regards,

Kev

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\09\04@213658 by Bob Barr

flavicon
face
On Thu, 4 Sep 2003 19:06:52 EDT, you wrote:

>Hi all!
>                Had a look at the piclist memory method big lookup tables and
>AN556 implementing table read now I am confused!!
>
>
>
>
>                 I am trying to get data from a large lookup table in Page 1
>of 16f873- (similar table in page0 seems to work fine) This is the first time
>I have used anything larger than a 16f628 so I think I may have messed up with
>Page selecting and clearing.
>
>

You're on the right track and yes, page select is causing the problems
that you're seeing. You need to make this part of your code its own
page 0 subroutine and put just the data in the upper bank. You then
call this subroutine from your mainline code.

I hope the spacing turns out to be readable.

;
;    do a table lookup based on 'overflow' and 'fine' values
;
;    Note: changes PCLATH - must do a pagesel after calling
;
;
GetTable:
   movlw    high(Table1)   ; get upper portion of Table1 base address
   movwf    PCLATH
   movf      overflow, w     ; get which 256-byte portion of Table1
   addwf    PCLATH, f     ; now pointing to right portion of table

   movf      fine, w             ; get offset into 256 byte page
   movwf    PCL                ; branch directly into table

;
;    NOTE: no return needed, executing the retlw in Table1 returns
;     to wherever GetTable was called from
;


From your mainline code, this would be used as:

;
;    set up your overflow and fine variables
;
   call         GetTable        ; convert to table value
   pagesel $+1                 ; restore PCLATH to current page
;
;    use the returned value in W as needed
;

>;;;;;;;;;;;Table:::::::::::::::::::::::
>       org      800h                 ;page1
>
>Table1
>       movf     pcl,f               ;using this seems to rollover at every
>256th value
^^^^^
Remove the above line to start your data at location 0800h

>       retlw     .1
>       retlw     .5
>       retlw     .2
>       retlw     .12
>       retlw      .6


Hope this helps.

Regards, Bob

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\09\05@182113 by Kevinhoward

picon face
Hi Bob,


An on list thank you!

For taking the time to reply and show me where I was going wrong. I have
modified the program and above all LEARNED from your excellent commenting.

Best regards,

Kev


--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...