Home Programming (Assembly and C) Converting Float to ASCII

Converting Float to ASCII

E-mail Print PDF
( 3 Votes )

Question: How do I convert a float value to ASCII and display it on an LCD or transmit over a UART TX?

Answer:  A float value can be converted to ASCII string using the ftoa function and then displayed on LCD using the LCD_PrString function or transmitted through UART using UART_PutString or TX8_PutString functions.

Code Samples

Display float on LCD

#include “stdlib.h”
int Status;
float MyFloat = 3.414;
LCD_Position(0,0);
LCD_PrString(ftoa(MyFloat, &Status));

Note: Code assumes that an LCD user module named “LCD” has been placed in the project and the LCD has been initialized


Transmit a float value as ascii string over UART


#include “stdlib.h”
int Status;
float MyFloat = 3.414;
UART_PutString(ftoa(MyFloat, &Status));

Note: Code assumes that an UART user module has been placed, configured and initialized)


 

Comments (0)
Only registered users can write comments!