Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Table reads AN556 example 5 error (solved)

Status
Not open for further replies.

pjmelect

Advanced Member level 2
Advanced Member level 2
Joined
May 13, 2012
Messages
576
Helped
127
Reputation
254
Reaction score
131
Trophy points
1,323
Activity points
5,880
Microchip issue an interesting document AN556 showing how to implement table reads. However the example they give to implement a table read (example 5) where the table can start at any memory location and can cross page boundaries contains errors. I looked online and found many people had reported that the routine does not work but no solutions to fix the program were presented so I decided to do it myself.

Code:
;This is the original code in AN556 example 5
    movlw    LOW TABLE
    addwf    OFFSETL,F
    movlw    HIGH TABLE    ;Get high byte of BASE address
    btfsc    STATUS,C
    addlw    1H
    movwf    PCLATH        ;write to PCLATH
    movf    OFFSETL,W
    call    TABLE
    
        org    01FDH
TABLE    addwf    PCL,F
    retlw    "A"
    retlw    "B"
    retlw    "C

I realised that the instruction addwf OFFSET,F was a typo and it should have been addwf OFFSET,W however even then the program did not work in every case as the author of the program had forgotten that addwf PCL,F instruction takes one byte before the data. To fix this I changed the TABLE pointers to (TABLE+1) The program now works correctly in every case.

Code:
    movlw    LOW (TABLE+1)
    addwf    OFFSETL,W
    movlw    HIGH (TABLE+1)    ;Get high byte of BASE address
    btfsc    STATUS,C
    addlw    1H
    movwf    PCLATH        ;write to PCLATH
    movf    OFFSETL,W
    call    TABLE
    
        org    1FDH
TABLE    addwf    PCL,F
    retlw    "A"
    retlw    "B"
    retlw    "C"

I have written a series of different table read routines including ones to read tables larger than 256 bytes, if you would like a copy of them please PM me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top