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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機(jī)驅(qū)動ds18b20用12864液晶顯示溫度程序

          單片機(jī)驅(qū)動ds18b20用12864液晶顯示溫度程序

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

          UINT16 temperature;//讀取溫度保存在此,用作暫存顯示時候分位顯示

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

          /*------------------------------------
          初始化18B20
          ------------------------------------*/
          bit DS18b20_Init()
          {
          bit ok;
          DQ=1;
          DelayUs2x(5);
          DQ=0;
          DelayUs2x(200);
          DelayUs2x(200);
          DQ=1;//釋放總線,準(zhǔn)備接收器件回應(yīng)
          DelayUs2x(50);
          ok=DQ;
          DelayUs2x(25);
          return ok;
          }

          /*------------------------------------
          向18b20寫數(shù)據(jù)
          ------------------------------------*/
          void DS18b20_WriteByte(UINT8 byte)
          {
          UINT8 i;
          for(i=0;i<8;i++)
          {
          DQ=0;
          DelayUs2x(5);//區(qū)分讀寫,讓讀的時間過去。
          DQ=byte&0x01;
          DelayUs2x(15);//讓有效數(shù)據(jù)穩(wěn)定
          DQ=1;//電平穩(wěn)定后,釋放總線
          DelayUs2x(5);
          byte>>=1;
          }
          DelayUs2x(25);//給芯片時間存數(shù)據(jù)
          }

          /*------------------------------------
          從18b20讀數(shù)據(jù)
          ------------------------------------*/
          UINT8 DS18b20_ReadByte()
          {
          UINT8 byte,i;
          for(i=0;i<8;i++)
          {
          DQ=0;
          byte>>=1;
          DQ=1;
          if(DQ)//執(zhí)行到此處,前面的語句已經(jīng)夠電平穩(wěn)定了,不用另加延時
          byte|=0x80;
          DelayUs2x(20);
          }
          return byte;
          }

          /*------------------------------------
          讀溫度
          ------------------------------------*/
          UINT16 DS18b20_ReadTemperature()
          {
          UINT16 b;
          UINT8 a;
          DS18b20_Init();
          DS18b20_WriteByte(0xcc);//skip rom 跳過ROM序列號檢查
          DS18b20_WriteByte(0x44);//convert temperature 轉(zhuǎn)換數(shù)字溫度
          DelayMs(10);//給芯片時間采樣,轉(zhuǎn)換溫度的時間
          DS18b20_Init();
          DS18b20_WriteByte(0xcc);
          DS18b20_WriteByte(0xbe);//讀取暫存器
          a=DS18b20_ReadByte();//低八位
          b=DS18b20_ReadByte();//高八位
          b<<=8;
          b=(b+a)*0.625;//放大十倍放在b中
          return b;
          }

          /*------------------------------------
          溫度顯示
          ------------------------------------*/
          void Display_Temperature()
          {
          temperature=DS18b20_ReadTemperature();//讀取溫度到轉(zhuǎn)換變量里
          /*
          LCD_SendImg16x16(0,3,User4_16x16,0);//顯示溫度圖標(biāo)
          LCD_SendImg16x16(3,3,User2_16x16,0);*///顯示℃
          LCD_WriteCommand(0x30);
          LCD_WriteCommand(0x98);
          LCD_DisplayCGRAM(3);
          LCD_WriteCommand(0x9B);
          LCD_DisplayCGRAM(2);
          LCD_WriteCommand(0x06);
          LCD_WriteCommand(0x99);
          LCD_WriteData(temperature%1000/100|0x30);
          LCD_WriteData(temperature%100/10|0x30);
          LCD_WriteData(.);
          LCD_WriteData(temperature%10|0x30);
          }

          #endif


          上一頁 1 2 下一頁

          評論


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