RAM Placed in Fixed Location
Last modified by Microchip on 2024/01/19 00:09
You have the option to place specific Random Access Memory (RAM) variables at a fixed location within your source code. This forces the allocation of the variable to a fixed location so that it won't move between firmware versions. This is also useful for boot loaders or applications that are compiled separately and need to access a fixed-location communications register.
/*******************************************************************************
* RAM variables placed at a fixed location.
*
******************************************************************************/
#if defined(__XC8__)
#ifdef __CCI__
unsigned char myRamVariable __at(0x20);
#else
unsigned char myRAMVariable @ 0x20;
#endif
#elif defined(__XC16__)
/* it is strongly discouraged from placing variables at fixed addresses */
#ifdef __CCI__
unsigned char myRAMVariable __at(0x2000);
#else
/* the toolchain will place this at address 0x2000 even if that address does
not exist on the device - we assume you know what you are doing */
unsigned char myRAMVariable __attribute__((address(0x2000)));
#endif
#elif defined(__XC32__)
/* Use absolute addresses, only when absolutely necessary as they can
increase the size of the data-init table. */
#ifdef __CCI__
unsigned char myRAMVariable __at(0xA0001000);
#else
unsigned char myRAMVariable __attribute__((address(0xA0001000)));
#endif
#endif
* RAM variables placed at a fixed location.
*
******************************************************************************/
#if defined(__XC8__)
#ifdef __CCI__
unsigned char myRamVariable __at(0x20);
#else
unsigned char myRAMVariable @ 0x20;
#endif
#elif defined(__XC16__)
/* it is strongly discouraged from placing variables at fixed addresses */
#ifdef __CCI__
unsigned char myRAMVariable __at(0x2000);
#else
/* the toolchain will place this at address 0x2000 even if that address does
not exist on the device - we assume you know what you are doing */
unsigned char myRAMVariable __attribute__((address(0x2000)));
#endif
#elif defined(__XC32__)
/* Use absolute addresses, only when absolutely necessary as they can
increase the size of the data-init table. */
#ifdef __CCI__
unsigned char myRAMVariable __at(0xA0001000);
#else
unsigned char myRAMVariable __attribute__((address(0xA0001000)));
#endif
#endif