Tool/software:
I have used this code for years with standard library 'itoa' to add an unsigned char value to a string and display it.
Does not work properly using 'ltoa(char str, int val, int radix)'.
I know that some versions of CCS 'ltoa' do not have a radix but that not the problem either.
Note the 'drawText(int x ,int y, unsigned int fg_color, unsigned int bg_color, char const *string)' function is well proven many times elsewhere in the program.
It prints this: SLAVE CLOCK #XS
Should print: SLAVE CLOCK #3
void dispClkID()
{
unsigned char clk_id;
char s1[20], s2[3];
/* hardware detection not built yet.
* clk_id is hard coded until then.
*/
clk_id= 3;
if (clk_id == 1) {
strcpy(s1," MASTER CLOCK #1 ");
drawText(TEXT_BG_CENTER,textY(0),BLACK,ORANGE,s1);
}
else if ((clk_id > 1)&&(clk_id < 5)) {
ltoa(clk_id,s2,10);
strcpy(s1," SLAVE CLOCK #");
strcat(s1,s2);
strcat(s1," ");
drawText(TEXT_BG_CENTER,textY(0),BLACK,ORANGE,s1);
}
else {
strcpy(s1,"Clock ID not set");
drawText(TEXT_BG_CENTER,textY(0),RED,BLACK,s1);
}
}