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 support@ccsinfo.com

Saving a Floating point num to e2rom

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



Joined: 21 Mar 2008
Posts: 10

View user's profile Send private message

Saving a Floating point num to e2rom
PostPosted: Sat Mar 22, 2008 5:11 pm     Reply with quote

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

I'm not sure what I'm doing wrong.?.

Can anyone help?

void test_display_flaot()
{
int16 long_i = 0;
float float_i = 1.0001;
float float_i_b = 0;
int i=0;

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

View user's profile Send private message

PostPosted: Sat Mar 22, 2008 5:41 pm     Reply with quote

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.
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