CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Saving a float-value in extern eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
XorpiZ
Guest







Saving a float-value in extern eeprom
PostPosted: Thu Nov 24, 2005 9:02 am     Reply with quote

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? Smile
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Nov 24, 2005 9:30 am     Reply with quote

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







PostPosted: Thu Nov 24, 2005 9:39 am     Reply with quote

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) ) ;

Embarassed
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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