page bounry

Status
Not open for further replies.

Gaston

Member
when they say a table can't cross the 256 boundry, does that mean the 256th line in the program? and would that be the same as the address 256 in the program counter. i'm haveing trouble understanding the pclath
 
I am assuming you are talking about PIC micros here.
when they say a table can't cross the 256 boundry, does that mean the 256th line in the program?
Not really, especially if you double space or use comments....
and would that be the same as the address 256 in the program counter.
Yes, it means that there are blocks of bytes, 256 bytes in size, starting at address 0000.... Each table must be contained within a single 256 byte block. This is because when you do math on PCL, only the lower 8bits of the program counter are effected.
 
so the program counter can hold more than 256, its just that you can only write to the lower 8 bits. so the pic can write to all of the bits? how does useing pclath make it posible to cross the page boundry. pommie did it for me but i don't understand what it does.
 
PCLATH has two slightly different uses.

First, whenever a write to PCL occurs then PCLATH is copied to the high byte of the program counter.
An example may help,
Code:
	movlw	0x01
	movwf	PCLATH
	movlw	0x23
	movwf	PCL
After the write to PCL the program will jump to location 0x0123 because the program counter gets loaded from PCLATH and PCL. Note the write to PCLATH doesn't affect anything until the write to PCL.

When it comes to tables then the normal way to use them is to place the table on a page boundary (0xnn00) and load PCLATH with the high byte of the address (0xnn). The limitation of this method is that the table has to be in the one block of 256 bytes.
An alternate method that gets around this limitation is to calculate PCLATH as well as PCL. Such as,
Code:
	movlw	high(table)
	movwf	PCLATH
	movwf	low(table)
	addwf	Pointer,W
	btfsc	STATUS,C
	incf	PCLATH,F
	movwf	PCL
table	retlw	00
This allows the table to be anywhere and if you make the Pointer 16 bit then you can have a table of any size.

The second use for PCLATH is when doing a jump or call. These instructions only provide 11 bits for the address and so the other bits come from the top 5 bits of PCLATH.
So, to jump to location 0x876 you would do,
Code:
	movlw	0x08
	movwf	PCLATH
	goto	0x076
However, this is never encountered unless you use a larger pic - one with more than 2K of program space.

HTH

Mike.
 
i think i'm begining to see. so basically the uper five bits of the program counter determines what 256 page your on?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…