打印浮点类型

[复制链接]
934|17
 楼主| ousj 发表于 2020-9-2 22:07 | 显示全部楼层 |阅读模式
PIC16F系列MCU用printf函数调试程序时能否打印浮点类型,如果能需要怎样配置?
dingy 发表于 2020-9-2 22:12 | 显示全部楼层

什么意思?不是很明白你说的什么,能再解释一下这个现象吗
 楼主| ousj 发表于 2020-9-2 22:16 | 显示全部楼层
例如  printf("a = %f\r\n",a); a是浮点型,当是%f编译就会出错,改为%d就能正常编译
guoyt 发表于 2020-9-2 22:22 | 显示全部楼层
报错信息?
 楼主| ousj 发表于 2020-9-2 22:25 | 显示全部楼层
0:: error: (1347) can't find 0x22F words (0x22f withtotal) for psect "text20" in class "CODE" (largest unused contiguous range 0x208)
 楼主| ousj 发表于 2020-9-2 22:29 | 显示全部楼层
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
wangzsa 发表于 2020-9-2 22:32 | 显示全部楼层
包含头文件#include <stdio.h> 试试看?
wangpe 发表于 2020-9-2 22:35 | 显示全部楼层

#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);
    }
}
参考这个例子看看?
guoyt 发表于 2020-9-2 22:38 | 显示全部楼层
#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);
    }
}
参考这个例子看看?
 楼主| ousj 发表于 2020-9-2 22:45 | 显示全部楼层
这个肯定是包含过的
huanghuac 发表于 2020-9-2 22:47 | 显示全部楼层
用%d的时候编译没错?
chenho 发表于 2020-9-2 22:51 | 显示全部楼层
怀疑是不是不支持浮点
dingy 发表于 2020-9-2 22:54 | 显示全部楼层
输出信息已经写了,使用24位浮点类型
zhanglli 发表于 2020-9-2 22:59 | 显示全部楼层

果然:
consider using the smaller 24-bit floating-point types
lium 发表于 2020-9-2 23:02 | 显示全部楼层
设置使用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中
pangb 发表于 2020-9-2 23:08 | 显示全部楼层
高效!!
 楼主| ousj 发表于 2020-9-2 23:12 | 显示全部楼层

嗯,我再好好缕一缕吧,有了好消息及时通知大家
看别人照片 发表于 2020-9-3 09:30 | 显示全部楼层
printf("a = %f\r\n",a); a是浮点型,当是%f编译就会出错,改为%d就能正常编译。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

712

主题

7557

帖子

1

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