2

I am struggling to understand why I get random data while trying to read from multidimensional table that is stored in rom.

I have a table of bitmap character which I want to display on OLED screen. Table of characters is too big to fit into ram and rom is natural place for it. When I try to read elements from the table, data is not the one stored in the table.

Here is what I try to do. I have bitmap declared as a multidimensional array at the begging of the C-file where it is used:

rom const char number[15][4][20] = { {
{0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0x70, 0x78, 0x38, 0x38, 0x38, 0x38, 0x78, 0x70, 0xf0, 0xe0, 0xc0, 0x00, 0x00},// row 1 columns 19
{0x00,...

This is where I try to read the data and print it to the screen:

for(i=0; i<4; i++)
    {
        PutImage(number[digit][i],20,4,offset,i+2);
    }

Implementation of PutImage function:

void PutImage(char ptr[], unsigned char sizex, unsigned char sizey, unsigned char startx, unsigned char starty)
{
unsigned char _page, _column;

//startx += OFFSET;

OledWriteCommand(0xb0+starty);
OledWriteCommand(startx&0x0F);
OledWriteCommand(0x10 | ((startx>>4)&0x0F));

for(_column=0; _column<sizex; _column++)
{
    OledWriteData(ptr[_column]);
}
}

If I change it so that data fits into ram it works just fine. So the problem has to be either that data is not stored correctly in the first place or the way I used it is incorrect.

The Pic I am using is 18F27J53 and datasheet section 7.1 (Table Reads and Table Writes) talks about some Assembler operations that are used for moving bytes between program memory and ram. As I am using C, i am not sure if that is something I need to be aware of or does the compiler know how to handle that.

user2771538
  • 103
  • 1
  • 10
  • can you explain a bit the function interface for PutImage? what are each of the parameters used for? – Pandrei Dec 02 '13 at 12:19

2 Answers2

1

Ok related question and its answer got me to (hopefully) right track: Can I make a function that accepts both ram and rom pointers in Microchip C18?

And thanks to Pandrei as well for pointing out that the implementation if PutImage could be the cause. I got the code working by making duplicate function PutROMImage which accepts "near rom char*" -type instead of just "char*" which defaults to ram.

So C18 does not allow pointers to point both ram and rom and PutImage -function parameter defaults to ram. So passing a pointer to array which is located in rom causes pointer point to random values.

I had not noticed this deficiency in the code and compiler wasn't smart enough to complain about that.

Community
  • 1
  • 1
user2771538
  • 103
  • 1
  • 10
0

having the data in ROM (.txt section) or RAM (.data section) has nothing to do with the problem you are facing.

Assuming that the initialization is correct and you initialize all the elements (if you don't, the elements left out will be default initialized to 0), the problem might be in the function's implementation: PutImage. Since you have problems when the size changes, maybe you have some hard-coded values in there...

Pandrei
  • 4,843
  • 3
  • 27
  • 44
  • please post the implementation for PutImage so that we can see the full picture. – Pandrei Dec 02 '13 at 11:41
  • Thanks for the reply. I added the implementation of PutImage. The thing is number -array won't fit to RAM and rom would be a natural place for thing that dont need to be changed. – user2771538 Dec 02 '13 at 12:12
  • what do you mean it does not fit in RAM? where is it placed then? – Pandrei Dec 02 '13 at 12:16
  • If I do not place the array in program memory, I get following error from linker: "Error - section 'number' can not fit the section. Section 'number' length=0x00000514" In that case I have 'code'#pragma idata number" before the declaration of number -array. – user2771538 Dec 02 '13 at 12:46