In the codevision compiler for Atmel processors, there is a possibility to specify the storage address of a global variable, for example
int a @0x100; // will place the variable at the address 0x100 in RAM
Of course, as per standard C, variables can be initialized upon declaration
int a=42;
However, I did not find any possibility to do them both. int a @0x100 = 42
or int a = 42 @0x100;
don't work, they cause compiler errors.
You might ask why it is so important to do it, because one could simply have
int a @0x100;
int main()
{
a = 42;
//...
}
However, if I have variables in the EEPROM, I need to initialize them, because this is the only way to automatically generate the eeprom file with the values in it. I can't assign those values later, because in that case it would actually write the values into the eeprom at each start of the program.
Just a look at CodeVisionAVR
help,
"The following procedure must be used if a global variable, placed at a specific address using the @ operator
, must be initialized during declaration:
/* the variable will be stored in EEPROM at address 0x10 */
eeprom int abc @0x10;
/* and it will be initialized with the value 123 */
eeprom int abc=123;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With