![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi
I am currently in the middle of a project using a PIC16f88, and have got to the stage where i think the program counter has overflowed, and it is jumping to the same place in the code all the time as opposed to where i want it to go. I have read the data sheet AN556 concerning PCLATH and don't quite understand it fully, it speaks about different pages. could someone please help me on this Thanks GreenP |
|
|
|
|
|
|
(permalink) |
|
For GOTOs and CALLs, the instructions contain 11 bits of the address of where the GOTO or CALL is going to.
11 bits accesses 2048 lines of code. The PIC16F88 has 4096 lines of code, which can be seen as consisting of two halves, one with the MSB of 0 and the other with an MSB of 1. These halves are called pages. There isn't room in the instruction for the MSB, only for the other 11, so at each GOTO or CALL, the MSB comes from bit 3 of PCLATH. Any CALL or GOTO that is in one half, that send the program counter to the other half, needs to set or clear Pclath, 3. If you use MPLAB, you can look at the program memory to see where instuctions are. If the address is 0x000 to 0x7FF, then Pclath, 3 should be clear when GOTO or CALL sends the program counter to that address. For instance, if there is a line at 0x600, that needs to call a routine at 0x800, the code would be:- org 0x600 bsf pclath, 3 call 0x800 bcf pclath, 3 ;This is useful if there are any other calls later org 0x800 ;here is the subroutine return |
|
|
|
|
|
|
(permalink) |
|
Thanking you very much for that Diver, something to get my head around
GreenP |
|
|
|
|
|
|
(permalink) |
|
Learn C language, compilers do the banking and paging, just don't exceed the page size for a single routine and limit array to fit the banks.
Last edited by penoy_balut; 20th January 2008 at 07:40 AM. |
|
|
|
|
|
|
(permalink) |
|
There are two built-in macro commands in MPLAB called LCALL and LGOTO that will handle the long call or goto.
BUT you must be careful to always set the correct page again after a LCALL You must also be careful on using them in conditional "skip" instructions as they contain several instructions and MPLAB won't warn you either. There is plenty of info on the piclist site here: http://www.piclist.com/techref/microchip/pages.htm |
|
|
|
|
|
|
(permalink) |
|
You might also consider why you're exceeding a single 2K page?, 2K is a LOT of PIC assembler, your program has to be pretty big to exceed it.
|
|
|
|
|
|
|
(permalink) |
|
As Nigel said, you would have to have written a lot of code to exceed 2k. If you do exceed it then you will get an error 306 - "Crossing page boundary -- ensure page bits are set." If you don't get that error then your problem is probably elsewhere.
Mike. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Code:
_fcall macro Address
if (Address & 0x800) ==0
bcf PCLATH,3
else
bsf PCLATH,3
endif
call (Address & 0x7ff) | ($ & 0x1800)
if ($ & 0x800) ==0
bcf PCLATH,3
else
bsf PCLATH,3
endif
endm
Mike. |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| What Value to move to PCLATH | Suraj143 | Micro Controllers | 19 | 18th September 2007 04:31 AM |
| BANKSEL AND PCLATH DOUBTS? | neelam29 | Micro Controllers | 2 | 18th February 2006 12:56 PM |
| Code not working..help | Electrix | Micro Controllers | 15 | 26th September 2005 11:12 AM |
| PCLATH | heida11 | Micro Controllers | 2 | 19th December 2004 12:14 PM |
| pclath 16f877 | jijita | Micro Controllers | 1 | 13th September 2004 05:59 PM |