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

how to store floating nos in eeprom

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

how to store floating nos in eeprom
PostPosted: Tue Dec 11, 2007 1:45 am     Reply with quote

Hi everyone,
i am using ccs compiler version 4.020 and pic16f877a
I have a question.i want to store some floating numbers in eeprom like 1.25,3.4 etc at different locations and i know that the limitations of eeprom is that it only store int8 bit or int16 bit.how can i store floating nos in eeprom.plz give me an example if i want to store let say 3.4 in eeprom.
thankx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 11, 2007 1:51 am     Reply with quote

This question is answered in the CCS FAQ page. Here is the link:
http://www.ccsinfo.com/faq.php
Look in this section:
Quote:

Memory
How do I write variables to EEPROM that are not a byte ?
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Tue Dec 11, 2007 2:04 am     Reply with quote

i have already seen that link which u give PCM PROGRAMMER but i didn't understand it.can u give me some other examples
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Dec 11, 2007 3:50 am     Reply with quote

So read the link...
Particularly this http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Dec 11, 2007 9:55 am     Reply with quote

A float is made up of four bytes. The example is trying to store one byte at a time. You, basically, take the lowest byte of the float, store it say at eeprom address 0x00, point to the next byte of the float, store it at position 0x01 of the eeprom and so on until you have stored all four bytes into sequential bytes of the eeprom. If you need to store a second float value you would store the LSB of that float at eeprom address 0x04 and move up.

When you read the bytes, from the eeprom, you can read the lowest byte and stuff it into the lowest (LSB) byte of the float, read the next byte and stuff it into the next byte position of the float and so on until you have reconstructed the entire float variable.

The same thing goes if you have an int16 that needs to be stored. You only need to store two bytes. You will, however, need to track where you are as far as memory position within the eeprom. You don't want to be over writing any value that you have previously stored.

Ronald
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