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.

Page boundary problem

Status
Not open for further replies.

Suraj143

Active Member
Hi! I’m using PIC16F628A.

If I use a data lookup table with PCL register I have to place the table in between the first 256 lines.
(Let say my program is having 1500 lines if I place the table in the end it wont work.)

Then what about the delay routines do I have place that also in the first 256 lines in my 1500 line program? Or can I place that in any location?
 
You can place your table anywhere if you use 16 bit maths to calculate the jump.
Code:
		movlw	high(Table)
		movwf	PCLATH
		movlw	low(Table)
		addwf	Pointer,W
		btfsc	STATUS,C
		incf	PCLATH,F
		movwf	PCL
Table		DT	"Hello World!",0

Pointer would contain the offset into Table. Your table would still be limited to 256 bytes long.

If you make the pointer 16 bit then you can have a table of any length.

Your delay routines can go anywhere unless they use computed goto's.

Mike.
 
Oh I see. Thanks Mike for the instant reply. But I have some small doubts.

High (Table) & Low (Table) means the first retlw xxx value & the last retlw xxx in the table?
Is Pointer is a GP register?

If I add your coding I can place the table in anywhere.
Code:
If you make the pointer 16 bit then you can have a table of any length.
Then to make the pointer to 16 bit do I have to shift to 16 bit microcontroller?
 
Suraj143 said:
Oh I see. Thanks Mike for the instant reply. But I have some small doubts.

High (Table) & Low (Table) means the first retlw xxx value & the last retlw xxx in the table?
Is Pointer is a GP register?

If I add your coding I can place the table in anywhere.
Code:
If you make the pointer 16 bit then you can have a table of any length.
Then to make the pointer to 16 bit do I have to shift to 16 bit microcontroller?

Hi suraji,

The Program Counter PC is 13 bits wide, the PCLATH contents is the upper 5 bits of this 13 bit PC.

Is this clear?
 
Last edited:
As long as the table is smaller than 256 bytes, you can place it in any 256 byte 'block', and just set the PCLATH bits accordingly - however, it's often easier (although only marginally) to just place the table in the first 256 bytes.
 
Thanks erricgibbs for the information.

How do I know my table is how much in bytes?

I have ten lines using RETLW XX.
 
hi,
The easy way to get your table length, place it at the start of a block, compile it and look at the hex file.

Or you could count each instruction in your table code, look at the disassembly file this will also help.
>>> I have ten lines using RETLW XX.

I would suggest you use the PCLATH method, its a more general solution.
As pommie has posted.
movlw high(Table)
movwf PCLATH
movlw low(Table)
addwf Pointer,W
btfsc STATUS,C
incf PCLATH,F
movwf PCL
Table DT "Hello World!",0
 
Code:
;
Table   dt      0x0E,0xA0, "4585", 0xD0,0xC4    ;18F4585   9.0-12.5 VDD
        dt      0x0C,0x20, "4610", 0xD1,0x00    ;18F4610   9.0-12.5 VDD
        dt      0x0C,0x00, "4620", 0xD1,0x04    ;18F4620   9.0-12.5 VDD
        dt      0x0E,0x80, "4680", 0xD1,0x04    ;18F4680   9.0-12.5 VDD
Total   equ     ($-Table)
Assemble, then look at the Total line in your .lst file...
 
Oh I see I have to assembled and see how much is it…

movlw high(Table) means the first line of the table value?
movlw low(Table) means the last line of the table value?

Thanks a lot
 
Suraj143 said:
Thanks erricgibbs for the information.

How do I know my table is how much in bytes?

I have ten lines using RETLW XX.

PIC's don't deal in bytes, they use words - ten lines is 10 words, a VERY small table - put it near the beginning of the program, no problems.
 
Suraj143 said:
Oh I see I have to assembled and see how much is it…

movlw high(Table) means the first line of the table value?
movlw low(Table) means the last line of the table value?

Thanks a lot

hi,
No, the high(table) value is the upper 5 bits of the PC, [address] and the low(table) is lower 8 bits of the PC [address]. Together they make the pointer to the character in the table.

Just for explanation. [not a real case]
Suppose the upper 5 bits were 00000 and the table started at 00000
then the first character would be at address 00000,0000,0000 and the
second char would be at 00000,0000,0001........
This is a poor example, but it may help you to get the idea.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top