打印
[Atmel]

SAM4S 串口虚拟printf打印输出浮点数

[复制链接]
1069|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
maydolly|  楼主 | 2015-7-21 11:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
编译环境:Atmel Studio 6.2
按下面方式虚拟串口
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
  Send_Data((uint8_t) ch);
/* Loop until the end of transmission */

return ch;
}  
打印的时候,字母数字符号什么的都正常,但是输出浮点数结果全是 f(0x66),请问有哪位知道原因吗?

相关帖子

沙发
ddllxxrr| | 2015-7-21 20:30 | 只看该作者
Send_Data((uint8_t) ch);
就是这句,强制类型转换。字母数字没问题,浮点在GCC中也许就是那个结果

使用特权

评论回复
板凳
maydolly|  楼主 | 2015-7-22 11:19 | 只看该作者
ddllxxrr 发表于 2015-7-21 20:30
Send_Data((uint8_t) ch);
就是这句,强制类型转换。字母数字没问题,浮点在GCC中也许就是那个结果 ...

啊?不是吧,我在keil中这样写就没问题啊
并且printf里面对float有转换成unsigned char吧
我查查看,多谢

使用特权

评论回复
地板
maydolly|  楼主 | 2015-7-22 11:19 | 只看该作者
ddllxxrr 发表于 2015-7-21 20:30
Send_Data((uint8_t) ch);
就是这句,强制类型转换。字母数字没问题,浮点在GCC中也许就是那个结果 ...

啊?不是吧,我在keil中这样写就没问题啊
并且printf里面对float有转换成unsigned char吧
我查查看,多谢

使用特权

评论回复
5
yicole| | 2015-7-27 10:37 | 只看该作者
学习了!

使用特权

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

本版积分规则

1

主题

3

帖子

0

粉丝