MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
EXAMPLE 7-2: EEDATA ACCESS VIA PSV<br />
#include <br />
int main(void) {<br />
PSVPAG = __builtin_psvpage(&user_data);<br />
CORCONbits.PSV = 1;<br />
/* ... */<br />
if (user_data[2]) ;/* do something */<br />
Device Support Files<br />
}<br />
These steps need only be done once. Unless PSVPAG is changed, variables in EE<br />
data space may be read by referring to them as normal C variables, as shown in the<br />
example.<br />
Note: This access model is not compatible with the compiler-managed PSV<br />
(-mconst-in-code) model. You should be careful to prevent conflict.<br />
7.7.2 Accessing EEDATA using TBLRDx instructions<br />
The TBLRDx instructions are not directly supported by the compiler, but they can be<br />
used via inline assembly. Like PSV accesses, a 23-bit address is <strong>for</strong>med from an SFR<br />
value <strong>and</strong> the address encoded as part of the instruction. To access the same memory<br />
as given in the previous example, the following code may be used:<br />
To use the TBLRDx instructions:<br />
• The TBLPAG register must be set to the appropriate address <strong>for</strong> the program<br />
memory to be accessed. For EE data, this will be 0x7F, but it is best to use the<br />
__builtin_tblpage() function.<br />
• The TBLRDx instruction can be accessed from an __asm__ statement or through<br />
one of the __builtin_tblrd functions; refer to the “<strong>dsPIC</strong>30F/33F<br />
Programmer’s Reference Manual” (DS70157) <strong>for</strong> in<strong>for</strong>mation on this instruction.<br />
EXAMPLE 7-3: EEDATA ACCESS VIA TABLE READ<br />
#include <br />
#define eedata_read(src, offset, dest) { \<br />
register int eedata_addr; \<br />
register int eedata_val; \<br />
\<br />
eedata_addr = __builtin_tbloffset(&src)+offset; \<br />
__asm__("tblrdl [%1], %0" : "=r"(eedata_val) : "r"(eedata_addr)); \<br />
dest = eedata_val; \<br />
}<br />
int main(void) {<br />
int value;<br />
TBLPAG = __builtin_tblpage(&user_data);<br />
eedata_read(user_data,2*sizeof(user_data[0]), value);<br />
if (value) ; /* do something */<br />
}<br />
© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 97