Microchip Technology SW006021-1N Manuel D’Utilisation
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 176
2012 Microchip Technology Inc.
5.5.4.2
ABSOLUTE OBJECTS IN PROGRAM MEMORY
Non-auto objects qualified const can also be made absolute in the same way,
however, the address will indicate an address in program memory. For example:
however, the address will indicate an address in program memory. For example:
const int settings[] @ 0x200 = { 1, 5, 10, 50, 100 };
will place the array settings at address 0x200 in the program memory.
Both initialized and uninitialized const objects can be made absolute. That latter is
useful when you only need to define a label in program memory without making a
contribution to the output file.
useful when you only need to define a label in program memory without making a
contribution to the output file.
Variables can also be placed at specific positions by using the psect pragma, see
Section 5.14.4.8 “The #pragma psect Directive”. The decision whether variables
should be positioned this way or using absolute variables should be based on the loca-
tion requirements. Using absolute variables is the easiest method, but only allows
placement at an address which must be known prior to compilation. The psect
pragma is more complex, but offers all the flexibility of the linker to position the new
psect into memory. You can, for example, specify that variables reside at a fixed
address, or that they be placed after other psects, or that the they be placed anywhere
in a compiler-defined or user-defined range of address.
Section 5.14.4.8 “The #pragma psect Directive”. The decision whether variables
should be positioned this way or using absolute variables should be based on the loca-
tion requirements. Using absolute variables is the easiest method, but only allows
placement at an address which must be known prior to compilation. The psect
pragma is more complex, but offers all the flexibility of the linker to position the new
psect into memory. You can, for example, specify that variables reside at a fixed
address, or that they be placed after other psects, or that the they be placed anywhere
in a compiler-defined or user-defined range of address.
5.5.5
Variables in EEPROM
For devices with on-chip EEPROM, the compiler offers several methods of accessing
this memory. You can defined named variables in this memory space, or use
block-access routines to read or write EEPROM. The EEPROM access methods are
described in the following sections.
this memory. You can defined named variables in this memory space, or use
block-access routines to read or write EEPROM. The EEPROM access methods are
described in the following sections.
5.5.5.1
EEPROM INITIALIZATION
For those devices that support external programming of their EEPROM data area, the
__EEPROM_DATA()
__EEPROM_DATA()
macro can be used to place initial values into the HEX file ready
for programming. The macro is used as follows.
#include <xc.h>
__EEPROM_DATA(0, 1, 2, 3, 4, 5, 6, 7);
The macro has eight parameters, representing eight data values. Each value should be
a byte in size. Unused values should be specified with zero.
a byte in size. Unused values should be specified with zero.
The macro may be called multiple times to define the required amount of EEPROM
data. It is recommended that the macro be placed outside any function definition.
data. It is recommended that the macro be placed outside any function definition.
This macro cannot used to write to EEPROM locations during runtime; it is used for
pre-loading EEPROM contents at program time only.
pre-loading EEPROM contents at program time only.
For convenience, the macro _EEPROMSIZE represents the number of bytes of
EEPROM available on the target device.
EEPROM available on the target device.