Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 11th March 2007, 11:41 PM   (permalink)
Default page bounry

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
Gaston is offline  
Reply With Quote
Old 11th March 2007, 11:46 PM   (permalink)
Default

I am assuming you are talking about PIC micros here.
Quote:
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....
Quote:
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.
__________________
--- The days of the digital watch are numbered. ---
kchriste is online now  
Reply With Quote
Old 12th March 2007, 12:26 AM   (permalink)
Default

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.
Gaston is offline  
Reply With Quote
Old 12th March 2007, 12:38 AM   (permalink)
Default

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.
Pommie is offline  
Reply With Quote
Old 12th March 2007, 02:09 AM   (permalink)
Default

i think i'm begining to see. so basically the uper five bits of the program counter determines what 256 page your on?
Gaston is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 02:45 PM
PIC: Table lookup across page boundary eblc1388 Micro Controllers 11 16th August 2005 02:42 PM
compiling with MPLAB evandude Micro Controllers 4 9th April 2005 08:08 AM
Elektor Web Page Sarac General Electronics Chat 1 8th November 2004 08:12 AM
Half page loads DirtyLude Feedback/Comments 7 14th May 2004 11:29 PM



All times are GMT. The time now is 11:16 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.