Searching \ for 'Look up Table : Where is my mistake ?' 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/mems.htm?key=table
Search entire site for: 'Look up Table : Where is my mistake ?'.

Truncated match.
PICList Thread
'Look up Table : Where is my mistake ?'
1999\08\26@130822 by Fabiano Leitao

picon face
<x-flowed>Hello, people.

I want to implement a table look-up for a P16C74A. This table is called by
another routine placed at 0x200. As the table is large and  crosses the 256
bytes page boudary, I used the piece of code suggested by the application
note AN556, in order to allow me to place the table anywhere in program
memory. Please , see the code below:

    org     00
    goto    Main

    org     04h
    goto    inter
        .
        .
    org     20h
Table1
     addwf   PCL,F
     retlw   B'00001110'  ; line 0x0000
     retlw   B'00010001'  ; line 0x0001
     retlw   B'00010001'  ; line 0x0002
     retlw   B'00010001'  ; line 0x0003
        .
        .
     retlw   B'00011111'  ; linha 0x00fd
     retlw   B'00010001'  ; linha 0x00fe
     retlw   B'00010001'  ; linha 0x00ff
     retlw   B'00011110'  ; linha 0x0100
     retlw   B'00010001'  ; linha 0x0101
     retlw   B'00010001'  ; linha 0x010f
        .
        .
     retlw   B'00010001'  ; linha 0x011f
     retlw   B'00010001'  ; linha 0x0120


     org      0x 0200
Call_table
     ; do a lot of things here
       .
       .
     movlw    LOW  Table1      ; AN556  suggestion
     addwf    offset_Table1
     movlw    HIGH Table1
     btfsc    STATUS,C
     addlw    1
     movwf    PCLATH
     movf     offset_Table1,w
     call     Table1
       .
       .
     return

     org      0x0300
Main
     .
     .
  call   Call _table
     .
     .
end

Well, the fact is that the return codes from the table calls are not
correct, and for some offset values given to the table, the PIC "crashes".
I suspect that the jump to the table routine is not OK.

Could anyone help me ?

This is my first message to this list. I expect to give many contributions
to everybody in the future.

Thanks in advance.

Fabiano O.L.



______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

</x-flowed>

1999\08\26@171456 by Peter van Hoof

flavicon
face
If 'm not mistaken instead of
Table1
       addwf   PCL,F
it should be:
Table1
       movwf   PCL

Peter


> {Original Message removed}

1999\08\26@184411 by Dennis Plunkett

flavicon
face
At 13:56 26/08/99 EST, you wrote:
{Quote hidden}

Dennis

1999\08\26@204233 by Mike Keitz

picon face
>>      org      0x 0200
>>Call_table
>>      ; do a lot of things here
>>        .
>>        .
>>      movlw    LOW  Table1      ; AN556  suggestion
>>      addwf    offset_Table1

The line above is probably your problem.  By default, MPASM uses 'f' as
the destination.  So the trial addition is modifying offset_Table1 when
you don't want to.

Replace that line with addwf  offset_Table1,w and it should work.


When you have large tables and are going to use this process, it isn't
necessary to have an 'addwf PCL,f' at the head of each table.  As long as
PCLATH is properly set up, you can modify PCL anywhere in the program and
the cprgram counter will go into the table.  So here's a more streamlined
method:

       ...
       movfw   HIGH Table1     ;Prepare to access the first part
of the table.
       movwf   PCLATH
       movfw   offset_Table1   ;Get the index into table.
       addlw   LOW  Table1
       skpnc                   ;Skip if still in first part
       incf    PCLATH,f        ;Go to next page.
       call    gettable
       ...
gettable
       movwf   PCL

The 'gettable' routine can be shared by all the table accesses in the
program.  Or, you can formulate the whole offset calculation and PCLATH
setting part as a subroutine and end it with a movwf PCL.  This will
cause the PIC to return via the table.


___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: dl.http://www.juno.com/dynoget/tagj.

1999\08\27@003610 by Ravi Pailoor

flavicon
face
part 0 3008 bytes content-type:text/x-vcard; charset=us-ascii; name="vcard.vcf" (decoded 7bit)

Try this
    org     20h
Table1
>    movwf temp
>   movlw HIGH $
>  movwf pclath
>  movf temp,w

     addwf   PCL,F
     retlw   B'00001110'  ; line 0x0000
     retlw   B'00010001'  ; line 0x0001
     retlw   B'00010001'  ; line 0x0002
     retlw   B'00010001'  ; line 0x0003

Pailoor

Fabiano Leitao wrote:

{Quote hidden}

--
Website : http://business.vsnl.com/chiptech


Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Ravi Pailoor
Content-Disposition: attachment; filename="vcard.vcf"

Attachment converted: wonderland:vcard.vcf 3 (TEXT/CSOm) (0000BC89)

1999\08\28@145134 by Fabiano Leitao

picon face
<x-flowed>Everything looks so obvious after someone shows you the answer! I can see
now what was wrong. At AN556, each example uses 'addlw PCL,F' under the
label 'Table', except example 5, which uses 'movwf PCL'. I did not noticed
it. My look-up table is ok now.

Thank you all.


{Quote hidden}

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

</x-flowed>

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