我正在尝试在LCD显示屏上显示整数。LCD的工作方式是您将8位ASCII字符发送到它,它会显示该字符。
到目前为止,我的代码如下:
unsigned char text[17] = "ABCDEFGHIJKLMNOP";
int32_t n = 123456;
lcd.printInteger(text, n);
//-----------------------------------------
void LCD::printInteger(unsigned char headLine[17], int32_t number)
{
//......
int8_t str[17];
itoa(number,(char*)str,10);
for(int i = 0; i < 16; i++)
{
if(str[i] == 0x0)
break;
this->sendCharacter(str[i]);
_delay_ms(2);
}
}
void LCD::sendCharacter(uint8_t character)
{
//....
*this->cOutputPort = character;
//...
}
如果我试图在LCD上显示123456
,实际上它会显示-7616
,显然不是正确的整数。
我知道问题可能是因为我将字符转换为带符号的int8_t
,然后以无符号的uint8_t
输出它们。但我必须以无符号格式输出它们。我不知道如何将int32_t
输入整数转换为ASCII uint8_t
字符串。
itoa
内部进行转换,这表明它是无符号的。 - SergeyA