Quote:
|
Originally Posted by WizardOfAz
Addresses 0 through 1023 are available in EEPROM. Each stores one byte, which is a char or unsigned char, whatever you like. 8 bits. If the data you're trying to store is already 8 bits like you say, it's pretty easy. Just do
writeEE(someAddress, someChar);
If you want to store a value that is more than 8 bits, like a 16 bit short or int, or a 32 bit long, you have to break it up into bytes first. And be careful with sign management. The cleanest way, I think, to store both bytes of an int would be like this:
int i;
...
writeEE(someAddress, (unsigned char)(((unsigned int)i)>>8)); // write high byte
writeEE(someAddress+1, (unsigned char)(((unsigned int)i)&0xff)); // write low byte
To get that int back out of EEPROM later, use this sequence:
i = (int)(((unsigned short)readEE(someAddress)<<8)
+ readEE(someAddress+1));
But also read what I said about delays in writing. If you want to use my code above and have more than 16 bytes to write, you'll have to either make the buffer bigger or figure out some other way to time it.
Did that help or add confusion?
Bill
|
It did help out, however there is one problem. When I write to the eeprom and try to play back from it using the readEE function it doesn't seem to work. I think my memory addresses are off. Would this be an acceptable way of using the writeEE function?
writeEE(0x00,somechar);
or would i have to write it like this?
write(&0x00,somechar);
Thanks for clearing some of the other stuff for me.