求助EEPROM问题
程序如下,用SIM仿真时可以擦除但无法写入 在最后一句死循环,请高手看看问题在哪谢谢!#include <p30F6010A.h>
#include <math.h>
int main ( void )
{
EEPROM_W(16,0xF002);
}
void EEPROM_W(unsigned int EE_DATA,unsigned int EE_ADDR )
{
NVMCON=0x4044;
NVMADRU=0x7F;
NVMADR=(unsigned int)(EE_ADDR);
asm volatile("mov #0x55,w0");
asm volatile("mov w0,NVMKEY");
asm volatile("mov #0xAA,w0");
asm volatile("mov w0,NVMKEY");
NVMCONbits.WR=1;
while( NVMCONbits.WR==1);
NVMCONbits.WREN=0;
asm volatile("NOP");
TBLPAG=0x7F;
WREG4=(unsigned int)EE_DATA;
WREG5=(unsigned int)EE_ADDR;//目标数据地址
asm volatile("TBLWTL w4,");
NVMCON=0x4004;
asm volatile("mov #0x55,w0");
asm volatile("mov w0,NVMKEY");
asm volatile("mov #0xAA,w0");
asm volatile("mov w0,NVMKEY");
NVMCONbits.WR=1; //开始写
while(NVMCONbits.WR=1); //检测寄存器
} 在NVMKEY代码后面增加2个Nop().
页:
[1]