View Single Post
Old 21-11-2007, 03:50 PM   #1
nguyen.geo
Đệ tử 2 túi
 
Tham gia ngày: Jan 2007
Bài gửi: 27
:
Dspic 30fxxxx EEPROM ????????

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 :

Code:
#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()	}

thay đổi nội dung bởi: namqn, 21-11-2007 lúc 05:39 PM.
nguyen.geo vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn