我写了个usart输入的数据打印函数,为什么打印回来的会是5位数的数字啊
uint8_t USART_Scanf(uint32_t value)
{
uint32_t index = 0;
uint32_t tmp[5] = {0, 0,0,0,0};
while (index < 5)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
tmp[index++] = (USART_ReceiveData(USART1));
USART_SendData(USART3, tmp[index]);
if ((tmp[index - 1] < 0x30) || (tmp[index - 1] > 0x39))
{
printf(&quot;
Please enter valid number between 0 and 9&quot;);
index--;
}
}
index = (tmp[4] - 0x30) + ((tmp[3] - 0x30) * 10+(tmp[2] - 0x30) *100+(tmp[1] - 0x30) *1000+(tmp[0] - 0x30)*10000);
if (index > value)
{
printf(&quot;
Please enter valid number between 0 and %d&quot;, value);
return 0xFF;
}
return index;
} |