Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC page boundary crossing

Status
Not open for further replies.

PA3040

Advanced Member level 3
Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Visit site
Activity points
6,936
Dear All

Can I have the simple example in assembly that effect the page memory boundary crossing and how handle the problem

1. one example for effect of 2k boundary crossing effect
2. how about solution above 1

My MCU is PIC16f877a

It would be much appreciated if some one can give a this help for my understanding purpose.

Code:
count	equ		0x20
LIST p=16f977a
#include <p16f877a.inc>

		org		0x00
Start	goto	main
main	clrf	count
loop	movf	count,w
		call	table
		incf	count
		goto	loop
		nop
		nop
		nop
		nop
		nop
		nop
[COLOR="#FF0000"]org		0x100[/COLOR]
table	addwf	PCL,F
		retlw	0x00
		retlw	0x01
		retlw	0x02
		retlw	0x03
		retlw	0x04
		retlw	0x05
		retlw	0x05
		retlw	0x06

end

In the above code in red color command line. when it is org 0x99 it is working and when it is 0x100 table reading gets malfunctions

please advice
Thanks in advance
 
Last edited:

Last edited:
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
There's also a big difference between 0x99 and 0x100 ! The problem is crossing the page boundary though, especially when you not only run off the end of the table but the next page too!

Brian.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear betwixt and suisti thanks for the reply and advice

I found following codes from AN556. Could you please advice how may I decided the value of "LOW Table" and "HIGH Table"

Code:
org 0x80
movlw LOW Table ;get low 8 bits of
; address
addwf offset,F ;do an 8-bit add
; operation
movlw HIGH Table ;get high 5 bits of
 ; address
btfsc status,c ;page crossed?
addlw 1 ;yes then increment
; high address
movwf PCLATH ;load high address in
; latch
movf offset,w ;load computed offset
; in w reg
call Table
.
.
org 0x9FD
Table:
movwf PCL,F ;load computed offset
; in PCL
retlw ’A’ ;return the ASCII
; char A
retlw ’B’ ;return the ASCII
; char B
retlw ’C’ ;return the ASCII
; char C

Please advice

- - - Updated - - -

Dear All

I changed my program as follows but still reaming the problem please advice

Code:
count	equ		0x20
LIST p=16f877a
#include <p16f877a.inc>

		org		0x00
Start	goto	main
main	
		clrf	count
		[COLOR="#FF0000"]bsf		PCLATH,3[/COLOR]
loop	movf	count,w
		call	table
		incf	count
		goto	loop
		nop
		nop
		nop
		nop
		nop
		nop
org		0x100
table	addwf	PCL,F
		retlw	0x00
		retlw	0x01
		retlw	0x02
		retlw	0x03
		retlw	0x04
		retlw	0x05
		retlw	0x05
		retlw	0x06

end
 
Last edited:

The idea is you don't have to worry about where the table is. The words "HIGH" and "LOW" in the assembler tell it to use the high byte and low byte of the address, in this case "table". So for example if your table is at address 0x1234, HIGH table would be set to 0x12 and LOW table would be set to 0x34.

However, the problem in your code is slightly different. Look at the value of 'count' as the program runs. It starts at zero (clrf count) but counts all the way up to 0xFF so when you add it to the program counter to jump into the table, you actually go well beyond the end of the table and in fact beyond address 0x200 which puts you in the next page again.

Assuming you are using MPLAB or MPLABX, run a simulation and place a watch on 'count', you will see it run off the end of the table into whatever else is in memory after it. You can also watch the page and bank settings as count becomes so large it passes the boundary. Remember that you 'call' the table so a return address is held on the stack, normally the retlw instruction restores the value off the stack but if you jump to an instruction which is not a return or retlw you will not be sent back to the original place in the program.

Brian.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Brian Thanks again and again for valuable explanation

really I got the start from your advice

now my program is working

modified program
Code:
LIST p=16f877a
#include <p16f877a.inc>

		org		0x00
Start	goto	main
main	clrf	count
loop	
		[COLOR="#FF0000"]movlw	HIGH table
		movwf	PCLATH[/COLOR]
		movf	count,w
		call	table
		incf	count
		goto	loop
		nop
		nop
		nop
		nop
		nop
		nop
org		0x100
table	addwf	PCL,F
		retlw	0x00
		retlw	0x01
		retlw	0x02
		retlw	0x03
		retlw	0x04
		retlw	0x05
		retlw	0x05
		retlw	0x06

end

Please advice if my table pass the two pages boundaries how could I impliment it

Pleas help

Thanks in advance

- - - Updated - - -

Dear Brian,
Please also advice how may I read more than 256 location using table
movf count,w which is only count 0 to FF that we can use only 255 elements on the one table
Thanks in advance
 

Please also advice how may I read more than 256 location using table

Code:
;init Windex (this is  2 byte var), now  = 2*256+99 = 611 !!!
 movlw 99
 movwf WindexL ; low byte
 movlw 2
 movwf WindexH ; high byte
....

Getitem ; now the  9

 movlw LOW Bigtable
 addwf WindexL, 1
 movlw HIGH Bigtable
 btfsc STATUS,0 ;carry
 addlw 1
 addwf WindexH, 0
 movwf PCLATH
 movf WindexL, 0
 movwf PCL ; go to item 611, returns with W = 9



Bigtable ;can be placed anywhere!!

 retlw 0 ;first item (Windex = 0)
 retlw 1 ;second ...
 ....
 ....
 retlw 9 ;the item 611 !!!! 
 ...
 ...  ; do you have enough place? :-)
 

Zuisti is showing the method I described. As long as you use the HIGH/LOW directives before actually making the call it should correct for the page boundary wherever it is. You program will still overflow the table as you have it at the moment though. You must limit the value added to PCL so it is never more than the number of entries in the table. If your program needs very large tables it's easier to switch to a PIC18 device, they have instructions specifically for reading and writing tables of any size.

Brian.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top