Microcontroller › PIC › Convert ‘ unsigned long int ‘ to ‘string’ without using inbuilt function for UART › Hello, Firstly, you didn’t
Hello,
Firstly, you didn’t declared buffer in a correct way:
Instead of “unsigned char *t_buffer[8];” use “unsigned char t_buffer[8];”
Secondly, you have to fill into t_buffer ascii representation for each digit. There are two ways for do this:
1. using sprintf command (header “stdio.h” must be previously included into project) :
sprintf((char*)t_buffer,”%lu”,data0);
2. step by step:
t_buffer[0] = (data0 / 1000000ul) + 0x30;
data0 /= 1000000ul;
t_buffer[1] = (data0 / 100000ul) + 0x30;
data0 /= 100000ul;
t_buffer[2] = (data0 / 10000ul) + 0x30;
data0 /= 10000ul;
t_buffer[3] = (data0 / 1000ul) + 0x30;
data0 /= 1000ul;
t_buffer[4] = (data0 / 100ul) + 0x30;
data0 /= 100ul;
t_buffer[5] = (data0 / 10ul) + 0x30;
t_buffer[6] = (data0 % 10ul) + 0x30;
t_buffer[7] = 0;