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.

Help in paging 16F877

Status
Not open for further replies.

TronicBrain

Member
Hi
This is the first time I reach about 550 instruction set in 16F877
But it started causing troubles

My code is about several subroutines called from the main program
At the beginning of the project I was adding the code piece after piece
And make a test after adding every sub routine
(all the subroutines are working well individually)

But when added the last piece of code it dose not work
When moving it after the main program
It works but leaving the last piece of code not working!

I thing it's a matter of paging the program memory

I do not know how to deal with PCLATH register
and my whole program will not exceed 700 instruction set

any help?
 
If your code is not going to exceed 700 instructions then it will fit in one bank. The bank size if 2048 (0x800) instructions. It is more likely that a table is moving and crossing a page boundary. Look for any access to PCL and check that the table that follows is all in one page - IE has the same high byte in the address.

If your code is going over 2k then you can call subroutines in the far bank by doing the following,
Code:
		movlw	high(FarSub)
		movwf	PCLATH
		call	FarSub
		clrf	PCLATH
Or,
Code:
		bsf	PCLATH,3
		call	FarSub
		bcf	PCLATH,3

Note that once you are in bank 2 then all calls and gotos will stay in bank 2 until you "return" to bank 1.

Mike.
 
There's also a Microchip macro 'fcall', which generates the required code for you:

Code:
; Macros
fcall    macro subroutine_name
    local here
    lcall subroutine_name
    pagesel here
here:
    endm

To use it just add it to the header of your program and use fcall instead of call for your subroutines.
 
This is one of the reasons I decided not to use PIC's, pageing is a pain.
 
I put all the subroutines which contain tables in the beginning of the program memory
and the problem is solved

thanks guys
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top