Page 1 of 1

Create a table with more than 256 byte of data

Posted: Thu Jun 14, 2012 5:47 am
by jeflores
Create a table with more than 256 byte of data, micro pic18F45K20, Using (TBLRD *).

If u can help me with an example would be of great help.
Thanks

Re: Create a table with more than 256 byte of data

Posted: Thu Jun 14, 2012 10:17 am
by Benj
Hello,

The easiest way to do this on a 8-bit PIC is to create multiple arrays of 256 bytes and then have a handler macro to decode the address and decide which array to use.

if (Address > 256)
{
Address = Address - 256
Data = Array1[Address]
}
else
{
Data = Array0[Address]
}

Re: Create a table with more than 256 byte of data

Posted: Thu Jun 14, 2012 10:51 am
by jeflores
Hello thanks for replying, I create multiple tables and as an image I had to do a lot. when I compile the project is a single table, use the instruction (TBLRD *) to read.
GOTO label6
MOVLW UPPER( label27 )
MOVWF TBLPTRU
MOVLW HIGH( label27 )
MOVWF TBLPTRH
MOVLW LOW( label27 )
MOVWF TBLPTRL
label6
MOVF __rom_get_00000_1_romAddr+D'2', W, 1
ADDWF TBLPTRL, F
BTFSC STATUS,C
INCF TBLPTRH, F
BTFSC STATUS,C
INCF TBLPTRU, F
TBLRD*
MOVF TABLAT, W

RETURN
label7
DW 0x0000
DW 0x0000
DW 0x0000
DW 0x5F06
DW 0x0006
DW 0x0307
DW 0x0700
DW 0x2403
DW 0x247E

how to do the reading, which made ​​it impossible for me to create it's like bigger than 256 bytes.
try the # pragma DATA, but I can only put one line and overflows if many characters.

any idea how to tell the compiler to make the data without me errror?
I speak Spanish, I apologize if it is not very clear trduccion, google helped me

Re: Create a table with more than 256 byte of data

Posted: Thu Jun 14, 2012 12:07 pm
by Benj
Hello I think the problem is due to the PIC's memory being placed into banks. Each bank of RAM is 256 bytes wide and therefore you cannot have a array that spans across multiple banks.

I think the assembler code should work but you may have to add the bank switching instructions in to allow you to access the other locations.

The C code and Flowcode will automatically do the bank switching for you on the example I posted earlier so you need not worry about having to do any of this.

It should be possible to create macros to read and write to the data array using multiple arrays of 256 bytes from a single address variable.

Re: Create a table with more than 256 byte of data

Posted: Fri Jun 15, 2012 3:34 am
by jeflores
Thanks, so I will.