Microchip Technology SW006022-1N Data Sheet

Page of 338
Memory Allocation and Access
 2012 Microchip Technology Inc.
DS52071B-page 139
7.9
ALLOCATION OF VARIABLES TO REGISTERS
You may specify a fixed register assignment for a particular C variable. It is not recom-
mended that this be done.
Accumulator registers are not allocated by the compiler so it is safe to allocate them 
using the following syntax:
  volatile register int Accum_A asm(“A”);
No other register should be allocated.
7.10
VARIABLES IN EEPROM
The compiler provides some convenience macro definitions to allow placement of data 
into the devices EE data area. This can be done quite simply:
int _EEDATA(2) user_data[] =  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
user_data
 will be placed in the EE data space (space(eedata)) reserving 10 words 
with the given initial values.
The device provides two ways for programmers to access this area of memory. The first 
is via the program space visibility window. The second is by using special machine 
instructions (TBLRDx).
7.10.1
Accessing EEDATA via User Managed PSV
The compiler normally manages the PSV window to access constants stored in 
program memory. If this is not the case, the PSV window can be used to access 
EEDATA memory.
To use the PSV window:
• The psv page register must be set to the appropriate address for the program 
memory to be accessed. For EE data this will be 0xFF, but it is best to use the 
_ _builtin_psvpage()
 function.
• In some devices, the PSV window should also be enabled by setting the PSV bit 
in the CORCON register. If this bit is not set, uses of the PSV window will always 
read 0x0000.
EXAMPLE 7-1: 
EEDATA ACCESS VIA PSV
#include <xc.h>
int main(void) {
  PSVPAG = 
_ _
builtin_psvpage(&user_data);
  CORCONbits.PSV = 1;
  /* ... */
  if (user_data[2]) ;/* do something */
  }
These steps need only be done once. Unless psv page is changed, variables in EE 
data space may be read by referring to them as normal C variables, as shown in the 
example. 
Note:
Using variables specified in compiler-allocated registers - fixed registers - 
is usually unnecessary and occasionally dangerous. This feature is 
deprecated and not recommended.
DD
Note:
This access model is not compatible with the compiler-managed PSV 
(-mconst-in-code) model. You should be careful to prevent conflict.