View previous topic :: View next topic |
Author |
Message |
UKH Guest
|
Array's at FLASH-ROM |
Posted: Fri Oct 10, 2003 3:21 am |
|
|
I hope that somebody can help me with my problem:
I have some array's (CONST byte array[]) in my programm for 18F452/458 und use the PCH-Compiler (lastest version 3.178). Sometimes in my programm this could be:
test = array[23]; // get values from ROM
The compiler optimize this and use the value of array at compiling-time. The problem is that this parts of FLASH will be changed during runtime, so arrry[23] differs in runtime.
Do I have a chance to avoid this ??
My current solution isn't nice:
tmp4 = 23;
test = array[tmp4];
Sorry for my poor English.
Kind regards
Uwe |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Oct 10, 2003 6:16 am |
|
|
Check out read_program_eeprom(). If you locate the array, you should be able to use this function. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Oct 10, 2003 9:15 am |
|
|
Mark wrote: | Check out read_program_eeprom(). If you locate the array, you should be able to use this function. |
Realistically, it is also worth considering using the internal EEPROM, rather than the main program memory, if this data is going to change more than once or twice. The 'life cycle' of the internal program memory, is far lower than that of the EEPROM (though both memories are 'EEPROM' in nature), and putting constant tables into the EEPROM, frees the program memory to hold code.
It is worth remembering that you can use the #define ability, to give a 'psuedo' array access nature to the EEPROM, with something like:
#define first_array (0)
#define second_array (20)
#define get_array(x,y) (int8)read_data_eeprom(x+y)
Then you can use code like:
get_array(first_array,4);
to read the fifth byte from the first array.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
brianj
Joined: 06 Oct 2003 Posts: 6 Location: Liverpool, UK
|
|
Posted: Sat Oct 11, 2003 5:46 am |
|
|
You could try the 'volatile' keyword.
volatile const char string[] = "HELLO" ;
x = string [0] ;
I haven't tried it in operation, but I can see from the assembler output that it's passing a parameter to a subroutine to get the first character rather than just using 'H'.
Brian |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Oct 11, 2003 8:42 am |
|
|
volatile is not used in CCS compiler. The array is declared as const which is the root of the problem. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sat Oct 11, 2003 9:51 am |
|
|
>volatile is not used in CCS compiler
It is in the one I'm using (v3.177d)!
volatile isn't mentioned in the help file, but the compiler accepts it without complaint and produces assembly output for the access to the constant in flash which looks like it could be re-reading the flash instead of using the value which was there at compile time.
Brian |
|
![](templates/subSilver/images/spacer.gif) |
brianj
Joined: 06 Oct 2003 Posts: 6 Location: Liverpool, UK
|
|
Posted: Sat Oct 11, 2003 9:53 am |
|
|
Sorry, the last post was from me (brianj). I forgot to log in.
Brian |
|
![](templates/subSilver/images/spacer.gif) |
|