高中生
最后登录1970-1-1
在线时间 小时
注册时间2013-11-17
|
我写了个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("\n\rPlease enter valid number between 0 and 9");
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("\n\rPlease enter valid number between 0 and %d", value);
return 0xFF;
}
return index;
}
|
|