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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > msp430單片機的ds18b20測溫度c程序

          msp430單片機的ds18b20測溫度c程序

          作者: 時間:2016-11-27 來源:網(wǎng)絡(luò) 收藏


          // 功能函數(shù)定義

          unsigned char DS18B20_Init(void){
          unsigned char result;
          DS18B20_DIR |= DS18B20_DQ;// ow output
          DS18B20_OUT &= ~DS18B20_DQ;// DS18B20_DQ=0;
          DelayX10us(48);// Bus master pulling low 480us minimum;
          DS18B20_OUT |= DS18B20_DQ;// DS18B20_DQ=1;
          DelayX10us(6);// Resister pull up 15-60us;
          DS18B20_DIR &= ~DS18B20_DQ;// ow input
          result = DS18B20_IN & DS18B20_DQ;
          DS18B20_DIR |= DS18B20_DQ;// ow output
          DelayX10us(48);// End of timeslot total 480us;
          return(result);// any 1 wire device ?result:=1 no devide; ?result:=0 have device;
          }//Intialization the 1-wire devices;

          unsigned char DS18B20_Init_2(void){
          unsigned char result;
          DS18B20_DIR |= DS18B20_DQ_2;// ow output
          DS18B20_OUT &= ~DS18B20_DQ_2;// DS18B20_DQ=0;
          DelayX10us(48);// Bus master pulling low 480us minimum;
          DS18B20_OUT |= DS18B20_DQ_2;// DS18B20_DQ=1;
          DelayX10us(6);// Resister pull up 15-60us;
          DS18B20_DIR &= ~DS18B20_DQ_2;// ow input
          result = DS18B20_IN & DS18B20_DQ_2;
          DS18B20_DIR |= DS18B20_DQ_2;// ow output
          DelayX10us(48);// End of timeslot total 480us;
          return(result);// any 1 wire device ?result:=1 no devide; ?result:=0 have device;
          }//Intialization the 1-wire devices;


          unsigned char DS18B20_ReadBit(void){
          unsigned char result;
          DS18B20_DIR |= DS18B20_DQ;// ow output
          DS18B20_OUT &= ~DS18B20_DQ;// DS18B20_DQ=0;
          _NOP();// Start of timeslot;
          DS18B20_OUT |= DS18B20_DQ;// DS18B20_DQ=1;
          _NOP();_NOP();_NOP();_NOP();
          // Wait from the start;
          DS18B20_DIR &= ~DS18B20_DQ;// ow input
          result = DS18B20_IN & DS18B20_DQ;
          DS18B20_DIR |= DS18B20_DQ;// ow output
          return(result);// return the result of the 1-wire devide;
          }//Read a bit on the 1-wire bus;

          unsigned char DS18B20_ReadBit_2(void){
          unsigned char result;
          DS18B20_DIR |= DS18B20_DQ_2;// ow output
          DS18B20_OUT &= ~DS18B20_DQ_2;// DS18B20_DQ=0;
          _NOP();// Start of timeslot;
          DS18B20_OUT |= DS18B20_DQ_2;// DS18B20_DQ=1;
          _NOP();_NOP();_NOP();_NOP();
          // Wait from the start;
          DS18B20_DIR &= ~DS18B20_DQ_2;// ow input
          result = DS18B20_IN & DS18B20_DQ_2;
          DS18B20_DIR |= DS18B20_DQ_2;// ow output
          return(result);// return the result of the 1-wire devide;
          }//Read a bit on the 1-wire bus;


          void DS18B20_WriteBit(unsigned char oww_dat){
          DS18B20_DIR |= DS18B20_DQ;// ow output
          DS18B20_OUT &= ~DS18B20_DQ;// DS18B20_DQ=0;
          if (1 == oww_dat)
          DS18B20_OUT |= DS18B20_DQ;// DS18B20_DQ=1;
          DelayX10us(10);// Remain the state for 100us;
          DS18B20_OUT |= DS18B20_DQ;// DS18B20_DQ=1;
          }//Write a bit to the 1-wire bus;

          void DS18B20_WriteBit_2(unsigned char oww_dat){
          DS18B20_DIR |= DS18B20_DQ_2;// ow output
          DS18B20_OUT &= ~DS18B20_DQ_2;// DS18B20_DQ=0;
          if (1 == oww_dat)
          DS18B20_OUT |= DS18B20_DQ_2;// DS18B20_DQ=1;
          DelayX10us(10);// Remain the state for 100us;
          DS18B20_OUT |= DS18B20_DQ_2;// DS18B20_DQ=1;
          }//Write a bit to the 1-wire bus;


          unsigned char DS18B20_ReadByte(void){
          unsigned char i;
          unsigned char result=0;
          for(i = 0; i8; i++){
          if(DS18B20_ReadBit())
          result |= 0x01 < i;
          DelayX10us(12);// ??
          }
          return(result);// return the result of the 1-wire device;
          }//Read a byte from the 1-wire bus;

          unsigned char DS18B20_ReadByte_2(void){
          unsigned char i;
          unsigned char result=0;
          for(i = 0; i8; i++){
          if(DS18B20_ReadBit_2())
          result |= 0x01 < i;
          DelayX10us(12);// ??
          }
          return(result);// return the result of the 1-wire device;
          }//Read a byte from the 1-wire bus;


          void DS18B20_WriteByte(unsigned char oww_dat){
          unsigned char i,temp;
          for(i = 0; i8; i++){
          temp = oww_dat >> i;
          temp &= 0x01;
          DS18B20_WriteBit(temp);
          }
          DelayX10us(7);// ??
          }//Write a byte to the 1-wire bus;

          void DS18B20_WriteByte_2(unsigned char oww_dat){
          unsigned char i,temp;
          for(i = 0; i8; i++){
          temp = oww_dat >> i;
          temp &= 0x01;
          DS18B20_WriteBit_2(temp);
          }
          DelayX10us(7);// ??
          }//Write a byte to the 1-wire bus;


          關(guān)鍵詞: msp430單片機ds18b2

          評論


          技術(shù)專區(qū)

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