tarts
Member level 2
Hi
I want to look up from table in pic16f887, but it seems that the PC overflows and I can't read the table correctly with these commands:
movfw offsetvalue
call table
...
table
addwf PCL
retlw x
retlw y
...
So i read this document: https://ww1.microchip.com/downloads/en/AppNotes/00556e.pdf
and added these (in bold) two lines
org 0x80
movlw HIGH Table
movwf PCLATH
movlw offset
call Table
.
.
.
org 0x320
Table:
addwf PCL,F
retlw ’A’
retlw ’B’
it seems to work fine as long as the PC counter doesn't overroll in the middle of the table. the last example in the document doesn't seem to work at all(example 5)
With this code the table can be located anywhere in the code. But it doesn't work for me. If you look at the code you can see that the author never tested it. status,c should be written in capitals. i fixed that, but it still doesn't work.
does anyone know what's wrong with it?
I want to look up from table in pic16f887, but it seems that the PC overflows and I can't read the table correctly with these commands:
movfw offsetvalue
call table
...
table
addwf PCL
retlw x
retlw y
...
So i read this document: https://ww1.microchip.com/downloads/en/AppNotes/00556e.pdf
and added these (in bold) two lines
org 0x80
movlw HIGH Table
movwf PCLATH
movlw offset
call Table
.
.
.
org 0x320
Table:
addwf PCL,F
retlw ’A’
retlw ’B’
it seems to work fine as long as the PC counter doesn't overroll in the middle of the table. the last example in the document doesn't seem to work at all(example 5)
Code:
org 0x80
movlw LOW Table ;get low 8 bits of address
addwf offset,F ;do an 8-bit add operation
movlw HIGH Table ;get high 5 bits of address
btfsc status,c ;page crossed?
addlw 1 ;yes then increment high address
movwf PCLATH ;load high address in latch
movf offset,w ;load computed offset in w reg
call Table
.
.
org 0x9FD
Table:
movwf PCL,F ;load computed offset in PCL
retlw ’A’ ;return the ASCII char A
retlw ’B’ ;return the ASCII char B
retlw ’C’ ;return the ASCII char C
.
.
.
does anyone know what's wrong with it?