Ive written a long program which is crossing over to different pages the problem ive got is I cant seem to select the "call" and "goto" routines on the next page, I've tried using "pagesel" but I still get the same warning and the program stops at that point.
If you are only using two pages then the simplist way is to put bsf PCLATH,3 before the call and bcf PCLATH,3 after it. You can get rid of the warning by ANDing the address with 0x7ff so you code ends up as,
I can call the routines on page 1 from page 0 but not the other way around, Ive looked on the datasheet but cant find what values I need to change.
Also you said that using "pclath" is the easiest way when using 2 pages, whats the difference when using more then 2 pages as I may have to upgrade to the 877 with 4 pages.
You can call routines in page 0 from page 1 but you have to clear bit 3 of PCLATH and set it after the call.
If you use more than 2 pages then you have to set bit 4 as well as bit 3 and so you may as well use the pagesel macro. Use pagesel Routine before the call and pagesel $ after it.
You might also try using the MicroChip macro 'fcall' (or various improved versions of it), you simply use fcall instead of call and it inserts the PCLATH code for you.
; Macros
fcall macro subroutine_name
local here
lcall subroutine_name
pagesel here
here:
endm
I don't like the Microchip macros such as banksel, pagesel, lcall etc. as they always insert two bit instructions even when only one is needed (each call takes 5 locations rather than three). You also can't write your own intelligent version as the assembler is only 2 pass so forward references cause errors.
Used to program with the 16F87x range - good as they are - when you get into a large program they can really be a nightmare with the page boundaries and ram bank switching every other line of code etc.
Best solution I found was to simply switch to the 18F2520 / 4520 chips - virtually the same price and pinout.
It has no page boundaries, and you have 384 bytes of ram available before you need to use the bank select register to switch to another bank of 256 bytes. (1536 bytes of ram in total on the 4520)
The assembler code is 99% compatible - just a few things need modifying but they are mostly covered in the Microchip 16F to 18F migration documents, plus you get all the extra soft and hardware features of this more advanced 18F chips; one of the best being the on chip oscillator option.
Once you have got running on the 18Fs I don't think you would every want to code a 16F again..
Ive written a long program which is crossing over to different pages the problem ive got is I cant seem to select the "call" and "goto" routines on the next page, I've tried using "pagesel" but I still get the same warning and the program stops at that point.
I have used the PIC for a while, when using large programs with tables & calls
I place my tables at the bottom of memory using the ORG command.
You must calculate where the 255 page boundaries occur then precede them with ORG to set memory location.
Then use code below
movlw HIGH table_a ;preload high bits of program counter
movwf PCLATH ;
movfw pointer
call table_a
the last two lines are a normal command for calling tables
pointer is location in table, then call table_a
the page locations are handled by the first 2 lines
Do you know that MCHP is planning to isue 16Fs with a new instructions set where several limitations are gone? In spite of that I will not go back to them.