Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Crossing page boundary in assembly

Status
Not open for further replies.

johnl69

Member
Hi

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.

how do I do this?

Im using pic 16f874a and writting in assembly.

thanks
john
 
Last edited:
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,
Code:
	bsf	PCLATH,3
	call	Bank1Routine &0x7ff
	bcf	PCLATH,3

I only put the AND after I have added the PCLATH stuff so I still get a warning if I miss one.

Edit, you should be aware that the code in bank 1 cannot call code in bank 0 without the relevant change to PCLATH.

HTH

Mike.
 
Last edited:
Cheers Pommie :D:D

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.

john
 
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.

Mike.
 
Thanks again

I tried;
Code:
 bcf PCLATH,3
 CALL ARROW_1 
 bsf PCLATH,3
but I still get the same warning and the program stops do I need to add the 7ff value to it?

john

EDIT; never mind my fault I types it right here but wrong in the program.
 
Last edited:
To get rid of the warning you have to fool the assembler into thinking your calling a routine in the same bank.

So, to call a routine in bank 0 from bank 1 you would do,
Code:
	bcf	PCLATH,3
	call	Page0Routine|0x800
	bsf	PCLATH,3

Can you post your code?

Mike.
 
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.

Mike.
 
Hi,

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..

hth

Richard
 
Once you have got running on the 18Fs I don't think you would every want to code a 16F again..

Lately I tried coding a 12F629 to see what I can do with it. Tremendous fun and satisfaction.

Once you have got something running happily on a 8-pin PIC, I don' think you would ever want to code a 16F or 18F again.
 
Hi

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.

how do I do this?

Im using pic 16f874a and writting in assembly.

thanks
john
If you do not like page boundaries ditch the PIC... or at least that one...I do not know off hand if they have any with a real address space.

In assembly you will be much happier without the accumulator.
 
Last edited:
PIC Boundaries

Hi

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

Hope this helps
 
My experiences

Hola Richard,

I got so used to the complexity of the 16F family (started in fact with the 16C57) that I did not considered that a problem anymore.

But later moved to the 18F. I know there are less risks of being trapped.

By the way:

Once you have got running on the 18Fs I don't think you would every want to code a 16F again..

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.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top