找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 871|回复: 3
打印 上一主题 下一主题
收起左侧

protues单片机数码管显示DS18B20,数据一直是00,会不会是延时时间出错

[复制链接]
跳转到指定楼层
楼主
单片机源程序如下:
#include <REGX51.H>
#include "intrins.h"

sbit DQ = P3^0;
uchar i;

int tem;
unsigned char NixieTable[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};


void Nixie(unsigned char location,unsigned char number)
{
        P2 = 0x00;
                switch(location)
        {
                case 1:P2_0 = 1; P2_1 = 0; P2_2 = 0; P2_3 = 0; break;
                case 2:P2_0 = 0; P2_1 = 1; P2_2 = 0; P2_3 = 0; break;
                case 3:P2_0 = 0; P2_1 = 0; P2_2 = 1; P2_3 = 0; break;
                case 4:P2_0 = 0; P2_1 = 0; P2_2 = 0; P2_3 = 1; break;
        }
        P0 = NixieTable[number];
        Delay1ms(10);
}


int        DS18B20_Init(void)
{
        uint Ack;
        DQ = 1;
        Delay1us(10);
        
        DQ = 0;
        Delay1us(480);
        DQ = 1;
        Delay1us(40);
        
        Ack = DQ;
        return Ack;
}

void SendByte(uchar Byte)
{
        DQ=1;
        Delay1us(1);
        for(i=0;i<8;i++)
        {
                DQ=0;
                DQ=Byte&0x01;
                Delay1us(5);
                DQ=1;
                Byte>>=1;
        }
}

uchar RcvByte(void)
{
        uchar Byte;

        DQ=1;
        Delay1us(1);
        for (i=8;i>0;i--)
        {
                DQ=0;
                Byte>>=1;
                DQ=1;
                Delay1us(1);
                if(DQ)
                Byte|=0x80;
                Delay1us(30);
                DQ=1;

        }
        return Byte;
}
float Get_temp(void)
{
        uchar TL, TH;
        int temp;                float T;
        DS18B20_Init();
        SendByte(0xcc);
        SendByte(0x44);
        Delay1us(5);
                DS18B20_Init();
                SendByte(0xcc);
                SendByte(0x44);
                SendByte(0xBE);
        TL = RcvByte();
        TH = RcvByte();
        temp = (TH << 8) | TL;
        T = temp * 0.0625;
        return T;
        
}


void main()
{
        
        while(1)
        {               
                tem = (int)Get_temp();
                Nixie(1,tem/10);
                Nixie(2,tem%10);
        }
        
}


屏幕截图 2022-12-04 102858.png (53.82 KB, 下载次数: 19)

屏幕截图 2022-12-04 102858.png
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:96682 发表于 2022-12-4 16:03 | 只看该作者
撇开程序不说单单温度探头复位电路都有点问题
回复

使用道具 举报

板凳
ID:1027942 发表于 2022-12-4 18:48 | 只看该作者
已经改了,温度 是需要把那个电阻删除吗
回复

使用道具 举报

地板
ID:584814 发表于 2022-12-5 14:55 | 只看该作者
会不会是延时时间出错 ? 试试就知道了哈
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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