Issue Observed in data saving in EEPROM of pic16f887

Hi ,

I use EEPROM of PIC16f887 for data saving. Value increment by switch press and same store in EEPROM and display.

Both value of number and EEPROM Display on LCD.

Issue Observed: EEPROM Value same as last incremented value during reset the controller.

EEPROM value not same as per last incremented value when power to IC Turn off for more than 30 Sec.

Based on your description, it sounds like your EEPROM data is not persisting across power cycles that last for more than 30 seconds, despite the fact that EEPROM (Electrically Erasable Programmable Read-Only Memory) is designed to maintain its contents even when power is lost. There could be several reasons for this issue, including problems with your hardware, software, or both.

  1. Write Timing: It might be possible that you are not allowing enough time for the write operation to complete before you are cutting the power. EEPROM writes require a certain amount of time to complete, and this time can vary depending on the specific EEPROM chip used. You should consult the datasheet of your PIC16F887 to determine how much time is required for a write operation and ensure that this duration has passed before cutting power.
  2. Power Supply Issues: If there are issues with your power supply, such as a slow ramp-down of power, this might cause issues with the EEPROM.
  3. Data Corruption: This could occur if the PIC16F887 is writing to the EEPROM while power is lost. To avoid this, consider adding a power-fail detection circuit to your design, which can stop the microcontroller from attempting to write to the EEPROM during a power loss.
  4. Software issues: Ensure you’re following the correct sequence of operations to write data to EEPROM, such as unlocking the memory, performing the write, and waiting for the write to complete before continuing.

Here’s a basic example of writing data to the EEPROM of a PIC microcontroller:

c

void write_EEPROM(int address, int data){
    while(EECON1bits.WR); // wait until the last attempt to write is finished
    EECON1bits.WREN = 1; // enable writing to EEPROM
    EEADR = address; // load the address we want to write to
    EEDATA = data; // load the data we want to write
    EECON1bits.EEPGD = 0; // access EEPROM data memory (not program memory)
    EECON2 = 0x55; // part of the sequence to write data
    EECON2 = 0xAA; // part of the sequence to write data
    EECON1bits.WR = 1; // initiate a write
    while(EECON1bits.WR); // wait until the write is finished
    EECON1bits.WREN = 0; // disable writing to EEPROM
}

Make sure your code follows a similar pattern to the code above when writing data to the EEPROM. If you continue to have issues, you may want to consider seeking help from Microchip’s technical support or user forums. They might be able to offer more specific advice based on their expertise with these microcontrollers.