Quick help with EEPROM

Discussion in 'Programmer's Corner' started by ke5nnt, Dec 16, 2011.

  1. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    I've written a test program in the past to try my hand at writing to and reading from the EEPROM. The program was successful, I was able to store information in the EEPROM and read that value back after a hard reset of the device. Problem is, I would like to know how it works so I can better understand what I'm asking the program to do.

    I'm using MPLAB IDE with the High-Tech C-Lite compiler, writing my program in the C language using a PIC MCU. The test program was written for the 16F628A, but my target device is the 12F629.

    The manual for the C-Lite compiler basically shows an example:
    Code ( (Unknown Language)):
    2. #include <htc.h>
    3. void eetest (void) {
    4.    unsigned char value = 1;
    5.    unsigned char address = 0;
    7.    // write value to EEPROM address
    8.    eeprom_write (address, value);
    9.    // read from EEPROM at address
    10.    value = eeprom_read (address);
    11. }
    Can you tell me, does the variable "address" simply access the first available address of the EEPROM memory? Should this be written as a physical memory address, such as 0Bh or what?
    What format is the variable "value" in? I understand that the line eeprom_write (address, value); places whatever value "value" has into the location "address", but is the line value = 1 placing a decimal 1 or what? If I use a command later in the program that says to increment value (e.g. value++), would the next value used be "2"?

    Thanks all.
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    Read the datashheet

    The call to eeprom_write does not store in the "first available" address, it stores in the address that you specify. In your case address zero or the first location of the eeprom aray.

    You can specify the address in any means that makes more sense to you. Hex, decimal, binary.... it is not going to matter to the compiler.

    Values are being stored as bytes period. That is 8 bits.
    Last edited: Dec 16, 2011
    ke5nnt likes this.
  3. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    Perfect response. Thanks a million!