228/317
8 - C Language and the C Compiler
The effect of the
const
modifier is to generate an error message whenever a statement tries
to assign a new value to that constant, as in the following example:
SIZE = 200 ;/* here the compiler will generate an error message */
This method, standard for C programs, has the drawback of consum ing memory space in
RAM, even for constants that are never written to. This is not acceptable in a microcontroller
where the RAM space is scarce. To alleviate this problem, the compiler offers the
-Cc
com-
mand line option . This option allocates the constant to a special segment named ROM_VAR,
and does not reserve the equivalent space in RAM.
8.3.1.2 EEPROM non-volatile storage
Some members of the ST7 family have, in addition to RAM and ROM, some EEPROM that
constitutes some non-volatile storage to store data and configuration parameters over power-
off periods.
The data that must be saved are read-write variables declared like any other variable. How-
ever, to ensure that these variables are allocated to EEPROM, a special segment must be de-
fined, that will be later linked and located at the start address of the EEPROM.
By default, variables are allocated to the predefined segment DEFAULT_RAM. To direct that
a variable is to be allocated to another segment, a statement such as the following must be
used:
#pragma DATA_SEG MyEEPROM
Where
MyEEPROM
is the name of the new segment that must be defined. All the variables dec-
larations that follow this statement will be placed in the segment
MyEEPROM
. To restore the
normal default segment for the variables that do not reside in EEPROM, the following state-
ment is used:
#pragma DATA_SEG DEFAULT
From that time on, the variables declared are put in the segment DEFAULT_RAM again. The
following example defines a few variables, of which two are placed in EEPROM:
int i, j ;
{ define two integer variables }
#pragma DATA_SEG MyEEPROM
int UserOption ;