int main(void)
{
fnInitLcd();
i = fnReadEEByTable(2);
fnDigiDisplay( i );
fnEraseEE(2);
fnWriteEE(2,6);
while(1);
}
void fnWriteCmd(unsigned int Cmd)
{
NVMCON = Cmd;
asm volatile ("push SR");
asm volatile ("mov #0x00e0,w0");
asm volatile ("ior SR");
asm volatile ("mov #0x55,w0");
asm volatile ("mov w0,NVMKEY");
asm volatile ("mov #0xAA,w1");
asm volatile ("mov w1,NVMKEY");
asm("NOP");
asm("NOP");
asm volatile ("pop SR");
NVMCONbits.WR = 1;
while(NVMCONbits.WR == 1);
}
unsigned int fnReadEEByTable(unsigned int addr) //通过表读指令从EEPROM中读一行指令到RAM
{
unsigned int ReturnValue;
TBLPAG = 0x7F;
WREG0 = addr*2+0xfc00;
asm volatile("TBLRDL [w0], w4");
ReturnValue = WREG4;
return ReturnValue;
}
void fnEraseEE(unsigned int OffsetAddr) // 擦除EEPROM中指定的一个字数据
{
NVMADRU = 0x7F;
NVMADR = OffsetAddr*2+0xfc00;
fnWriteCmd(EE_ERASE_WORD);
NVMCONbits.WREN = 0;
}
void fnWriteEE(unsigned int OffsetAddr,unsigned int SourceArray) // 向EEPROM中指定的行写入一个字数据
{
WREG1 = SourceArray;
WREG2 = OffsetAddr*2 + 0xfc00;
asm volatile("TBLWTL.W w1, [w2]");
fnWriteCmd(EE_WRITE_WORD);
NVMCONbits.WREN = 0;
}
这是我写的对dsPICD30f5015内部EEPROM 擦除和写操作的代码,我先擦除再写最后读出来在LCD上显示
但是擦不了写不上,不知道哪里的问题,求指点 |