The questions of how to write and read multibyte data objects to and from EEPROM are often asked in these forums. If using the HI-TECH compiler's 'eeprom' qualifier is not suitable for whatever reason, because we know that a data object has an address and a size, a general solution can be crafted similar to that demonstrated in this simple example:
Code:
#include <htc.h>
#include <stddef.h>
struct ee_map_s {
char sn[9]; /* Serial number string */
long l;
float f;
char c;
};
#define EE_ADDR(member) (offsetof(struct ee_map_s, (member)))
void ee_read(unsigned char ee_addr, void *vp, unsigned char n)
{
unsigned char *p = vp;
while (n--) {
*p++ = eeprom_read(ee_addr++);
}
}
void ee_write(unsigned char ee_addr, void *vp, unsigned char n)
{
unsigned char *p = vp;
while (n--) {
eeprom_write(ee_addr++, *p++);
}
}
void main(void)
{
float f = 1.234;
long l = 1234;
ee_write(EE_ADDR(f), &f, sizeof f);
ee_write(EE_ADDR(l), &l, sizeof l);
ee_read(EE_ADDR(f), &f, sizeof f);
for (;;);
}