Ouch sprintf is 6000+ bytes to get Float to LCD

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Ouch sprintf is 6000+ bytes to get Float to LCD

1,001 次查看
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 回复

718 次查看
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 项奖励
回复