![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Bryan
Joined: 23 Apr 2005 Posts: 73
|
EEPROM, 8-bit only? |
Posted: Thu Apr 13, 2006 2:00 am |
|
|
I was creating a test program to read in my analog voltage and convert it to a digital number to be written to the EEPROM using the onchip A/D coverter, and this worked fine except for one small problem. My A/D is 10 bits and the EEPROM apparently is only 8 bits, so any value over 255 gets set to 0 on the EEPROM and so I only get this zero result when I try to read it back from the EEPROM. I am using a PIC18F1320 and just wondering if anyone knows of a way to either increase the size of each address location on the EEPROM or allow for storage of 10 bit numbers on the EEPROM some other way. Any help would be greatly appreciated! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Apr 13, 2006 2:10 am |
|
|
You just write two bytes.
The 'make8' function, is designed to allow you to split a 16bit value (which is what you will be having to use to hold a 10bit value), into two bytes, and the 'make16' value allows you to put them back together again. There are also solutions by casting a pointer to point to an int, rather than an int16, or a union to access the bytes.
This applies all the time, when moving data to different storage 'media', even on a PC, or larger computer system.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Bryan
Joined: 23 Apr 2005 Posts: 73
|
|
Posted: Thu Apr 13, 2006 2:47 am |
|
|
Got it working. Thanks Ttelmah! If anyone needs them, here are the functions that I wrote for writing 16 bit numbers to the EEPROM:
Code: | void write_eeprom16(int address1, int address2, int16 value)
{
int8 lowerhalf = 0;
int8 upperhalf = 0;
lowerhalf = make8(value,0);
write_eeprom(address1,lowerhalf);
upperhalf = make8(value,1);
write_eeprom(address2,upperhalf);
}
int16 read_eeprom16(int address1, int address2)
{
int16 finalvalue = 0;
int8 lowerhalf = 0;
int8 upperhalf = 0;
upperhalf = read_eeprom(address2);
lowerhalf = read_eeprom(address1);
finalvalue = make16(upperhalf,lowerhalf);
return finalvalue;
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|