sprintf function is too large, in the STM8 above is not afraid to use, is still. Text overflow. In order to upload the collected values through the serial port to the computer, you can only write a floating-point number into a string function:
#include <stdio.h> #include <stdint.h>static char table[]={' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};vo ID Num2char (char *str, double number, uint8_t G, uint8_t l) { uint8_t i; int temp = NUMBER/1; Double t2 = 0.0; for (i = 1; i<=g; i++) { if (temp==0) str[g-i] = table[0]; else str[g-i] = table[temp%10]; temp = TEMP/10; } * (str+g) = '. '; temp = 0; t2 = number; for (I=1; i<=l; i++) { temp = t2*10; Str[g+i] = table[temp%10]; t2 = t2*10; } * (str+g+l+1) = ' + ';} int main (int argc, char const *argv[]) { char str[20]; Num2char (str, 23.56821312, 8, ten); printf ("%s\n", str); return 0;}
The test results are as follows:
00000023.5682131
Floating-point numbers converted into string functions