I've been trying to learn how to save several variables of information to eeprom memory which can be recalled later which will be stored like a selection of recipes.
I know the 16F877A has 256 Bytes of eeprom memory but how many byte will each number variable take-up.
Also the manual says it takes up 5 memory addresses between each save of data (00H to FFH ) is this correct or have I read this incorrectly, as this will depend upon the size of the data that you are trying to save ???
Does anyone have any code examples on the best way to save several recipes containing 8 numbers variable to memory.
Here is the code I have been using so far.
Code: Select all
unsigned char read_eeprom(unsigned char addr)
{
eeadr = addr; // low byte
eeadrh = 0; // high byte
clear_bit(eecon1,EEPGD); // select eeprom memory
set_bit(eecon1,RD); // set read bit
return(eedata);
}
void write_eeprom(unsigned char addr, unsigned char data)
{
eeadrh = 0; // high byte
eeadr = addr; // low byte
eedath = 0; // high byte
eedata = data; // low byte
clear_bit(eecon1,EEPGD); // select eeprom data memory
set_bit(eecon1,WREN); // enable write
eecon2 = 0x55;
eecon2 = 0xaa;
set_bit(eecon1,WR); // write command
while(eecon1&2); // wait untill writing is ready
clear_bit(eecon1,WREN); // disable write
}
Many thanks in advance Dave