/* ANY-LICENSE V1.0 ---------------- You can use these files under any license approved by the Open Source Initiative, preferrably one of the popular licenses, as long as the license you choose is compatible to the dependencies of these files. See http://www.opensource.org/licenses/ for a list of approved licenses. Author: Martin Furter Project: Tins AVR Lib Repository: http://repos.borg.ch/projects/tins_avr_lib/trunk Copyright: 2015 */ #include void uint8_to_string( uint8_t vb, char* str ) { uint16_t v; uint16_t p; uint8_t d; v = vb; // 100 p = v * 41; d = p >> 12; *str++ = '0' + d; v -= d * 100; // 10 p = 26 * v - (v >> 2); d = p >> 8; *str++ = '0' + d; v -= d * 10; // 1 d = v; *str++ = '0' + d; // end of string *str = 0; } void uint16_to_string( uint16_t v, char* str ) { uint8_t v0; uint8_t v1; uint8_t x; uint16_t p; uint8_t d; // 10'000 // gets an overflow at 50139 so just fix it with this check here :) if( v > 50000 ) { v -= 50000; d = 5; } else { d = 0; } const uint8_t f2 = 104; const uint8_t f1 = 219; const uint8_t f0 = 192; v0 = v; v1 = v >> 8; x = (f1 * v0 + f0 * v1 ) >> 8; x = (f2 * v0 + f1 * v1 + x) >> 8; x = ( f2 * v1 + x) >> 12; d += x; *str++ = '0' + d; v -= x * 10000; // 1'000 const uint8_t g2 = 4; const uint8_t g1 = 24; const uint8_t g0 = 148; v0 = v; v1 = v >> 8; x = (g0 * v0) >> 8; x = (g1 * v0 + g0 * v1 + x) >> 8; p = g2 * v + g1 * v1 + x; d = p >> 12; *str++ = '0' + d; v -= d * 1000; // 100 p = v * 41; d = p >> 12; *str++ = '0' + d; v -= d * 100; // 10 p = 26 * v - (v >> 2); d = p >> 8; *str++ = '0' + d; v -= d * 10; // 1 d = v; *str++ = '0' + d; // end of string *str = 0; }