打印

请教输入usart输入打印问题

[复制链接]
351|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我写了个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("
Please 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("
Please enter valid number between 0 and %d", value);
            return 0xFF;
        }
        return index;
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

437

主题

437

帖子

0

粉丝