Ouch sprintf is 6000+ bytes to get Float to LCD

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Ouch sprintf is 6000+ bytes to get Float to LCD

1,002件の閲覧回数
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?

ラベル(1)
0 件の賞賛
返信
1 返信

719件の閲覧回数
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 件の賞賛
返信