View previous topic :: View next topic |
Author |
Message |
rolox
Joined: 25 Dec 2014 Posts: 33
|
Table in ROM PIC18 |
Posted: Sat Nov 07, 2015 8:09 am |
|
|
Hi,
i know, its a repeating topic, but could not find solution.
I'm changing from a PIC16F1877 to a PIC18F26K20
Changes in source are quite few - but i can't get my ROM tables work, the are created in RAM :-(
this line places a table in ROM for PIC16F :
Code: | char rom Font32x48Data1[]={ 0x01,0x02,0x03 ....} |
Accessing via pointer works perfect.
But the same line puts Data into RAM (as i can see at the given RAM usage after compiling) , but all filled with 0x00 (as checked while debugging..
any hints ?
best regards
Roland |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Nov 07, 2015 8:39 am |
|
|
Classic first line for reply:
"What compiler version?".
It certainly doesn't put the data in RAM on any version I have here.
Just tried with the font from my ssd1306 driver, and simple code:
Code: |
#include <18F26k20.h>
#device ADC=10
#use delay(crystal=20000000)
char rom font[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
//.....140 font entries.
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE //final one closing shape 140
};
//540 byte array
void main()
{
int8 test,ctr;
while(TRUE)
{
for (ctr=0;ctr<sizeof(font);ctr++)
test=*(font+ctr);
}
}
|
and it is using 6 bytes of RAM. and 720 bytes ROM for the whole program..... |
|
|
rolox
Joined: 25 Dec 2014 Posts: 33
|
|
Posted: Sat Nov 07, 2015 9:56 am |
|
|
compiler is 5.051 ...pretty up-to-date....
your example is the construction i'm using too ...
tried it with my font files too ...and fonts go to ROM as expected.
Now i have to check where the difference is to the "big" code ...
best regrads
Roland |
|
|
rolox
Joined: 25 Dec 2014 Posts: 33
|
|
Posted: Sat Nov 07, 2015 10:34 am |
|
|
i can reproduce the effect in my "big" code, but not in a small test program.
If i include my font files in a method as follows, the RAM is used :
Code: | void InitFonts()
{
#ifdef USE_FLASH
//do something
#else
#include "font 32x48.c"
//do something else
#endif
} |
if i place the #ifdef statement OUTSIDE the function call, everything works as expected.
But : if i use this small method in a small example code, it works too.
And it worked with the PIC16. Anyway ...i'm happy with the solution so far.
best regards
Roland |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun Nov 08, 2015 2:41 am |
|
|
#including the file inside a routine, implies the variable will become local. Now it shouldn't really cause the behaviour you are seeing, but in some ways it makes a sort of warped 'sense', since a pointer accessible constant has to exist globally (after all it is constant).
It is worthy of reporting to CCS, if you can generate a repeatable example that does it...
At least you know how to work round this:
Code: |
#ifndef USE_FLASH
#include "font 32x48.c"
#endif
void InitFonts()
{
#ifdef USE_FLASH
//do something
#else
//do something else
#endif
}
|
|
|
|
|