View previous topic :: View next topic |
Author |
Message |
hayee
Joined: 05 Sep 2007 Posts: 252
|
how to store floating nos in eeprom |
Posted: Tue Dec 11, 2007 1:45 am |
|
|
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
|
|
Posted: Tue Dec 11, 2007 1:51 am |
|
|
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
|
|
Posted: Tue Dec 11, 2007 2:04 am |
|
|
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
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Dec 11, 2007 9:55 am |
|
|
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 |
|
|
|