打印浮点类型

[复制链接]
 楼主| ousj 发表于 2022-3-6 19:54 | 显示全部楼层 |阅读模式
PIC16F系列MCU用printf函数调试程序时能否打印浮点类型,如果能需要怎样配置?
dingy 发表于 2022-3-6 19:56 | 显示全部楼层
什么意思?不是很明白你说的什么,能再解释一下这个现象吗
 楼主| ousj 发表于 2022-3-6 19:59 | 显示全部楼层
例如  printf("a = %f\r\n",a); a是浮点型,当是%f编译就会出错,改为%d就能正常编译
huangchui 发表于 2022-3-6 20:02 | 显示全部楼层
报错信息?
 楼主| ousj 发表于 2022-3-6 20:04 | 显示全部楼层
0:: error: (1347) can't find 0x22F words (0x22f withtotal) for psect "text20" in class "CODE" (largest unused contiguous range 0x208)
 楼主| ousj 发表于 2022-3-6 20:06 | 显示全部楼层
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
huangchui 发表于 2022-3-6 20:08 | 显示全部楼层
包含头文件#include <stdio.h> 试试看?
zhenykun 发表于 2022-3-6 20:10 | 显示全部楼层

#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);
    }
}
参考这个例子看看?
yszong 发表于 2022-3-6 20:14 | 显示全部楼层
对,
参考这个例子看看?
 楼主| ousj 发表于 2022-3-6 20:17 | 显示全部楼层
这个肯定是包含过的
stly 发表于 2022-3-6 20:20 | 显示全部楼层
用%d的时候编译没错?
chenho 发表于 2022-3-6 20:22 | 显示全部楼层
怀疑是不是不支持浮点
dingy 发表于 2022-3-6 20:24 | 显示全部楼层
输出信息已经写了,使用24位浮点类型
 楼主| ousj 发表于 2022-3-6 20:28 | 显示全部楼层

果然:
consider using the smaller 24-bit floating-point types
supernan 发表于 2022-3-6 20:30 | 显示全部楼层
设置使用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中
dengdc 发表于 2022-3-6 20:32 | 显示全部楼层
高效!!
jiajs 发表于 2022-3-6 20:34 | 显示全部楼层
printf("a = %f\r\n",a); a是浮点型,当是%f编译就会出错,改为%d就能正常编译。
 楼主| ousj 发表于 2022-3-6 20:36 | 显示全部楼层
嗯,我再好好缕一缕吧,有了好消息及时通知大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

712

主题

7557

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

712

主题

7557

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部