欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 能有大佬幫我看看這個單片機DS18B20哪里寫錯了嗎?顯示000.0000 [打印本頁]

作者: ArroGance    時間: 2023-3-29 22:16
標(biāo)題: 能有大佬幫我看看這個單片機DS18B20哪里寫錯了嗎?顯示000.0000
#include <at89c51RC2.h>
#include <intrins.h>


sbit DS18B20_IO = P3^7;

#define DS18B20_SKIP_ROM        0xCC
#define DS18B20_CONVERT_T       0x44
#define DS18B20_READ_SCRATCHPAD 0xBE

unsigned char DS18B20_Start(void) //初始化
{
        unsigned int i;
        unsigned char Ack;
        DS18B20_IO=1;
        DS18B20_IO=0;
        i = 227;while (--i);//延時500us
        DS18B20_IO=1;
        i = 29;while (--i);//延時70us
        Ack=DS18B20_IO;
        i = 227;while (--i);//延時500us
        return Ack;
}

void DS18B20_SendByte(unsigned char Byte)//寫入一個字節(jié)
{
        unsigned int j,i;
        for(j=0; j<8; j++)
        {        
                DS18B20_IO=0;
                i = 4;while (--i);//延時10us
                DS18B20_IO=Byte&(0x01<<j);
                if(DS18B20_IO==1)
                {               
                        DS18B20_IO=1;               
                }
                i = 23;while (--i);//延時50us        
                DS18B20_IO=1;
                _nop_();_nop_();
        }
}

unsigned char DS18B20_ReceiveByte(void)
{
        unsigned char Byte=0x00;
        unsigned int j,i;
        for(j=0; j<8; j++)
        {
                DS18B20_IO=0;
                i = 2;while (--i);//延時5us
                DS18B20_IO=1;
                i = 2;while (--i);//延時5us
                if(DS18B20_IO==1)
                {
                        Byte|=(0x01<<j);
                }
                i = 23;while (--i);//延時50us
                DS18B20_IO=1;
                _nop_();_nop_();
        }
        return Byte;
}

void ConvertT(void)
{
        DS18B20_Start();
        DS18B20_SendByte(DS18B20_SKIP_ROM);
        DS18B20_SendByte(DS18B20_CONVERT_T);
}

float ReadT(void)
{
        unsigned char LSB,MSB;
        int Tmp;
        float T;
        DS18B20_Start();
        DS18B20_SendByte(DS18B20_SKIP_ROM);
        DS18B20_SendByte(DS18B20_READ_SCRATCHPAD);
        LSB=DS18B20_ReceiveByte();
        MSB=DS18B20_ReceiveByte();
        Tmp=(MSB<<8)|LSB;
        T=Tmp/16.0;
        return T;
}




作者: zhongfofo    時間: 2023-3-30 08:51
溫度設(shè)計要看你電路那塊配合來寫程序的。
作者: ArroGance    時間: 2023-3-30 10:59
zhongfofo 發(fā)表于 2023-3-30 08:51
溫度設(shè)計要看你電路那塊配合來寫程序的。

大佬能幫我看下上面OneWire總線部分嗎,我總感覺那里的寫入和讀出有問題
就是這兩個  
void DS18B20_SendByte(unsigned char Byte)
unsigned char DS18B20_ReceiveByte(void)




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