Hello, I'm currently trying to store 2 values of 2 bytes each to the EEPROM to my PIC16. The EEPROM stores single bytes. How would I divide my value into 2 bytes to write them? And how do I then read them into one single value again? I'm using C.
byte1 = word
byte2 = word >> 8
word = byte1 | (byte2 << 8)
union {
uint16_t wrd;
unsigned char b[2];
struct {
unsigned char b1 : 8;
unsigned char b0 : 8;
} byt;
} dat;
int main() {
dat.wrd = 0xABCD;
printf("wrd = 0x%X ", dat.wrd);
printf("b[1] = 0x%X, b[0] = 0x%X ", dat.b[1], dat.b[0]);
printf("byt.b1 = 0x%X, byt.b0 = 0x%X\n", dat.byt.b1, dat.byt.b0);
exit(0);
wrd = 0xABCD b[1] = 0xAB, b[0] = 0xCD byt.b1 = 0xCD, byt.b0 = 0xAB
by Duane Benson
by Duane Benson
by Robert Keim