標(biāo)題: protues單片機(jī)數(shù)碼管顯示DS18B20,數(shù)據(jù)一直是00,會(huì)不會(huì)是延時(shí)時(shí)間出錯(cuò) [打印本頁(yè)]

作者: captaine    時(shí)間: 2022-12-4 10:31
標(biāo)題: protues單片機(jī)數(shù)碼管顯示DS18B20,數(shù)據(jù)一直是00,會(huì)不會(huì)是延時(shí)時(shí)間出錯(cuò)
單片機(jī)源程序如下:
#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, 下載次數(shù): 55)

屏幕截圖 2022-12-04 102858.png

作者: wc86110    時(shí)間: 2022-12-4 16:03
撇開(kāi)程序不說(shuō)單單溫度探頭復(fù)位電路都有點(diǎn)問(wèn)題
作者: captaine    時(shí)間: 2022-12-4 18:48
已經(jīng)改了,溫度 是需要把那個(gè)電阻刪除嗎
作者: man1234567    時(shí)間: 2022-12-5 14:55
會(huì)不會(huì)是延時(shí)時(shí)間出錯(cuò) ? 試試就知道了哈




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1