PDA

View Full Version : Dspic 30fxxxx EEPROM ????????


nguyen.geo
21-11-2007, 03:50 PM
Chào các bác! em đang làm 1 đoạn chương trình cho con 30f4011 về phần EEPROM nội. Nhưng không biết rõ lắm về câu lệnh của C30 có hỗ trợ cho việc ghi, đọc và xóa Rom Nội không ? Em tìm được đoạn code này trên Microchip nhưng đọc không hiểu. Các bác giúp em với. Đây là đoạn Code về EEPROM viết bằng C30 :

#include <p30fxxxx.h>
#include <libpic30.h>

_FOSC(CSW_FSCM_OFF & XT_PLL8); /* Set up for XTxPLL8 mode since */
/* we will be tuning the FRC in this example */
_FWDT(WDT_OFF); /* Turn off the Watch-Dog Timer. */
_FBORPOR(MCLR_EN & PWRT_OFF); /* Enable MCLR reset pin and turn off the power-up timers. */
_FGS(CODE_PROT_OFF); /* Disable Code Protection */

/*Declare constants/coefficients/calibration data to be stored in DataEEPROM*/
int _EEDATA(32) fooArrayInDataEE[] = {0x00,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,
0x9,0xA,0xB,0xC,0xD,0xE,0xF};

/*Declare variables to be stored in RAM*/
int fooArray1inRAM[] = {0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF, 0xABCD, 0xBCDE,
0xCDEF, 0xDEFA, 0x0000, 0x1111, 0x2222, 0x3333, 0x4444, 0x5555};
int fooArray2inRAM[16];
int main(void);
void _ISR _DefaultInterrupt(void);
int main(void)
{ _prog_addressT EE_addr;
int temp = 0;

/* initialize a variable to represent the Data EEPROM address */
_init_prog_address(EE_addr, fooArrayInDataEE);

/*Copy array "fooArrayinDataEE" from DataEEPROM to "fooArray2inRAM" in RAM*/
_memcpy_p2d16(fooArray2inRAM, EE_addr, _EE_ROW);

/*Erase a row in Data EEPROM at array "fooArrayinDataEE" */
_erase_eedata(EE_addr, _EE_ROW);
_wait_eedata();

/*Write a row to Data EEPROM from array "fooArray1inRAM" */
_write_eedata_row(EE_addr, fooArray1inRAM);
_wait_eedata();

while(1); /* Place a breakpoint here, run code and refresh the DataEEPROM window in MPLAB IDE */
}
void __attribute__((interrupt, no_auto_psv)) _DefaultInterrupt(void)
{ while(1) ClrWdt() }

namqn
26-11-2007, 07:15 PM
Phần code mà bạn đã post có lẽ nằm trong ví dụ CE017 mới của Microchip. Các hàm đọc, ghi, và xóa EEPROM trong ví dụ đó đã được đưa vào thư viện libpic30. Bạn có thể đọc tài liệu 'MPLAB C30 C Compiler User's Guide', mục 6.7 về việc truy cập EEDATA từ C. Bạn cũng nên đọc tài liệu 'CE017_Readme.txt' đi kèm với source code của ví dụ CE017, trong đó họ có giải thích cách thức sử dụng các hàm của thư viện cũng như thông tin về source code của thư viện.

Thân,