Ouch sprintf is 6000+ bytes to get Float to LCD

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ouch sprintf is 6000+ bytes to get Float to LCD

546 Views
PG1
Contributor I

I need to take a floating point number from -9999. to -.0001 to 0 to .0001 to 9999.  and display it on an  7 segment 4 digit LCD.

 

I had planned to use sprintf to take the float (or double)  and convert it to an ascii string stored in a buffer. Then the buffer could picked apart to get the sign, digits, and proper decimal point. location.

 

But the freescale implementation of sprintf is over 6000 bytes.

 

Does anyone have any suggestions for code which does not occupy as much space?

Labels (1)
0 Kudos
1 Reply

263 Views
bigmac
Specialist III

Hello,

 

One possible approach is to convert the float value to a fixed point value with 16-bit integer and fractional parts.  Each part can then be separately converted to ASCII decimal characters for the display.

 

  float x = 455.1234;  int integer;    // Integer part  word frac;      // Fractional part    integer = (int)x;  frac = (int)((long)(x * 10000) - integer * 10000);  // Range 0 - 9999

 

When displaying the integer part, you might normally suppress leading zeros.  However, the fractional part would require leading zeros to be present.

 

Regards,

Mac

 

0 Kudos