5.4.4.1 Absolute Objects In Data Memory
Any object which has static storage duration and which has file scope can be placed at an absolute address in data memory, thus all but static objects defined inside a function and stack-based objects can be made absolute.
For example:
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, but to be compatible with the C90
standard, it should be place after the identifier
The compiler will mark storage for absolute objects as being 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 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 5.3.9.4 Near Type Qualifier).
When defining absolute bit
variables (see 5.3.2.1 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);
When compiling for an Enhanced Mid-range PIC device, the address specified for absolute objects can be either a conventional banked memory address or a linear address. As the linear addresses start above the largest banked address, it is clear which type of address has been specified. In the following example:
int input[100] __at(0x2000);
it is clear that input should placed at address 0x2000 in the linear address space, which is address 0x20 in bank 0 RAM in the conventional banked address space.