File: mh-lcd-float.c

package info (click to toggle)
kuttypy 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,896 kB
  • sloc: python: 58,651; javascript: 14,686; xml: 5,767; ansic: 2,716; makefile: 453; asm: 254; sh: 48
file content (31 lines) | stat: -rw-r--r-- 613 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* 
Version of lcd.c handles floating point numbers in a crude manner, without using the
formatting functions of C library. Including this increases the program size a lot.
Use only if really necessary.
*/

#include "mh-lcd.c"


void lcd_put_float(float val, uint8_t ndec)
{
uint32_t  ival;
uint16_t  mf, dec;
uint8_t   k;
if(val < 0)
	{
	val = -val;
	lcd_put_char('-');
	}
if (ndec > 3) ndec = 3;  // maximum 3 decimals
mf = 1;
for(k =0; k < ndec; ++k) mf *= 10;
ival = val * mf + .5;         // multiply by 10^ndec
dec = ival % mf;
ival = ival / mf;
lcd_put_long(ival);
lcd_put_char('.');
lcd_put_int(dec);
}