Microchip Technology SW006022-2N Data Sheet

Page of 338
MPLAB
®
 XC16 C Compiler User’s Guide
DS52071B-page 140
 2012 Microchip Technology Inc.
7.10.2
Accessing EEDATA Using TBLRDx Instructions
The TBLRDx instructions are not directly supported by the compiler, but they can be 
used via inline assembly or compiler built-in functions. Like PSV accesses, a 23-bit 
address is formed from an SFR value and the address encoded as part of the instruc-
tion. To access the same memory as given in the previous example, the following code 
may be used:
To use the TBLRDx instructions:
• The TBLPAG register must be set to the appropriate address for the program 
memory to be accessed. For EE data, this will be 0x7F, but it is best to use the 
_ _builtin_tblpage()
 function.
• The TBLRDx instruction can be accessed from an __asm__ statement or through 
one of the __builtin_tblrd functions; refer to the “dsPIC30F/33F 
Programmer’s Reference Manual”
 (DS70157) for information on this instruction.
EXAMPLE 7-2: 
EEDATA ACCESS VIA TABLE READ
#include <p30Fxxxx.h>
#define eedata_read(src, offset, dest) {  \
  register int eedata_addr;               \
  register int eedata_val;                \
                                          \
  eedata_addr = 
_ _
builtin_tbloffset(&src)+offset; \
  eedata_val = 
_ _
builtin_tblrdl(eedata_addr); \
  dest = eedata_val;                      \
  }
char user_data[] __attribute__((space(eedata))) = { /* values */ };
int main(void) {
  int value;
  TBLPAG = 
_ _
builtin_tblpage(&user_data);
  eedata_read(user_data,2*sizeof(user_data[0]), value);
  if (value) ; /* do something */
  }