How do I access a variable in external program space of PIC18 Device?

With MPLAB® XC8, the far type qualifier is used to place variables into the external program space of PIC18 devices. Only some devices support the External Memory Interface (EMI).

Accesses to far variables are less efficient than accesses to internal variables, and extensive accesses to these variables will result in larger code sizes.

Here is an example of an unsigned int object placed into the device’s external code space:

Note that a --RAM option is mandatory to specify the external address range where far variables will reside. In the MPLAB X IDE >Project Properties > XC8 Linker Category > Memory Model drop-down menu, add the additional memory into the RAM Ranges field.

For example, specify
into the RAM Ranges field to supply the information to the Linker that additional memory is in the range of 30000-3FFFF.

You may also want to set the --EMI option to select which mode your device will use to access the external memory. In MPLAB X IDE, adjust the External Memory field in the Linker tab of the Build Options dialog > Memory Model > External Memory to Wordwrite / Bytewrite/ Byteselect.

Refer to the Compiler manual for more information relating to these options.

Configuration bits and Special Function Registers (SFRs) may need to be set up to configure the device to use the external memory.

© 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.