Question: How do I convert a long value to ASCII and display it on an LCD or transmit over a UART TX?
Answer: A long value can be converted to ASCII string using the ltoa function and then displayed on LCD using the LCD_PrString function or transmitted through UART using UART_PutString or TX8_PutString functions.
Prototype: char *ltoa(char *string, long value, int base);
Parameters:
*string - Pointer to a string where the converted ASCII result has to be stored
value - The long value to be converted
base - Base of conversion
Return Value:
The function returns the pointer of the string where the ASCII result is stored.
Display long on LCD
#include “stdlib.h”
long MyLong = 123456; // Long value to be converted and displayed
char AsciiString[12]; // Buffer to store the Ascii result
LCD_Position(0,0);
LCD_PrString(ltoa(AsciiString, MyLong, 10));
Note: Code assumes that an LCD user module named “LCD” has been placed in the project and the LCD has been initialized
Transmit a long value as ascii string over UART
#include “stdlib.h”
long MyLong = 123456; // Long value to be converted and displayed
char AsciiString[12]; // Buffer to store the Ascii result
UART_PutString(ltoa(AsciiString, MyLong, 10));
Note: Code assumes that an UART user module has been placed, configured and initialized



