View Single Post
  #26   Spotlight this post!  
Unread 21-01-2004, 00:30
WizardOfAz's Avatar
WizardOfAz WizardOfAz is offline
Lead Mentor
AKA: Bill Bennett
FRC #1011 (CRUSH)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Tucson, AZ
Posts: 101
WizardOfAz will become famous soon enough
Send a message via AIM to WizardOfAz
Re: read/write EEPROM on 18F8520

Quote:
Originally Posted by Paul
I was going over the code given on this post and I was wondering what memory address's are avalible to write to? And how much information can be fit into a single address when using unsigned chars? Any help would be appreciated.
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