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 support@ccsinfo.com

Question about read/write _eeprom

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



Joined: 28 Feb 2006
Posts: 151

View user's profile Send private message

Question about read/write _eeprom
PostPosted: Fri Nov 07, 2014 7:51 am     Reply with quote

Hi all! my queestion is about the read_eeprom and write_eeprom functions.

I dont know were i read that the compiler always make those functions INLINE, is that true? Im looking a way to free some flash memory on my pic, and i use a lot of read_eeprom and write_eeprom.

The same happens with read_EXT_eprom and write_EXT_eeprom?

thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 07, 2014 9:07 am     Reply with quote

Encapsulate your use.
Remember that the 'odds' are you want to transfer things that are larger than bytes. Floats, int32's, structures etc..
The supplied functions are designed to be the 'core' of code written by you to transfer the larger lumps you want. CCS demo this with their float transfer in the manual.

I use a generalised function, to transfer any size variable to/from the EEPROM.
Code:

void to_eeprom(int8 address, int8 *data, int8 count)
{
   do
   {
       write_eeprom(address++,*data);
       data++;
   } while (--count>0);
}
//change address & count to int16 for chips with >256 bytes EEPROM

void from_eeprom(int8 address, int8 *data, int8 count)
{
   do
   {
       *data = read_eeprom(address++);
       data++;
   } while (--count>0);
}

//Then you can transfer an entire object like a structure to/from the EEPROM

struct demo
{
    int16 ctr;
    int8 things[8];
    float value;
} demo_val;

    from_eeprom(0, &demo_value, sizeof(demo));
//reads the entire structure from EEPROM

    to_eeprom(0, &demo_value, sizeof(demo));
//writes the structure back.
//Works just as well with any type of variable
//I normally #define the addresses
#define DEMO_IN_EEPROM 0

//to avoid forgetting where things are actually held.
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