11.11.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 instruction. 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 EEData, 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 16-Bit MCU and DSC Programmer’s Reference Manual (DS-70000157) for information on this instruction.
EEData Access Via Table Read
#include <xc.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 */
}