View previous topic :: View next topic |
Author |
Message |
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
How to write an arrray of structs into EEPROM? |
Posted: Tue Dec 18, 2018 5:22 am |
|
|
I have the following type of array:
Code: |
typedef struct{
int16 hr;
int8 err;
} err_field;
err_field my_errors[10];
|
How to store it in PIC's EEPROM?
18F2550 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Dec 18, 2018 8:08 am |
|
|
Code: | void to_eeprom(char * thing, int8 size, int16 address)
{
int16 ctr;
for (ctr=0;ctr<size;ctr++) //loop through the number of bytes
write_eeprom(address++,*(thing++)); //writing bytes to address++
} |
//Then call with
Code: | to_eeprom((char *)my_errors, sizeof(my_errors), 0); //to write starting at zero |
|
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Thu Dec 20, 2018 6:20 am |
|
|
Thanks!
And reading from eeprom must be looks like:
Code: |
void read_errors(char * thing, int8 size, int16 address)
{
int16 ctr;
for (ctr=0;ctr<size;ctr++)
*(thing++)=read_eeprom(address++);
}
read_errors((char *)my_errors, sizeof(my_errors), EF_ADDR);
|
|
|
|
|