Quick help with EEPROM

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
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:
Rich (BB code):
#include <htc.h>
void eetest (void) {
   unsigned char value = 1;
   unsigned char address = 0;

   // write value to EEPROM address
   eeprom_write (address, value);
   // read from EEPROM at address
   value = eeprom_read (address);
}
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.
 

spinnaker

Joined Oct 29, 2009
7,830
Read the datashheet

The data EEPROM is a nonvolatile memory array, separate from the data RAM and program memory, which is used for long-term storage of program data.
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:
Top