winnie 发表于 2009-4-26 11:46:17

dspic30f的EEPROM写程序怎么编写呀?MPLAB C30程序,

读程序:
uint EEPROM_READ(uint addr)
{
WREG1=2*addr+0xFC00; // Init Pointer
TBLPAG=0x7F;
__asm__ volatile("TBLRDL ,W4");//read data EEPROM
return WREG4;
}
写程序我是这样编的:
void EEPROM_WRITE(uint addr,uint value)
{
TBLPAG=0x7F;
WREG1=2*addr+0xFC00; // Init Pointer
WREG0=value;
__asm__ volatile("TBLWTL W0,");
NVMCON=0x4004;
NVMKEY=0x55;
NVMKEY=0xAA;
_WR=1;
Nop();
Nop();
}

winnie 发表于 2009-4-26 11:46:22

void WriteConfig(int addr, int value)
{
TBLPAG=0x7f;
WREG1=2*addr+0xFC00; // Init Pointer
NVMCON=0x4044;
NVMKEY=0x55;
NVMKEY=0xAA;
_WR=1;
Nop();
Nop();
while(_WR);
TBLPAG=0x7f;
WREG1=2*addr+0xFC00; // Init Pointer
WREG0=value;
__asm__ volatile("TBLWTL W0,");
NVMCON=0x4004;
NVMKEY=0x55;
NVMKEY=0xAA;
_WR=1;
Nop();
Nop();
while(_WR);
}


先擦除再写入,调试OK
页: [1]
查看完整版本: dspic30f的EEPROM写程序怎么编写呀?MPLAB C30程序,