STVD使用printf输出数据错误

使用STM8L052输出调试信息

重定向put char

#include "stdio.h"  //必不可缺少
char putchar (char c)
{
    /* Write a character to the USART */
    USART_SendData8(USART1, c);
    /* Loop until the end of transmission */
    while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);

    return (c);
}

输出字符串都没问题。

typedef struct
{
    uint16_t time;
    uint8_t cRssi;
}SysParam;

SysParam Sys;//定义了一个结构体数据

printf("hello world!");

当我输出数据时发现不对。

printf("rssi %d
",Sys.cRssi);

调试窗显示值是12,输出是确是3073

但是

printf("rssi %d
",Sys.time);

是正确的。

查了半天感觉应该是数据类型的问题。

printf("rssi %d
",(uint16_t)Sys.cRssi);

把uint8_t转为uint16_t输出就行了。

2019年9月24日

原文地址:https://www.cnblogs.com/IdeaMing/p/11577205.html