gnupic: Help needed
Subject:
Re: Help needed
From:
Greg Hill ####@####.####
Date:
13 Sep 2004 17:26:53 +0100
Message-Id: <Pine.LNX.4.44.0409130946200.22828-100000@hillnet.us>
On Mon, 13 Sep 2004, Julian Green wrote:
> Im doing a project with the PIC16F871, and I am using a number of lookup
> tables that uses computed goto. Is there a way of getting the linker to
> chose an address for the table that does not cross page boundaries?
The only way I know of (to make the linker get an address which won't
cross a table boundary) is to put your table in its own CODE segment and
force its address:
CRC16_Lookup CODE 0x0100
global CRC16_Lookup
movwf temp
movlw High($)
movwf PCLATH
....
Another option, which I implemented for a previous employer using an
18F8520 (?) part, is to calculate whether the table lookup is going to
cross a page boundary and then increment the high and upper PC addresses
as necessary. Since I don't work there anymore, I don't have access to the
code (and couldn't copy the relevant portion anyway, even if I did have
access to it). But the basic idea is this:
- reserve enough registers to hold all bits of the program counter (3
registers on the 18F series I worked on; I think it's 2 on the 16F's)
- initialize both registers:
movlw LOW CRC16_Lookup
movwf reg1
movlw HIGH CRC16_Lookup
movwf reg2
- add the address of the table to your offset and store to one register
addwf reg1,f
- test for overflow in that addition. (confirm.. use btfsc or btfss here?)
btfsc status,c
incf reg2,f
- repeat (test for overflow, carry it into the next register) on devices
with more that 16 bits of program counter
- move registers into PC
movf reg2,w
movwf PCLATH
movf reg1,w
movwf PCL
This code example probably won't work out-of-the-box, as it's been a while
since I did PIC at all and even longer since I did a 16F project.
Hopefully it'll be enough to get you started in the right direction.
Greg