电子技术论坛

 找回密码
 快速注册

QQ登录

只需一步,快速开始

搜索
下载方法|用单线程|避免多扣帖子规范|求助必读|发帖建议积分策略|勋章介绍|新人必读获取金币|推广论坛|出售帖子基本礼节|致会员信|版规总则
禁涉政治|反对低俗|举报专帖征集相片|留下足迹|推荐精华上传附件|制作分卷|使用网盘禁发qq群|恶意灌水|纯表情帖加入团队|监督机制|安全上网
查看: 1970|回复: 1

关于DS18B20和数码管

[复制链接]
发表于 2012-3-20 18:21:28 | 显示全部楼层 |阅读模式

注册家电维修技术论坛,与同行畅聊维修技术,享更多技术论坛功能。

您需要 登录 才可以下载或查看,没有帐号?快速注册

x
这个程序是DS18B20读回的温度值显示在数码管的两位上,但效果是十位上的数不停闪烁,个位的数稳定正常显示,怎么处理?谢谢各位了

程序:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char

sbit DQ=P3^7;

uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

uchar temp,shi,ge;

void delay_4us(uint time)
{
        while(time--);
}

void delay_ms(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
                for(y=110;y>0;y--);
}

uchar DS18b20_reset()
{
        uchar i;
        DQ=1;
        DQ=0;
        delay_4us(180);
        DQ=1;
        delay_4us(10);
        i=DQ;
        while(!DQ);   //等待存在脉冲
        return i;       
}

void DS18b20_writebyte(uchar dat18w)
{
        uchar i;
        for(i=0;i<8;i++)
        {
                DQ=0;
                DQ=dat18w&0x01;
                delay_4us(4);
                DQ=1;
                dat18w>>=1;               
        }
                delay_4us(10);
}

uchar DS18b20_readbyte()
{
        uchar i,dat18r;
        for(i=0;i<8;i++)
        {
                DQ=1;
                DQ=0;
                dat18r>>=1;
                DQ=1;
                if(DQ)
                dat18r|=0x80;
                delay_4us(10);
        }
        return dat18r;
}

uchar read1temperature()
{
        uchar L,H;
        while(DS18b20_reset());
        DS18b20_writebyte(0xcc);
        DS18b20_writebyte(0x44);
        delay_ms(750);

        while(DS18b20_reset());
        DS18b20_writebyte(0xcc);
        DS18b20_writebyte(0xbe);       
        L=DS18b20_readbyte();
        H=DS18b20_readbyte();
        H<<=4;
        H+=(L&(0xf0))>>4;
        while(DS18b20_reset());
        return H;
}

void display(uchar shi,uchar ge)
{
                        P0=table[shi];
                        P2=0xbf;
                        delay_ms(10);

                        P0=table[ge];
                        P2=0xdf;
                        delay_ms(10);
}


void main()
{       
        while(1)
        {
                temp=read1temperature();
                shi=temp/10;
                ge=temp%10;

                display(shi,ge);
        }
}
发表于 2012-3-30 08:57:03 | 显示全部楼层
可能延时长了
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|家电维修技术论坛 ( 鄂ICP备09003585号-2 )

GMT+8, 2025-2-22 23:28 , Processed in 0.046515 second(s), 5 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

CopyRight © 电子技术论坛
电子邮箱:8794149@qq.com | 联系 QQ:3081868839 | 官方网址:www.dzdu.com

Qiji. All Rights Reserved


服务条款 | 站长声明

Wuhan Qiji Technology Co., Ltd.武汉奇迹科技有限公司版权所有


鄂ICP备09003585号-2鄂公网安备42010602000420号

快速回复 返回顶部 返回列表