championx
Joined: 28 Feb 2006 Posts: 151
|
Question about read/write _eeprom |
Posted: Fri Nov 07, 2014 7:51 am |
|
|
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: 19546
|
|
Posted: Fri Nov 07, 2014 9:07 am |
|
|
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.
|
|
|