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
 
LinkBack Thread Tools Display Modes
Old 17th September 2007, 03:44 AM   (permalink)
Question What Value to move to PCLATH

Hi I have a terrible problem when writing to PCLATH so please take a look.

I attached the disassembly listing it shows the actual line number in my Data Tables.
You can see the half of Table11 & Table12 exceeding 0FFh mark. Highlighted in red.

I can call Table1 to 10 anywhere in the program memory. Because there in the first 0FFh mark. But when I call Tables 11 & 12 it won’t work very well.

I’m calling Table11 from 12Fh line. Here what I wrote to PCLATH.

Code:
calling Table11 from 12Fh line
	 
        movlw	HIGH Table11
        movwf	PCLATH      
        call	Table11
I think I have missed some PCLATH value any idea.
Attached Images
File Type: jpg Table.JPG (132.8 KB, 12 views)
Suraj143 is offline  
Old 17th September 2007, 03:53 AM   (permalink)
Default

Have you tried running it through MPLABs simulator. Should be easy to spot what's happening then.

Also try looking into the fcall macro
Code:
fcall    macro subroutine_name
    local here
    lcall subroutine_name
    pagesel here
here:
    endm
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 17th September 2007 at 04:22 AM.
blueroomelectronics is online now  
Old 17th September 2007, 04:29 AM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
Have you tried running it through MPLABs simulator. Should be easy to spot what's happening then.
Hi blueroomelectronics thanks for your input.I have never used MPLAB simulator I dont know how to do that.

But when I reduced the data in the Table11 its working because its below first 0FFh mark.

And I dont know anything about macros.
Suraj143 is offline  
Old 17th September 2007, 04:32 AM   (permalink)
Default

Hi,
I think your table 12 should be working well.
Look at the table 11, it starts at memory location 0x00EC and ends at 0x010A. So you are able to call table 11 until 0x00ff. From 0x0100 onwards, it starts going wrong because the high side of table 11 is always 0x00.
Do you get what I mean?
You can force the high side of table 11 to start at 0x01 by:
Code:
   org 0x0100
table11
   addwf   PCL, f
.
.
__________________
Superman returns..
bananasiong is offline  
Old 17th September 2007, 04:52 AM   (permalink)
Default

Quote:
Originally Posted by bananasiong
Hi,
I think your table 12 should be working well.
Look at the table 11, it starts at memory location 0x00EC and ends at 0x010A. So you are able to call table 11 until 0x00ff. From 0x0100 onwards, it starts going wrong because the high side of table 11 is always 0x00.
Do you get what I mean?
You are absolutely correct. When I reduced the data in the Table11 its starts working but when I add more data to Table11 its starts going wrong.

I’ll add org 0X0100 to Table11 as you mentioned
Code:
	org	0x0100
Table11	addwf	PCL,F
	retle	xx
And I’ll call the table like this from anywhere in my program memory like this.
Code:
	movlw	HIGH Table11
        movwf	PCLATH      
        call	Table11
Earlier I add org 0ECh to Table11 It also didn't fixed.Now only I understood the cut off mark is 100h.

Tell me am I right?
Suraj143 is offline  
Old 17th September 2007, 04:54 AM   (permalink)
Default

Using the sim is simply selecting it from the debug menu. Add view watchlists like PCL and PCLATH and single step through your program.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 17th September 2007, 04:58 AM   (permalink)
Default

Yes you're right. Because PCL is an 8-bit register. As long as the high side of the table doesn't change in the table, then everything will be fine.
__________________
Superman returns..
bananasiong is offline  
Old 17th September 2007, 05:07 AM   (permalink)
Default

Thanks a lot bananasiong then for the Table12 I wont need an org statement.

I can call directly like this from anywhere in the program memory.

Code:
	movlw	HIGH Table12
        movwf	PCLATH      
        call	Table12
But if I add more tables after Table11 (100h) I have to look what Table exceeds the next 0FFh mark.
Suraj143 is offline  
Old 17th September 2007, 05:16 AM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
Using the sim is simply selecting it from the debug menu. Add view watchlists like PCL and PCLATH and single step through your program.
Hi blueroomelectronics as soon I'm going to try your simulating method.Thanks for that.
Suraj143 is offline  
Old 17th September 2007, 05:38 AM   (permalink)
Default

If you calculate the address properly then you can have your tables anywhere you like.
Code:
TableNN
	movwf	Temp		;Save W
	movlw	High TabNN	;get high byte of address
	movwf	PCLATH		;put in PCLATH
	movlw	Low TabNN	;get low byte
	addwf	Temp,W		;add on offset
	btfsc	STATUS,C	;crossed page boundary?
	incf	PCLATH,F	;yes, so increment high byte
	movwf	PCL		;do jump

TabNN	dt	"Hello World",0
Mike.

Last edited by Pommie; 17th September 2007 at 06:01 AM. Reason: Clarification
Pommie is offline  
Old 17th September 2007, 05:49 AM   (permalink)
Default

Hi Mike you are always there.

Oh I see another method.So I can place the Tables anywhere in the program memory.

In your method do I need to add org statements for Tables?Or without org statements I can place Tables anywhere?

Thanks.
Suraj143 is offline  
Old 17th September 2007, 05:59 AM   (permalink)
Default

You can place tables anywhere, even if they cross a page boundary it will still work correctly.

Mike.
Pommie is offline  
Old 17th September 2007, 06:09 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
You can place tables anywhere, even if they cross a page boundary it will still work correctly.

Mike.
Thank you very much Mike for your support.
Suraj143 is offline  
Old 17th September 2007, 07:01 AM   (permalink)
Default

Besides the giving of fish, good to also train how to fish.

AN556
http://ww1.microchip.com/downloads/e...tes/00556e.pdf

AN's - The great solvers of mystery.
donniedj is offline  
Old 17th September 2007, 07:53 AM   (permalink)
Default

Anyone into PIC programming should really take time to fully understand the purpose and significance of PCLATH.

One would need to take care of it during Table read crossing 256 page boundary, CALL/GOTO code crossing 2K boundary and possibly interrupt handling.
__________________
L.Chung
eblc1388 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Validating Code Without PIC burg Micro Controllers 4 22nd April 2007 05:14 PM
Accessing EEPROM Clayton Micro Controllers 15 23rd March 2007 04:00 AM
Pic16f88 Mark (Imagine Design) Micro Controllers 5 6th June 2006 10:21 PM
Code not working..help Electrix Micro Controllers 15 26th September 2005 12:12 PM
PCLATH heida11 Micro Controllers 2 19th December 2004 01:15 PM



All times are GMT. The time now is 08:35 PM.


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

eXTReMe Tracker