|
|
View previous topic :: View next topic |
Author |
Message |
Bedros B Guest
|
#rom used to initialize float into EEPROM |
Posted: Thu Oct 01, 2009 6:40 am |
|
|
I want to use the #ROM preprocessor directive to preload the PIC16F1936 EEPROM with values at the time of programming the chip. This works well if the variables are integers 8, 16 or 32 bit by using left shift commands for example:
Code: |
#define putLong(value) {value,(value>>8),(value>>16),(value>>24)}
#rom 0x0f000 = putLong(0x12345678)
#rom 0x0f004 = putLong(0x9ABCDE)
…etc…
|
But how can I store floating point numbers?
Are there any preprocessor directives that can help me?
Thanks
Bedros |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 01, 2009 1:39 pm |
|
|
Use the FloatConv.exe program contained in this zip file to convert
a floating point number from Microchip 32-bit format to four hex bytes:
http://www.piclist.com/images/floatconv10.zip
(Drag the exe file onto your desktop and click on it).
Then put the bytes in a #rom statement at the data eeprom address.
Then read the data eeprom in your program with read_eeprom().
The test program shown below will display:
Code: |
#include <16F1936.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// Embed the 4 bytes for 1.234 (from FloatConv.exe) into eeprom.
#rom 0xF000 = {0x7F, 0x1D, 0xF3, 0xB6}
float read_float_eeprom(int8 addr)
{
int8 i;
float data;
for(i=0; i<4; i++)
*((int8*)&data + i) = read_eeprom(addr + i);
return(data);
}
//======================================
void main(void)
{
float temp;
temp = read_float_eeprom(0);
printf("%4.3f", temp);
while(1);
} |
|
|
|
bedros b Guest
|
|
Posted: Thu Oct 01, 2009 3:39 pm |
|
|
Thanks for the info.
The "floatconv.exe" program is very useful.
Makes it almost possible to do it manually as you suggested.
I was hoping to have a simpler way, so it becomes simple
to change the float values as required.
Thanks again
Bedros |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Oct 02, 2009 6:25 am |
|
|
Just for future reference, if you have the CCS IDE, the Numeric Converter from the Tools menu does the same job as the floatconv tool above. You still need to manually copy the hex values, though. _________________ Andrew |
|
|
|
|
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
|