首页 > 其他 > 详细

STVD使用printf输出数据错误

时间:2019-09-24 13:41:15      阅读:138      评论:0      收藏:0      [点我收藏+]

使用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\r\n",Sys.cRssi);

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

但是

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

是正确的。

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

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

把uint8_t转为uint16_t输出就行了。

 

2019年9月24日

 

STVD使用printf输出数据错误

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

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!