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.

Calling a Table from Different Locations

Status
Not open for further replies.

Suraj143

Active Member
Hi all!
Here is a sample program of mine. It has 4 tables each 100 lines data & I want to call them from end of my memory.

In the comments I have wrote the actual line number in MPLAB.

My first question is I want to call the TABLE1 from the MAIN routine (MAIN is in 2000 line). Is my coding write?

Thanks

Code:
	org	0x00

;setting up ports
	bsf	STATUS.rp0
	clrf	TRISB
	bcf	STATUS.rp0

	org	0x03

TABLE1	addwf	PCL,f
	retlw	xx
	retlw	xx
	retlw	xx
	retlw	xx
	-----
	-----		;100 line

TABLE2	addwf	PCL,f
	retlw	xx
	retlw	xx
	retlw	xx
	retlw	xx
	-----
	-----		;200 line

	org	0x04

TABLE3	addwf	PCL,f
	retlw	xx
	retlw	xx
	retlw	xx
	retlw	xx
	-----
	-----		;300 line


TABLE4	addwf	PCL,f
	retlw	xx
	retlw	xx
	retlw	xx
	retlw	xx
	-----
	-----		;400 line



MAIN	movlw	0x03	;main program starts from 2000 line
	movwf	PCLATH
	call	TABLE1	;call Table1
 
STATUS.rp0 working too? I use a comma usually.

Note that your origin of TABLE1 is 0x03, you should change it to 0x300 as suggested.
Do you get what I mean?
The memory location of addwf is 0x0003
The memory location of the first retlw is 0x0004
but you locate TABLE3 to start at 0x0004
 
Hi the program starts from org 0x00
so how can I determine what to put to origin for TABLE1 can I use any value

like org 0x01,org 0x02 etc....
 
Hi if I change the TABLE1 origin to org 0x3

Is this right?
Code:
MAIN	movlw	0x3	;main program starts from 2000 line
	movwf	PCLATH
	call	TABLE1	;call Table1
 
Code:
MAIN	movlw	0x03	;main program starts from 2000 line
	movwf	PCLATH
	call	TABLE1	;call Table1
A better method is:
Code:
MAIN	movlw	HIGH TABLE1	;Let the compiler figure it out for you
	movwf	PCLATH
	call	TABLE1	;call Table1
Another thing to remember is that the ADDWF PCL instruction will not compute a value greater than 8-bits. Some PICs also have an issue that bit 9 of the PC is always cleared by the ADDWF PCL instruction. Which PIC are you using?
how can I determine what to put to origin for TABLE1 can I use any value like org 0x01,org 0x02 etc
No.:eek: Then your tables would overlap. Hopefully the compiler would complain about it if you tried it ;)
 
Suraj143 said:
Hi if I change the TABLE1 origin to org 0x3

Is this right?
Code:
MAIN	movlw	0x3	;main program starts from 2000 line
	movwf	PCLATH
	call	TABLE1	;call Table1

Yes, this is correct. However you need to do as Bananasiong says and change your org statements to ORG 0x300 etc.

Also, to make your code more readable you should change movlw 0x3 to movlw high TABLE1.

Mike.
 
kchriste said:
Code:
Another thing to remember is that the ADDWF PCL instruction will not compute a value greater than 8-bits. Some PICs also have an issue that bit 9 of the PC is always cleared by the ADDWF PCL instruction. Which PIC are you using?
[/QUOTE]

I have not heard of this before. Can you give me the number of a pic that displays this behavior so I can have a look at the data sheet.

Mike.
 
As I said, you can see from the disassembler listing.
movlw HIGH TABLE1
this will take the high side of TABLE1 to w register.
 
Thanks for your replies.I'm using 628A.

Now TABLE1 is ok.its starting from org 0x300

For first two tables it need 200 lines if I place table3 also in the org 0x300 origin it will not enough because its remaining only 56 lines.So I must goto origin 0x400.

Then my TABLE3 I must start from org 0x400 but this is interrupt origin.
 
Suraj143 said:
Thanks for your replies.I'm using 628A.

Now TABLE1 is ok.its starting from org 0x300

For first two tables it need 200 lines if I place table3 also in the org 0x300 origin it will not enough because its remaining only 56 lines.So I must goto origin 0x400.

Then my TABLE3 I must start from org 0x400 but this is interrupt origin.
Interrupt origin is 0x0004, isn't it?
a-gif.13528
 

Attachments

  • a.GIF
    a.GIF
    12.6 KB · Views: 334
Oh I see.Interrupt is 0x0004.

bananasiong said:
Note that your origin of TABLE1 is 0x03, you should change it to 0x300 as suggested.
Do you get what I mean?
The memory location of addwf is 0x0003
The memory location of the first retlw is 0x0004
but you locate TABLE3 to start at 0x0004

If my origin of TABLE1 is 0x300 then how the first memory location of addwf is becoming 0x0003?
Is this 0x300 & 0x0003 is same?

Then the first literal value will be the interrupt address :rolleyes:
 
0x0300 and 0x0003 are not the same.
If the origin of TABLE1 is 0x300, so the location of the addwf in TABLE1 is 0x300, followed by 0x301.....

If the origin of TABLE1 is 0x0003, the location of the addwf in TABLE1 is 0s0003, followed by 0x0004.....
 
Oh I see then I will start the TABLE4 from org 0x400
Then the next instructions in the Table4 followed by 0x401, 402 etc.....

Finally

At one time I saw somewhere telling if the program memory size is less than 2K-words no need to write to PCLATH is this true?

It means if my lines below 2048 then I can directly address to PCL without using PCLATH. In any place from the coding.

Ex: Table1 is in 10th line but I can call from 2000 line?

Thanks a lot.
 
No, you're confused. Reread Pommie's replies.

PCLATH can be used to change page. If you're writing to only the same page (under 2 k), you don't need to change page using PCLATH (usually bit 3 and bit 4).
However if you use PCL after the program memory 0xff, you need to write to PCLATH, even you're just using the same page (same 2 k)
 
Maybe some examples will help,
Code:
	movlw	03
	movwf	PCLATH
	movlw	0x45
	movwf	PCL;	will jump to address 0x345

	movlw	07
	movwf	PCLATH
	movlw	0xac
	movwf	PCL;	will jump to address 0x7ac

	movlw	0x0a
	movwf	PCLATH
	movlw	0x67
	movwf	PCL;	will jump to address 0xa67

As you can see PCLATH is simply copied into the high byte of the program counter when you write to PCL.

Note that in the last case it is jumping to an address outside the lower 2K page and so when it returns you must clear PCLATH or subsequent gotos and calls will go to the second bank.

Mike.
 
You won't find anything more about paging in the datasheet of PIC16F628A which you are using. It is because this device has the flash memory of 2 k. Read the datasheet of other device to know more about that.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top