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
+30000-3FFFF
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.