I tried the CCS examples for saving a floating point number.
I tried to write a 1.0001 to starting local e2rom address of 38. What get's displayed is 255.000
write_float_eeprom(38,1.0001);
float_i_b = (float)read_float_eeprom(38);
fprintf(COMM_PORT2,"fVal:[%3.6f] \n\r"float_i_b); //DEBUG TEST
}
void write_float_eeprom(int16 e2_addr, float data) //e2_addr = Start of E2 rom address. Data = Floating point number to convert
{
int8 i;
for (i = 0; i < 4; i++)
{
write_eeprom(i + e2_addr, *(((int8*)&data + i) )) ;
}
}
float read_float_eeprom(int16 e2_addr)
{
int i;
float data;
for (i = 0; i < 4; i++)
{
*(((int8*)&data + i) = read_eeprom(i + e2_addr);
}
return(data);
}
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Sat Mar 22, 2008 5:41 pm
Quote:
float read_float_eeprom(int16 e2_addr)
{
int i;
float data;
for (i = 0; i < 4; i++)
{
*(((int8*)&data + i) = read_eeprom(i + e2_addr);
}
return(data);
}
You have an extra parenthesis on the left side of the (*int8).
It won't compile.
Quote:
fprintf(COMM_PORT2,"fVal:[%3.6f] \n\r"float_i_b);
You're missing the comma after the format string.
This won't compile either.
Quote:
void test_display_flaot()
"float" is spelled wrong.
Therefore, this is not the real code that you tested. It doesn't compile.
Also, you should specify the PIC that you're using and your compiler version.
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