I'm so close to having output on my LCD as desired. Problem is that when I extract the digits from the integer to have digits as integer and the remainder to be my fraction , I can't seem to get the right output.
Before the decimal the output looks fine but after, it doesn't.
void ST7735_uBinOut8(uint32_t n){
uint32_t value2;
value2 = n;
char integer2[2];
char fraction2[4];
uint32_t f_part2 = abs(value2)%256;
uint32_t i_part2 = ((abs(value2)) /256) ;
if (abs(value2) > 256000U)
{
integer2[0] = '*';
integer2[1] = '*';
fraction2[0] = '*';
fraction2[1] = '*';
fraction2[2] = '*';
fraction2[3] = '*';
}
else
{
if (abs(value2) < 256000U)
sprintf(integer2, "%d", i_part2);
sprintf(fraction2, "%.3d", f_part2);
}
printf("%s.%s", integer2, fraction2);
The following are the values I pass to this function:
outTestCaseType2 outTests2[14]={
{ 0, " = 0.00?\r" }, // 0/256 = 0.00
{ 4, " = 0.01?\r" }, // 4/256 = 0.01
{ 10, " = 0.03?\r" }, // 10/256 = 0.03
{ 200, " = 0.78?\r" }, // 200/256 = 0.78
{ 254, " = 0.99?\r" }, // 254/256 = 0.99
{ 505, " = 1.97?\r" }, // 505/256 = 1.97
{ 1070, " = 4.17?\r" }, // 1070/256 = 4.17
{ 5120, " = 20.00?\r" }, // 5120/256 = 20.00
{ 12184, " = 47.59?\r" }, // 12184/256 = 47.59
{ 26000, " = 101.56?\r" }, // 26000/256 = 101.56
{ 32767, " = 127.99?\r" }, // 32767/256 = 127.99
{ 34567, " = 135.02?\r" }, // 34567/256 = 135.02
{255998, " = 999.99?\r" }, // 255998/256 = 999.99
{256000, " = ***.**?\r" } // error
};
Below is a screen shot of my output and the column on my right is what I'm supposed to get. OUTPUT IMG
I fixed it by playing around with the operators. I changed to as follows and it seems to work and get the output I wanted after like 4 h but I'm sure that 4 h goes towards me learning and that's the struggle of a noob but its ok.
void ST7735_uBinOut8(uint32_t n){
uint32_t value2;
value2 = (n*1000)/256;
char integer2[2];
char fraction2[4];
uint32_t f_part2 = abs(value2)%1000;
uint32_t i_part2 = ((abs(value2)) /1000) ;
//f_part2 = abs(f_part2)%1000;
// i_part2 = abs(i_part2) /1000 ;
if (abs(n) >= 256000U)
{
integer2[0] = '*';
integer2[1] = '*';
fraction2[0] = '*';
fraction2[1] = '*';
fraction2[2] = '*';
fraction2[3] = '*';
}
else
{
if (abs(n) < 256000U)
sprintf(integer2, "%d", i_part2);
sprintf(fraction2, "%.3d", (f_part2));
}
printf("%s.%.2s", integer2, fraction2);
}
This is my output now: IMG
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.