I got an MCU that sends to a LCD a series of numbers to display. I need to send their ASCII coresponding value for it to work right. Those numbers are float types, no more than 2 digits precision for the fraction part.
The thing is that I need a function that will parse the float, get its digits without reversing them, convert them to ASCII, and put the ASCII code for comma at its location in the number.
Example:
number = 123.45
result = 49 50 51 44 52 53 //Where 44 is the ASCII code of comma
Any suggestions for writing a function that can do this? Would be awesome if the result variable would retain a single ASCII code at a time since I need to call the WriteToLCD function for each symbol at a time.
Also I dont really have access to library functions like sprintf, itoa, ftoa etc.
Some code sample:
void LCD_print(int number)
{
char aux;
int naux=0,maux=0;
while(number!=0)
{
maux=number%10;
naux=naux*10+maux;
number=number/10;
}
while(naux)
{
aux=naux%10+'0';
WriteToLCD(aux);
naux=naux/10;
}
}
I got this function from somewhere off the internet, it does a good job at converting integers to ASCII, but I need the argument to become a float and add the dot's ASCII code to the result.
Main will look something like this:
void main()
{
//other stuff
float number = ReadValueFromSensor();
LCD_print(number);
}