5.4.4.1 Absolute Objects In Data Memory
Any object that has static storage duration and file scope can be placed
at an absolute address in data memory; thus, all objects except for static
objects defined inside a function and stack-based objects can be made absolute.
volatile unsigned char Portvar __at(0x06);
will
declare a variable called Portvar
located at 06h in the data memory. Note
that the __at()
construct can be placed before or after the variable
identifier in the definition.The compiler will mark storage for absolute objects as used if the address
is within general-purpose RAM (GPR). Note that address 0 (zero) is not considered to be
part of the GPR for PIC18 devices. Taking the address of an object at this address would
yield a NULL
pointer, and the compiler often uses this location for
internally-defined objects. You should not place absolute objects at address 0.
No checks are made for the overlap of absolute variables with other absolute variables. There is no harm in defining more than one absolute variable to live at the same address if this is what you require. No warning will be issued if the address of an absolute object lies outside the memory of the device or outside the GPR defined by the linker classes.
Absolute variables in RAM cannot be initialized when they are defined and are not cleared by the runtime startup code. After defining absolute variables, assign them an initial value at a suitable point in your main-line code, if required.
Objects should not be made absolute to force them into common (unbanked)
memory. Always use the __near
qualifier for this purpose (see Near Type Qualifier).
bit
variables (see Bit Data Types And Variables), the address
specified must be a bit address. A bit address is obtained by multiplying the byte address
by 8, then adding the bit offset within that bit. For example, to place a
bit
variable called mode at bit position #2 at address 0x50, use the
following:bit mode __at(0x282);
int input[100] __at(0x2000);
it is clear
that input
should be placed at address 0x2000 in the linear address space,
which corresponds to address 0x20 in bank 0 RAM in the conventional banked address
space.