How to Store Boolean Array into External EEPROM?

Status
Not open for further replies.

nick703

Advanced Member level 1
Joined
Oct 17, 2011
Messages
422
Helped
21
Reputation
44
Reaction score
22
Trophy points
1,298
Location
surat
Activity points
3,987
I have Boolean Array of 16 Value how can i store this value in external eeprom?

or how can i convert boolean array to char and roll back to array?
 

A bool is normally a '1' or a '0'.
Either store the bool as one value per eeprom address (16 addresses) or convert it to two 8-bit values (think of bit shifting) and store it as two bytes (2 addresses).

Brian.
 

You haven't specified which language you want to use but the principle is the same for all. This is an example in C:

Code:
char Value = 0;
Value |= BoolValue1;
Value |= (BoolValue2 << 1);
Value |= (BoolValue3 << 2);
Value |= (BoolValue4 << 3);
Value |= (BoolValue5 << 4);
Value |= (BoolValue6 << 5);
Value |= (BoolValue7 << 6);
Value |= (BoolValue8 << 7);
SaveValueToEEPROM();

then repeat for the remaining bool values and store them in the next address.
What it does is start with a variable containing 00000000 then OR the bool values with it, shifting one more bit each time, the result using the bool numbers is 76543210 with the original bool zero or one in those bit positions. You should check with your compiler/assembler that it really does store boolean values as single bits, some store them as an 8-bit value even when only one bit is used. If that is the case, a slightly different strategy is needed.

Brian.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…