PDA

View Full Version : 16f877a: PCLATH register



herve
- 31st August 2006, 20:24
Could somebody give me a simple example, showing how to use " PCLATH register", in a short program. My objective is to solve the message 306: Crossing page boundary - ensure page bits are set", which appears in my program. My program is done with MPLAB IDE V6.60.

Thank you in advance,

Best regards,

Hervé.

Acetronics2
- 31st August 2006, 20:46
Hi,Herve

You can forget about Message 306 ... PBasic cares for you !!!

It can be cancelled using :

@ Errorlevel -306

at the top of your program ...

OR using PM Compiler ... !!!

Now PCLATH permits to use a larger adressing range than an asm CALL allows, Look at fig 2.3 p 19 of the Datasheet : it explains the different BANKS of memory. PCLATH permits to choose one of these Banks.

a look at page 32 will show you how addressing is done ...

Good readings
Alain

herve
- 1st September 2006, 19:20
Hello Acetronics,
I have already used "ERRORLEVEL - 306". It was OK to suppress the message, but when I launched the program, I faced with problems at the level where the message 306 was indicated (before the addition of "ERRORLEVEL-306"). So, I concluded that I could not ignore this message.

I am going to analyse the datasheet, in accordance with your proposal, but could you give me a short example of program using PCLATH register, in order that it completes my analysis efficiency ?

Thank you in advance,

Best regards,

Hervé.

paul borgmeier
- 1st September 2006, 20:21
also look here
http://www.picbasic.co.uk/forum/showthread.php?t=555

Acetronics2
- 2nd September 2006, 10:58
Hello Acetronics,
I faced with problems at the level where the message 306 was indicated , ... but could you give me a short example of program using PCLATH register, in order that it completes my analysis efficiency ?

Hervé.

Hi, Hervé

Using pure PbP would never involve such problems ... sooooooo, WHAT do you do and want to do here ????????????????????

My crystal ball is gone for holidays ...

Alain

Dave
- 2nd September 2006, 13:18
herve, The message is just a warning. As long as you are not using the BRANCH statement you should be OK. If you are using the BRANCH statement in your program then change it to BRANCHL. This is the BranchLong statement and is used when branching to other parts of your program that are not in the same page (crossing page boundries).

Dave Purola,
N8NTA

herve
- 2nd September 2006, 22:12
Hello Dave and Alain,
I am not using any "BRANCH procedure". My program is only using a lot of "GOTO" and "CALL" instructions. People explained me that this large number of "GOTO" and "CALL" is the reason why there is the message 306 (Crossing page boundary -- ensure page bits are set): the pic program memory (where my program is saved) is divided into pages due to limitation in the program counter size that can't carry the whole address bits for the whole memory. My program may have exceeded the size of one page so it crossed the page boundries to the next page. So the pc (program counter) overflowed.

The solution would be to adjust PCLATH register.

That is why I would like someone to give me an example of PCLATH use, through a short program, in order that I could know how to do with this PCLATH.

If you could help me, I thank you in advance,

Best regards,

Hervé.

paul borgmeier
- 3rd September 2006, 08:38
...My program is only using a lot of "GOTO" and "CALL" instructions. ...
herve,

You are missing the (same) message from the people trying to help you. Everybody gets the 306 warning message (which is not an error message, just a warning) if their program crosses a page boundary – everybody. Are you just getting the warning or is your program not doing what you expect? If it is the latter, then move your ASM routines to the first code page and makes sure this routine does not jump forward across a page boundary. If your ASM routine “intends” to jump forward across a page boundary, you can adjust bits 3 and 4 of PCLATCH just before the ASM CALL or GOTO. Personaly, I wouldn't go there unless you are well versed in ASSEMBLY programming. Again, see:

http://www.picbasic.co.uk/forum/showthread.php?t=555

Good Luck

Acetronics2
- 3rd September 2006, 10:59
Hi, Hervé

Here an example ( ASM source ... )

REDCYL ;SUB pour lire SEUIL et NCYL
movlw 1 ;Aller dans LTABLE chercher le SEUIL (negatif)
;de ligne rouge
bcf PCLATH,0 ;LTABLE est la page 2(en h200)
bsf PCLATH,1 ;donc PCLATH =2
call LTABLE

and somewhere further

LTABLE org h'200' ;Table des delais N =367 - 1500 t/mn(0° avant,soit T/4)
addwf PCL,f ;sauter au bon endroit h34=opcode pour RETLW

INCLUDE c:\aepl\Oltab.txt ;ici la LTABLE préalablement générée par le prog. gentab.bas


The goal is to retrieve a value in a Lookup table ...

BUT you NEED to know the page number ... where you want to jump to !!!

So, a solution is to place " manually" your called stubb to a known location ( not "squatted" ) by PbP ... :

ORG xxxx

CalledStubb
.....
.....

PbP example

'************************************************* ****************************
'Table des Valeurs d'avance en 200h - longueur Maxi 254 lignes !!!
'************************************************* ****************************

asm

bcf PCLATH,0
bsf PCLATH,1

call Table

Movwf _Avance

endasm

and further, at the very top high free program location.

asm


ORG 200h
Table

movfw _Index
addwf PCL,F

Include C:\Documents and Settings\Alain\Mes documents\Avance.txt


endasm

END

No secret there ...

Bonnes vacances ...

Alain

herve
- 6th September 2006, 07:03
Hi everybody,
Thank you for all your elements. I am waiting for the week-end to analyse them in details (lack of time during the week !).

Best regards,

Hervé.