[PIC®/AVR®/dsPIC®产品] PIC16F18344的EEPROM操作

[复制链接]
3368|4
 楼主| fangyixm 发表于 2021-7-5 15:40 | 显示全部楼层 |阅读模式
   在使用PIC16F18344的内部eeprom时,写入数据,然后读出来,很多地址的数据都不对,这会什么原因?中断已经关闭。
void DATAEE_WriteByte(uint8_t bAdd, uint8_t bData)
{
    uint8_t GIEBitValue = INTCONbits.GIE;

    NVMADRH = 0;
    NVMADRL = bAdd; //+ EEP_OFFSET;
    NVMDATL = bData;   
    NVMCON1bits.NVMREGS = 1;
    NVMCON1bits.WREN = 1;
    INTCONbits.GIE = 0;     // Disable interrupts
    NVMCON2 = 0x55;
    NVMCON2 = 0xAA;
    NVMCON1bits.WR = 1;
    NOP();  // NOPs may be required for latency at high frequencies
    NOP();   
    // Wait for write to complete
    while (NVMCON1bits.WR)
    {
    }

    NVMCON1bits.WREN = 0;
    INTCONbits.GIE = GIEBitValue;   // restore interrupt enable
}

uint8_t DATAEE_ReadByte(uint8_t bAdd)
{
    NVMADRH = 0;
    NVMADRL = bAdd; //+ EEP_OFFSET;
    NVMCON1bits.NVMREGS = 1;   
    NVMCON1bits.RD = 1;
    NOP();  // NOPs may be required for latency at high frequencies
    NOP();
    NOP();  // NOPs may be required for latency at high frequencies
    NOP();
    return (NVMDATL);
}
xinxianshi 发表于 2021-7-5 16:22 | 显示全部楼层
先清除再写,试试。
lcczg 发表于 2021-7-5 16:49 | 显示全部楼层
你的地址是否加了7000h? 如下数据手册所述:
11.4.3 NVMREG WRITE TO EEPROM
Writing   to   the   EEPROM   is   accomplished   by   the
following steps:1.Set  the  NVMREGS  and  WREN  bits  of  theNVMCON1 register.
2.Write the desired address (address +7000h) into the     NVMADRH:NVMADRL     register     pair
 楼主| fangyixm 发表于 2021-7-5 19:20 | 显示全部楼层
对,就是这个偏移地址的问题
guijial511 发表于 2021-7-5 21:01 来自手机 | 显示全部楼层
地址操作不对
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

5

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部