11.11.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 EEData 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.

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 EEData space may be read by referring to them as normal C variables, as shown in the example.

Note: This access model is not compatible with the compiler-managed PSV (-mconst-in-code) model. You should be careful to prevent conflict.