CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to write an arrray of structs into EEPROM?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

How to write an arrray of structs into EEPROM?
PostPosted: Tue Dec 18, 2018 5:22 am     Reply with quote

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: 19518

View user's profile Send private message

PostPosted: Tue Dec 18, 2018 8:08 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 20, 2018 6:20 am     Reply with quote

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);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group