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

          新聞中心

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

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

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


          void DS18B20_ReadTemp(void)
          {unsigned char tempH,tempL,tempH_2,tempL_2;
          DS18B20_Init();
          DS18B20_Init_2();
          DS18B20_WriteByte(SkipRom);
          _NOP();
          DS18B20_WriteByte_2(SkipRom);
          _NOP();
          //There is just one DS1820 on the bus;
          DS18B20_WriteByte(ConvertTemperature);
          DelayX10us(10);
          DS18B20_WriteByte_2(ConvertTemperature);
          DelayX10us(10);
          //Start to convert temperature;
          DS18B20_Init();
          DS18B20_Init_2();
          DS18B20_WriteByte(SkipRom);
          _NOP();
          DS18B20_WriteByte_2(SkipRom);
          _NOP();
          DS18B20_WriteByte(ReadScratchpad);
          DS18B20_WriteByte_2(ReadScratchpad);
          GetScratchpad[0]=DS18B20_ReadByte();
          //Master samples the LSB temperature from the scratchpad;
          GetScratchpad[1]=DS18B20_ReadByte();
          //Master samples the MSB temperature from the scratchpad;
          GetScratchpad[2]=DS18B20_ReadByte();
          //Master samples the Th register or userbyte1 from the scratchpad;
          GetScratchpad[3]=DS18B20_ReadByte();
          //Master samples the Tl register or userbyte0 from the scratchpad;
          GetScratchpad[4]=DS18B20_ReadByte();
          //Master samples the configuration register from the scratchpad;
          GetScratchpad[5]=DS18B20_ReadByte();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad[6]=DS18B20_ReadByte();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad[7]=DS18B20_ReadByte();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad[8]=DS18B20_ReadByte();
          //Master samples the CRC from the scratchpad;
          tempH=(GetScratchpad[1] < 4) | (GetScratchpad[0] >> 4);
          tempL=(GetScratchpad[0] & 0x0f);
          DS18B20_Init();

          GetScratchpad_2[0]=DS18B20_ReadByte_2();
          //Master samples the LSB temperature from the scratchpad;
          GetScratchpad_2[1]=DS18B20_ReadByte_2();
          //Master samples the MSB temperature from the scratchpad;
          GetScratchpad_2[2]=DS18B20_ReadByte_2();
          //Master samples the Th register or userbyte1 from the scratchpad;
          GetScratchpad_2[3]=DS18B20_ReadByte_2();
          //Master samples the Tl register or userbyte0 from the scratchpad;
          GetScratchpad_2[4]=DS18B20_ReadByte_2();
          //Master samples the configuration register from the scratchpad;
          GetScratchpad_2[5]=DS18B20_ReadByte_2();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad_2[6]=DS18B20_ReadByte_2();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad_2[7]=DS18B20_ReadByte_2();
          //Master samples the reservedbyte from the scratchpad;
          GetScratchpad_2[8]=DS18B20_ReadByte_2();
          //Master samples the CRC from the scratchpad;
          tempH_2=(GetScratchpad_2[1] < 4) | (GetScratchpad_2[0] >> 4);
          tempL_2=(GetScratchpad_2[0] & 0x0f);
          DS18B20_Init_2();
          //Issue a reset to terminate left parts;
          //if(tempH & 0x80)
          //{ tempH=~tempH;
          //tempL=~tempL+1;
          //ResultSignal=1;
          ////Negative temperature;
          //}
          ResultTemperatureH=tempH;
          ResultTemperatureLL=decimalL[tempL];
          ResultTemperatureLH=decimalH[tempL];

          ResultTemperatureH_2=tempH_2;
          ResultTemperatureLL_2=decimalL[tempL_2];
          ResultTemperatureLH_2=decimalH[tempL_2];
          //Result of temperature;
          }//Read the byte0 and byte1 from scratchpad;



          void Delay10us(void){
          unsigned char i;
          for (i=0; i<(SMCLK/500-3); i++);
          }

          //Time is accurately !!
          void DelayX10us(unsigned char x10us){
          unsigned int i;
          for (i=0; i
          Delay10us
          }

          上一頁 1 2 3 下一頁

          關鍵詞: msp430單片機ds18b2

          評論


          技術專區(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); })();