标题: 求助,下边程序只要添加dat_code[],数码管就无法正常显示 求解? [打印本页]

作者: wucaimeng    时间: 2022-8-14 06:48
标题: 求助,下边程序只要添加dat_code[],数码管就无法正常显示 求解?
#include"public.h"
#include"smg.h"
#include"ds18b20.h"

void main()
{
        int temp_temperture=0;
        uchar temp_buff[6];
        uchar ds18b20_init(void);    //初始化 根据返回值判断 DS18B20是否在线
        while(1)
        {
                 temp_temperture=125.23*100;
                if(temp_temperture<0)
                {
                        temp_buff[0]=0x40;
                }
                else temp_buff[0]=0x00;                                                 

                temp_buff[1]=dat_code[temp_temperture%10];                //个位
                temp_buff[2]=dat_code[temp_temperture%100/10];                //十位
                temp_buff[3]=dat_code[temp_temperture%1000/100];            //百位         加小数点
                temp_buff[4]=dat_code[temp_temperture%10000/1000];                //千位
                temp_buff[5]=dat_code[temp_temperture/10000];

                display(1,temp_buff[1]);
                display(2,temp_buff[2]);
                display(3,temp_buff[3]);
                display(4,temp_buff[4]);
                display(5,temp_buff[5]);
                display(6,temp_buff[0]);
        }
}






作者: xianfajushi    时间: 2022-8-14 10:44
盲人摸象还是管中窥豹?
作者: 飞云居士    时间: 2022-8-14 11:39
dat_code[temp_temperture%10]应该是dat_code[temp_temperture]%10。下面同理
作者: angmall    时间: 2022-8-14 13:02
你有资料我们没有,你有原理图我们没有,你有模块化程序我们没有。就你那两句描述,怎么帮你

你这个程序不完整,没法给你看是哪里出问题了!

作者: 名字不是重点    时间: 2022-8-14 17:09
第8行:
uchar ds18b20_init(void);    //初始化 根据返回值判断 DS18B20是否在线
是什么鬼?

作者: 名字不是重点    时间: 2022-8-14 17:26
飞云居士 发表于 2022-8-14 11:39
dat_code[temp_temperture%10]应该是dat_code[temp_temperture]%10。下面同理

你确定?
作者: Hephaestus    时间: 2022-8-14 19:59
飞云居士 发表于 2022-8-14 11:39
dat_code[temp_temperture%10]应该是dat_code[temp_temperture]%10。下面同理

这一句显然楼主是对的,你是错的。
作者: lkc8210    时间: 2022-8-14 22:31
display函数是怎么写的?
作者: 单片机学习习    时间: 2022-8-19 21:45
uchar ds18b20_init(void);   把括号里的void去掉就行了
作者: Hephaestus    时间: 2022-8-19 23:37
单片机学习习 发表于 2022-8-19 21:45
uchar ds18b20_init(void);   把括号里的void去掉就行了

你的回复毫无道理啊!
作者: robinsonlin    时间: 2022-8-20 12:58
temp_buff[4]=dat_code[temp_temperture%10000/1000];                //千位
temp_buff[5]=dat_code[temp_temperture/10000];


temp_buff[]  是 int 类型吧?  你把int类型来除以10000。  大概率是这里卡住了。 尝试把 上面两句注释掉试试看看。
作者: xxxevery    时间: 2022-8-25 15:01
楼主只是说数码管无法正常显示,是显示不出来吗?还是显示的和自己预想的不一样,从给出的程序看,除
temp_temperture=125.23*100;这句有取值范围的问题(temp_temperture是int值,而125.23是浮点数,但这里编译器可以隐式转换过去),整个主程序应该可以编译过去,楼主要想搞清楚问题所在还是要把情况再说清楚些




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1