Debian Codegraph @

kpy/mh-lcd-float.c

raw symbols SCIP
1 /*
2 Version of lcd.c handles floating point numbers in a crude manner, without using the
3 formatting functions of C library. Including this increases the program size a lot.
4 Use only if really necessary.
5 */
6
7 #include "mh-lcd.c"
8
9
10 void lcd_put_float(float val, uint8_t ndec)
11 {
12 uint32_t ival;
13 uint16_t mf, dec;
14 uint8_t k;
15 if(val < 0)
16 {
17 val = -val;
18 lcd_put_char('-');
19 }
20 if (ndec > 3) ndec = 3; // maximum 3 decimals
21 mf = 1;
22 for(k =0; k < ndec; ++k) mf *= 10;
23 ival = val * mf + .5; // multiply by 10^ndec
24 dec = ival % mf;
25 ival = ival / mf;
26 lcd_put_long(ival);
27 lcd_put_char('.');
28 lcd_put_int(dec);
29 }
30
31