12.6 Locating and Accessing Data in EEPROM Memory [DD]
In this example, two arrays are defined in data EEPROM.
Table1
is aligned to a 32-bit address, so it will be eligible for
erasing or programming using the row programming algorithm. Table2
is
defined with standard alignment, so it must be erased or programmed one word at a time. The
macro _EEDATA
is used to place a variable in the Data EEPROM section of
memory and align the variable to the specified byte boundary. This macro is defined in the
processor header files for devices which contain data flash. This example is targeted for
the dsPIC30F6014 processor.
The compiler and linker treat Data EEPROM like any other custom-defined
(psv)
section. The __psv__
access qualifier is used to
instruct the compiler to generate the necessary instructions to manage the PSV or EDS page
register automatically.
/* load SFR definitions and macros */
#include "xc.h"
/* load standard I/O definitions */
#include "stdio.h"
__psv__ unsigned int _EEDATA(32) Table1[16];
__psv__ unsigned int _EEDATA(2) Table2[4]= {0x1234, 0x5678, 0x9ABC,0xDEF0};
unsigned int i, temp_data[4];
__psv__ unsigned int *ee_rd_ptr;
int main( void )
{
/* initialize EEPROM read pointer */
ee_rd_ptr = &Table2[0];
/* read integer data from EEPROM */
temp_data[0] = *ee_rd_ptr++;
temp_data[1] = *ee_rd_ptr++;
temp_data[2] = *ee_rd_ptr++;
temp_data[3] = *ee_rd_ptr;
/* display it */
for ( i = 0; i < 4; i++)
printf(" %x", temp_data[i]);
printf("\n");
}
The equivalent array definitions for Table1
and
Table2
in assembly language appear below. Use of *
as
a section name causes the assembler to generate a unique name based on the source file
name.
.global _Table1
.section *,eedata
.align 32
_Table1:
.space 32
.global _Table2
.section *,eedata
.align 2
_Table2:
.word 0x1234
.word 0x5678
.word 0x9ABC
.word 0xDEF0