From the comments I know that you already found the
itoa()
function.
But with microcontrollers there is usually a limited amount of memory and execution time should be as short as possible. So it might be better to implement specific functions yourself rather than using the more general library functions. This example will produce strings with leading zeroes (e.g. '0128').
char *utoa10(unsigned val, char *buffer, int digits)
{
unsigned n;
buffer[digits--] = 0;
while (digits >= 0)
{
n = val / 10;
buffer[digits--] = (char)(val - n * 10) + '0';
val = n;
}
return buffer;
}
void usart_adc(unsigned val)
{
char buffer[5];
utoa10(val, buffer, 4);
usart_pstr(buffer);
}