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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 基于ARM9的18B20溫度傳感器程序

          基于ARM9的18B20溫度傳感器程序

          作者: 時間:2016-11-24 來源:網絡 收藏
          18B20溫度傳感器,典型的時序操作器件,用51單片機寫很方便,可是把這現(xiàn)成的程序移植到FPGA、ARM、430上面,還需要一定的翻譯功底。

          本文引用地址:http://www.ex-cimer.com/article/201611/320703.htm

          //-------------------------------------------------------------------------------------
          //函數名稱:dmsec //入口參數:count //函數功能:延時子程序
          //-------------------------------------------------------------------------------------
          void dmsec(uint count) { uchar i;
          while(count--) {
          for(i=0;
          i<125;
          i++);
          }
          }
          //-------------------------------------------------------------------------------------
          //函數名稱:tmreset //入口參數:無 //函數功能:
          //-------------------------------------------------------------------------------------
          void tmreset(void) {
          ushort i;
          dq=0;
          i=343;
          while(i>0) i--;
          //大約900us dq=1;
          i=13;
          while(i>0) i--;
          } //-------------------------------------------------------------------------------------
          //函數名稱:tmpre //入口參數:無 //函數功能:等待DS18B20應答
          //-------------------------------------------------------------------------------------
          void tmpre(void) {
          uchar i;
          while(dq);
          while(~dq);
          i=13;
          while(i>0) i--;
          } //-------------------------------------------------------------------------------------
          //函數名稱:tmrbit //入口參數:無 //返回值: dat //函數功能:在總線上讀一位
          //-------------------------------------------------------------------------------------
          bit tmrbit(void) {
          uchar i;
          bit dat;
          dq=0;
          i++;
          dq=1;
          i++;
          i++;
          dat=dq;
          i=30;
          while(i>0) i--;
          return(dat);
          } //-------------------------------------------------------------------------------------
          //函數名稱:tmrbyte //入口參數:無 //返回值: dat //函數功能:讀一個字節(jié)
          //-------------------------------------------------------------------------------------
          uchar tmrbyte(void) {
          uchar i,j,dat=0;
          for(i=1;i<=8;i++) {
          j=tmrbit();
          dat=(j<<7)|(dat>>1);
          }
          return(dat);
          } //-------------------------------------------------------------------------------------
          //函數名稱:tmwbyte //入口參數:dat //函數功能:寫命令
          //-------------------------------------------------------------------------------------
          void tmwbyte(uchar dat) {
          uint i;
          uchar j;
          bit testb;
          for(j=1;j<=8;j++) {
          testb=dat&0x01;
          dat=dat>>1;
          if(testb) {
          dq=0;
          //寫1 i++;
          i++;
          dq=1;
          i=27;
          while(i>0) i--;
          }
          else {
          dq=0;
          //寫0 i=27;
          while(i>0) i--;
          dq=1;
          i++;
          i++;
          }
          }
          } //-------------------------------------------------------------------------------------
          //函數名稱:tmrbyte //入口參數:無 //函數功能:讀取溫度值
          //-------------------------------------------------------------------------------------
          void read_tr() {
          uchar a,b;
          ushort y;
          tmreset();
          tmpre();
          dmsec(1);
          tmwbyte(0xcc);
          tmwbyte(0x44);
          dmsec(100);
          tmreset();
          tmpre();
          dmsec(1);
          tmwbyte(0xcc);
          tmwbyte(0xbe);
          a=tmrbyte();
          //l b=tmrbyte();
          //h y=b&0x0f;
          y=y<<8;
          y=a|y;
          if(y>0x800) {
          y=0x1000-y;
          bjTr=cal12bit(y);
          bjTr=bjTr+0x8000;
          }
          else
          {
          bjTr=cal12bit(y);
          }
          } //12位精度
          void temp_init(void) {
          tmreset();
          tmpre();
          tmwbyte(0xcc);
          tmwbyte(0x4e);
          tmwbyte(0x88);
          tmwbyte(0x44);
          tmwbyte(0x7f);
          tmreset();
          }



          關鍵詞: ARM918B20溫度傳感

          評論


          技術專區(qū)

          關閉
          看屁屁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); })();