Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What Value to move to PCLATH

Status
Not open for further replies.

Suraj143

Active Member
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.
 

Attachments

  • Table.JPG
    Table.JPG
    132.8 KB · Views: 149
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
 
Last edited:
blueroomelectronics said:
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.
 
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
.
.
 
bananasiong said:
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?
 
Using the sim is simply selecting it from the debug menu. Add view watchlists like PCL and PCLATH and single step through your program.
 
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.
 
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.
 
blueroomelectronics said:
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.
 
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:
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.
 
You can place tables anywhere, even if they cross a page boundary it will still work correctly.

Mike.
 
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.
 
First of all thanks for all of your replies.
I tried every ones methods.I placed org statements to the Table11 also but still I coudn't access to Table11 onwards.

From Table 1 to 10 its working perfectly but from Table11 onwards its not working.

Here is my code.Main routine starts from 12Fh line.
Code:
Main	clrf	2Ah
        incf	2Ah,F	    ;increment the jump value
        movf	2Ah,W       ;Put jump value into W  
        [COLOR="Red"]movlw	High Table11
        movwf	PCLATH
        call	Table11[/COLOR]
        movwf	30h         ;get the 30h GP register
        xorlw	0FFh        ;If table11 value is 0FF in 30h register? 
        btfsc	STATUS,Z    ;bit 2 of STATUS will be SET (=1)
        goto	Exit        ;goto Exit
	call 	Scan	    ;show Display

Please help me.
 

Attachments

  • Table.JPG
    Table.JPG
    134.8 KB · Views: 148
Your corrupting W.

Mike.
Code:
Main	clrf	2Ah
        incf	2Ah,F	    ;increment the jump value
        movlw	High Table11
        movwf	PCLATH
[COLOR="Red"]        movf	2Ah,W       ;Move this to here[/color] 
        call	Table11
        movwf	30h         ;get the 30h GP register
        xorlw	0FFh        ;If table11 value is 0FF in 30h register? 
        btfsc	STATUS,Z    ;bit 2 of STATUS will be SET (=1)
        goto	Exit        ;goto Exit
	call 	Scan	    ;show Display
 
I cannot call the Table11 onwards

First of all thanks for all of your replies in my earlier thread.

My problem is I cannot call the Table11 onwards.

I tried every ones methods. I placed org statements to the Table11 also but still I coudn't access to Table11 onwards.

From Table 1 to 10 it’s working perfectly but from Table11 onwards it’s not working.

Here is my code. Main routine starts from 12Fh line.

Code:
Main	clrf	2Ah
        incf	2Ah,F	    ;increment the jump value
        movf	2Ah,W       ;Put jump value into W  
        [COLOR="Red"]movlw	High Table11
        movwf	PCLATH
        call	Table11[/COLOR]
        movwf	30h         ;get the 30h GP register
        xorlw	0FFh        ;If table11 value is 0FF in 30h register? 
        btfsc	STATUS,Z    ;bit 2 of STATUS will be SET (=1)
        goto	Exit        ;goto Exit
	call 	Scan	    ;show Display

Please help me to solve my problem.Attachment contains the disassembly listing.
 

Attachments

  • Table.JPG
    Table.JPG
    134.8 KB · Views: 134
Mike I didn't notice that.For sure that will be the problem.When I call the Table11 its showing all PORTB outputs not the data in the Table11.

Thank you very much Mike for guiding me.

I'm really tired with this project I cannot sleep even.I'm going to adjust the coding as you mentioned.

Thank you very much Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top