5 #define RESISTOR_HI 1500 // kOhm
6 #define RESISTOR_LO 150 // kOhm
8 volatile unsigned char battery_100mv;
10 void battery_adc(uint16_t adcval)
13 * This is tricky: we need to maintain precision, so we first
14 * multiply adcval by as big number as possible to fit uint16_t,
15 * then divide to get the final value,
16 * and finally type-cast it to unsigned char.
17 * We don't do running average, as the required precision
20 battery_100mv = (unsigned char)
22 * (RESISTOR_HI+RESISTOR_LO)/RESISTOR_LO // resistor ratio
23 / 4) >> 8); // divide by 1024