PIC16F系列MCU用printf函数调试程序时能否打印浮点类型,如果能需要怎样配置?

[复制链接]
1584|11
手机看帖
扫描二维码
随时随地手机跟帖
18437952617|  楼主 | 2019-5-5 18:30 | 显示全部楼层 |阅读模式
PIC16F系列MCU用printf函数调试程序时能否打印浮点类型,如果能需要怎样配置?
例如  printf("a = %f\r\n",a); a是浮点型,当是%f编译就会出错,改为%d就能正常编译,
报错信息::0:: error: (1347) can't find 0x22F words (0x22f withtotal) for psect "text20" in class "CODE" (largest unused contiguous range 0x208)
Non line specific message::: advisory: (1493) updated 32-bit floating-point routines might trigger "can't find space" messages appearing after updating to this release; consider using the smaller 24-bit floating-point types
更多操作 评论编辑回复

使用特权

评论回复
CoolSilicon| | 2019-5-6 08:59 | 显示全部楼层
本帖最后由 CoolSilicon 于 2019-5-6 09:01 编辑

包含头文件#include <stdio.h> 试试看?

使用特权

评论回复
评论
18437952617 2019-5-6 09:31 回复TA
这个肯定是包含过的,用%d的时候编译没错,怀疑是不是不支持浮点 
CoolSilicon| | 2019-5-6 08:59 | 显示全部楼层
#include <math.h>
#include <stdio.h>
/* Print acos() values for -1 to 1 in degrees. */
void
main (void)
{
    float i, a;
    for(i = -1.0; i < 1.0 ; i += 0.1)
   {
       a = acos(i)*180.0/3.141592;
       printf(“acos(%f) = %f degrees\n”, i, a);
    }
}
参考这个例子看看?

使用特权

评论回复
CoolSilicon| | 2019-5-6 08:59 | 显示全部楼层
#include <math.h>
#include <stdio.h>
/* Print acos() values for -1 to 1 in degrees. */
void
main (void)
{
    float i, a;
    for(i = -1.0; i < 1.0 ; i += 0.1)
   {
       a = acos(i)*180.0/3.141592;
       printf(“acos(%f) = %f degrees\n”, i, a);
    }
}
参考这个例子看看?

使用特权

评论回复
18437952617|  楼主 | 2019-5-6 09:31 | 显示全部楼层
CoolSilicon 发表于 2019-5-6 08:59
包含头文件#include  试试看?

这个肯定是包含过的,用%d的时候编译没错,怀疑是不是不支持浮点

使用特权

评论回复
systemchip| | 2019-5-6 09:35 | 显示全部楼层
输出信息已经写了,使用24位浮点类型

使用特权

评论回复
CoolSilicon| | 2019-5-6 09:39 | 显示全部楼层
systemchip 发表于 2019-5-6 09:35
输出信息已经写了,使用24位浮点类型

果然:
consider using the smaller 24-bit floating-point types

使用特权

评论回复
oxygenzz| | 2019-5-6 16:08 | 显示全部楼层
设置使用24位浮点类型:
把下面连接选项加到 XC8 Linker中
-fshort-float
Project properties -> XC8 Linker -> Additional options:  -fshort-float
选择C90库
Link in C Library -> C90

测试代码:
float x = 2.2;
printf("%f",x);
加入main.c中

使用特权

评论回复
CoolSilicon| | 2019-5-6 16:32 | 显示全部楼层
oxygenzz 发表于 2019-5-6 16:08
设置使用24位浮点类型:
把下面连接选项加到 XC8 Linker中
-fshort-float

高效!!!!支持大师!

使用特权

评论回复
wei565831866| | 2022-5-25 13:22 | 显示全部楼层
oxygenzz 发表于 2019-5-6 16:08
设置使用24位浮点类型:
把下面连接选项加到 XC8 Linker中
-fshort-float

请问下,得用XC8编译器吗?  我用的PICC编译器是不是不能这样设置啊?
也没法打印浮点数。。。

使用特权

评论回复
lcczg| | 2022-5-26 15:19 | 显示全部楼层
wei565831866 发表于 2022-5-25 13:22
请问下,得用XC8编译器吗?  我用的PICC编译器是不是不能这样设置啊?
也没法打印浮点数。。。 ...

编译出错?
手册里171页有例子。https://ww1.microchip.com/downlo ... /HTC_PIC_manual.pdf

使用特权

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

本版积分规则

4

主题

17

帖子

0

粉丝