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 CCS Technical Support

How to store float value in EEPROM

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



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

How to store float value in EEPROM
PostPosted: Tue Aug 16, 2011 12:32 am     Reply with quote

Hi,

I'm in a problem don't understand how to do it!

1. I have a variable type float where I cannot use '%' sign as an operator.
2. using write_eeprom(adress,value) value is int type so I guess cannot pass float.
how do i do it?

My code is something like this:

Code:

                       printf(lcd_putc," \fEnter\nCalibration value.");
                       delay_ms(1000);
                       cali = read_button();     // cali = float
                       delay_ms(1000);
                       printf(lcd_putc," \f Present\n Value");
                       delay_ms(1000);
                       f=read_button();      // f= float
                       delay_ms(1000);
                       cali=cali/f;
                       printf(lcd_putc,"\f Cal.\nSaved");
                       delay_ms(1000);
                       break;


And for storing the value i'm using something like:

Code:


                    temEE=cali/256;
                    write_eeprom(10,temEE);
                    temEE=cali%256;        // Error cannot use % for float
                    write_eeprom(11,temEE);


Please help, I thought of using an int pointer and doing it, but thats way too lengthy way to do it, if any one has a better way please help!

thanks,
Sid
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: How to store float value in EEPROM
PostPosted: Tue Aug 16, 2011 3:17 am     Reply with quote

Sid2286 wrote:
Hi,

I'm in a problem don't understand how to do it!

1. I have a variable type float where I cannot use '%' sign as an operator.
2. using write_eeprom(adress,value) value is int type so I guess cannot pass float.
how do i do it?

My code is something like this:

Code:

                       printf(lcd_putc," \fEnter\nCalibration value.");
                       delay_ms(1000);
                       cali = read_button();     // cali = float
                       delay_ms(1000);
                       printf(lcd_putc," \f Present\n Value");
                       delay_ms(1000);
                       f=read_button();      // f= float
                       delay_ms(1000);
                       cali=cali/f;
                       printf(lcd_putc,"\f Cal.\nSaved");
                       delay_ms(1000);
                       break;


And for storing the value i'm using something like:

Code:


                    temEE=cali/256;
                    write_eeprom(10,temEE);
                    temEE=cali%256;        // Error cannot use % for float
                    write_eeprom(11,temEE);


Please help, I thought of using an int pointer and doing it, but thats way too lengthy way to do it, if any one has a better way please help!

thanks,
Sid


Code:

         BYTE i, offset, *ptr;

         offset = 10;  // or whatever the offset is meant to be
         ptr = (BYTE*)&cali;
         for (i=0, i < sizeof(cali),i++)
              write_eeprom(offset++,*ptr++);


_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Aug 16, 2011 5:45 am     Reply with quote

Look at the make8() and make32() functions. You store data to EEPROM as bytes. Break larger structures (like floats) into to bytes and put the bytes into EEPROM.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 16, 2011 12:59 pm     Reply with quote

CCS has a driver file with routines to store floats and ints in eeprom:
Quote:

c:\program files\picc\drivers\internal_eeprom.c

Just #include it in your program and call the appropriate routines.


There is also another file with routines for external eeprom.
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