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 external program space of PIC18 devices. Only some devices support the external memory interface.

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:

Example:

Note that a --RAM option is mandatory to specify the external address range where far
variables will reside. In 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
+30000-3FFFF
into the RAM Ranges field to supply the information to Linker that additional memory is in the Range of 30000-3FFFF.

You may also want to set the --EMI (External Memory Interface) 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 = Wordwrite / Bytewrite/ Byteselect.

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

Configuration bits and SFRs may need to be set up, to configure the device to use the external memory.

© 2016 Microchip Technology, Inc.
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.