RAM Placed in Fixed Location

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
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.