📄 example_locate_access_eeprom.c
字号:
/* Example illustrating how to locate and access data in EEPROM Memory*/
/***********************************************************************
* 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 *
* all the processor header files, except the ones that don't have *
* data flash. This example is targeted for the dsPIC30F6014 processor,*
* and includes the processor header file p30f6014.h or optionally *
* p30fxxxx.h. *
* *
* The compiler and linker treat Data EEPROM like any other custom- *
* defined (psv) section. The compiler will not set the PSV bit in the *
* CORCON register or set the PSVPAG to access Data EEPROM; you must *
* perform these tasks manually. Once the PSV bit and PSVPAG are set *
* for Data EEPROM, the compiler can freely access any variables stored*
* there. As this example shows, you can use the __builtin_psvpage() *
* and __builtin_psvoffset() helper functions for variables stored *
* in Data EEPROM. *
* *
* If an application stores constants in the compiler-managed PSV *
* section of program memory (auto_psv) and Data EEPROM, the compiler *
* will set the PSV bit in the CORCON register and set PSVPAG for *
* the compiler-managed PSV section on startup (in crt0.s). You must *
* manually modify PSVPAG to access Data EEPROM. Namely, the original *
* PSVPAG must be saved before the access, and then restored after the *
* access. *
* *
* Note 1: When placing variables in Data EEPROM, the const qualifier *
* is optional. *
* 2: The ((address ( ))) attribute can be used to locate *
* variables in Data EEPROM to a specific address. *
* *
* *
* For additional information about dsPIC architecture and language *
* tools, refer to the following documents: *
* *
* MPLAB C30 Compiler User's Guide : DS51284 *
* dsPIC 30F MPLAB ASM30, MPLAB LINK30 and Utilities *
* User's Guide : DS51317 *
* Getting Started with dsPIC DSC Language Tools : DS51316 *
* dsPIC 30F Language Tools Quick Reference Card : DS51322 *
* dsPIC 30F 16-bit MCU Family Reference Manual : DS70046 *
* dsPIC 30F Programmer's Reference Manual : DS70030 *
* *
* Example file has been compiled with MPLAB C30 v1.30.00 *
* *
************************************************************************
* *
* Author: *
* Company: *
* Filename: Ex_Locate_Access_EEPROM.c *
* Date: 02/01/2005 *
* File Version: 1.00 *
* Other Files Required: p30f6014.gld *
* Tools Used: MPLAB IDE -> 7.01.00 *
* Compiler -> 1.30.00 *
* Assembler -> 1.30.00 *
* Linker -> 1.30.00 *
* *
***********************************************************************/
/* Include the appropriate header (.h) file, depending on device used */
/* Example (for dsPIC30F5013): #include <p30f5013.h> */
/* Alternatively include the generic header file, p30fxxxx.h, as shown
below. */
/* load SFR definitions and macros */
#include "p30fxxxx.h"
unsigned int _EEDATA(32) Table1[16]={0};
unsigned int _EEDATA(2) Table2[4]= {0x1234, 0x5678, 0x9ABC, 0xDEF0};
unsigned int *ee_rd_ptr;
unsigned int temp_data[4];
int main( void )
{
/* enable the PSV window since no program constants
are stored in program memory */
CORCONbits.PSV = 1;
/* set the PSV page using a built-in function */
PSVPAG = __builtin_psvpage(&Table2);
/* initialize EEPROM read pointer using a built-in function */
ee_rd_ptr = (unsigned int *) __builtin_psvoffset(&Table2);
/* 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;
while ( 1 );
}
/* 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -