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();
} 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]