View previous topic :: View next topic |
Author |
Message |
XorpiZ Guest
|
Saving a float-value in extern eeprom |
Posted: Thu Nov 24, 2005 9:02 am |
|
|
Hi.
Just a quick question. I want to use write_ext_eeprom to write to an external eeprom (24LC512), but I was wondering whether it is possible to give the function a float as the second parameter?
ie: write_ext_eeprom( address, float_value)?
Or do i have to convert my float_value to a hex_value first? And if so, how do I do that? |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Nov 24, 2005 9:30 am |
|
|
Microchip & CCS use 32 bit format to handle/store a float. Those 4 data bytes must
be in 4 consecutive mem positions/addresses.
The exponential notation is arranged as follows:
1) The first 8 bit (MSB) represent the exponent.
2) The next single bit keep the sign
3) The following 23 last bits represent the mantisa.
Code: |
WRITE_FLOAT_EXT_EEPROM(int16 address, float data)
{
int i;
for (i = 0; i < 4; i++)
write_ext_eeprom(i + n, *(&data + i) ) ;
}
|
Humberto |
|
|
XorpiZ Guest
|
|
Posted: Thu Nov 24, 2005 9:39 am |
|
|
Silly me.. *note to self* Read the FAQ next time.
WRITE_FLOAT_EXT_EEPROM(long int n, float data) {
int i;
for (i = 0; i < 4; i++)
write_ext_eeprom(i + n, *(&data + i) ) ;
|
|
|
|