|
|
View previous topic :: View next topic |
Author |
Message |
Sid2286
Joined: 12 Aug 2010 Posts: 119
|
How to store float value in EEPROM |
Posted: Tue Aug 16, 2011 12:32 am |
|
|
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: 1634 Location: Perth, Australia
|
Re: How to store float value in EEPROM |
Posted: Tue Aug 16, 2011 3:17 am |
|
|
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
|
|
Posted: Tue Aug 16, 2011 5:45 am |
|
|
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
|
|
Posted: Tue Aug 16, 2011 12:59 pm |
|
|
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. |
|
|
|
|
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
|