<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機(jī)的ds18b20驅(qū)動程序

          51單片機(jī)的ds18b20驅(qū)動程序

          作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
          /*************************************
          函數(shù)名:re1820b
          函數(shù)功能:讀數(shù)據(jù)
          參數(shù):無
          返回:dat(數(shù)據(jù))
          備注:無
          *************************************/
          uchar re1820b(void)
          {
          uchar i=0;
          uchar dat = 0;
          for (i=8;i>0;i--)
          {
          DQ = 0; // 給脈沖信號
          dat>>=1;
          DQ = 1; // 給脈沖信號
          if(DQ)
          dat|=0x80;
          delaydq(4);
          }
          return(dat);
          }
          /*************************************
          函數(shù)名:wr1820b
          函數(shù)功能:寫數(shù)據(jù)
          參數(shù):dat(數(shù)據(jù))
          返回:無
          備注:無
          *************************************/
          void wr1820b(uchar dat)
          {
          unsigned char i=0;
          for (i=8; i>0; i--)
          {
          DQ = 0;
          DQ = dat&0x01;
          delaydq(5);
          DQ = 1;
          dat>>=1;
          }
          }
          /*************************************
          函數(shù)名:ReadTemp
          函數(shù)功能:溫度轉(zhuǎn)換
          參數(shù):無
          返回:無
          備注:無
          *************************************/
          void ReadTemp(void)
          {
          unsigned char a=0;
          unsigned char b=0;
          unsigned char t=0;
          dqinit();
          wr1820b(0xCC); // 跳過讀序號列號的操作
          wr1820b(0x44); // 啟動溫度轉(zhuǎn)換
          delaydq(100);
          dqinit();
          wr1820b(0xCC); //跳過讀序號列號的操作
          wr1820b(0xBE); //讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度
          delaydq(100);
          a=re1820b(); //讀取溫度值低位
          b=re1820b(); //讀取溫度值高位
          if(b>127)
          {
          b=(256-b);a=(256-a);fflag=1; //負(fù)溫度求補(bǔ)碼
          }
          temp_value=b<<4;
          temp_value+=(a&0xf0)>>4;
          temp2=a&0x0f; //小數(shù)的值
          xs=temp2*0.0625*10; //小數(shù)位,若為0.5則算為5來顯示 xs小數(shù)
          }
          /*************************************
          函數(shù)名:temp_to_str
          函數(shù)功能:溫度顯示
          參數(shù):無
          返回:無
          備注:無
          *************************************/
          void temp_to_str() //溫度數(shù)據(jù)轉(zhuǎn)換成液晶字符顯示
          {
          if(fflag==1)
          { TempBuffer[0]=-;
          TempBuffer[1]=temp_value/10+0; //十位
          TempBuffer[2]=temp_value%10+0; //個位
          TempBuffer[3]=.;
          TempBuffer[4]=xs+0;
          TempBuffer[5]=0xdf; //溫度符號
          TempBuffer[6]=C;
          TempBuffer[7]=看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();