欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: STC89C516單片機(jī)調(diào)用DS18B20溫度傳感器代碼問(wèn)題 [打印本頁(yè)]

作者: 大膽1    時(shí)間: 2021-2-3 12:56
標(biāo)題: STC89C516單片機(jī)調(diào)用DS18B20溫度傳感器代碼問(wèn)題
跟著b站上學(xué)習(xí)的單片機(jī),在溫度傳感器碰到了瓶頸,訪問(wèn)溫度返回的數(shù)據(jù)一直顯示255看到本論壇有相關(guān)的帖子說(shuō)是時(shí)序問(wèn)題,我就用軟件又重新生成了一遍相關(guān)的延時(shí)
結(jié)果還是不行,然后又屢著視頻代碼一遍遍的看還是不行
希望大佬可以幫忙看看是那邊錯(cuò)的
下面附上代碼
                  單總線的代碼
  1. #include <REGX52.H>
  2. sbit OneWire_DQ=P3^7;
  3. unsigned char OneWire_Init()
  4. {
  5.   unsigned char i,r;
  6.   OneWire_DQ=1;
  7.   OneWire_DQ=0;
  8.   i = 247;while (--i);//延時(shí)500us  229
  9.   OneWire_DQ=1;
  10.         i = 32;while (--i);//延遲70us  31
  11.   i=OneWire_DQ;
  12.   i = 247;while (--i);//延時(shí)500us  229
  13.   return r;
  14. }

  15. void OneWire_Write(unsigned char Bit)
  16. {
  17.   unsigned char i;
  18.   OneWire_DQ=0;
  19.   i = 4;while (--i);//延遲10us  3
  20.   OneWire_DQ=Bit;
  21.   i = 25;while (--i);//延遲60us  4(60)
  22.   OneWire_DQ=1;
  23. }

  24. unsigned char OneWire_Read()
  25. {
  26.   unsigned char i;
  27.   unsigned char Bit;
  28.   OneWire_DQ=0;
  29.   i = 2;while (--i);//延遲5us
  30.   OneWire_DQ=1;
  31.   i = 2;while (--i);//延遲5us  (9us)
  32.   Bit=OneWire_DQ;
  33.   i = 24;while (--i);//延遲50us  24
  34.   return Bit;
  35. }

  36. void OneWire_SendByte(unsigned char Data)
  37. {
  38.         unsigned char i;
  39.         for(i=0;i<8;i++)
  40.         {
  41.                 OneWire_Write(Data&(0x01<<i));               
  42.         }
  43. }

  44. unsigned char OneWire_ReadByte()
  45. {
  46.   unsigned char i;
  47.   unsigned char Byte=0x00;
  48.                 for(i=0;i<8;i++)
  49.         {
  50.                 if(OneWire_Read()){Byte|=(0x01<<i);}               
  51.         }
  52.   return Byte;
  53. }
復(fù)制代碼
      返回?cái)?shù)據(jù)的代碼
  1. #include <REGX52.H>
  2. #include "OneWire.h"
  3. #include "LCD1602.h"
  4. void Delay1ms()                //@12.000MHz
  5. {
  6.         unsigned char i, j;

  7.         i = 1;
  8.         j = 110;
  9.         do
  10.         {
  11.                 while (--j);
  12.         } while (--i);
  13. }

  14. void DS18B20_ConvertT()
  15. {
  16.         OneWire_Init();
  17.         Delay1ms();
  18.         OneWire_Write(0xCC);
  19.         OneWire_Write(0x44);
  20. }
  21. float DS18B20_Read()
  22. {
  23.         unsigned char TLSB,TMSB;
  24.         int temp;
  25.         float T;
  26.         OneWire_Init();
  27.         Delay1ms();
  28.         OneWire_Write(0xCC);
  29.         OneWire_Write(0xBE);
  30.         TLSB=OneWire_ReadByte();
  31.         TMSB=OneWire_ReadByte();//          用的LCD1602顯示的數(shù)據(jù)
  32.   LCD_ShowNum(1,1,TMSB,8);//         
  33.   LCD_ShowNum(1,9,TLSB,8);
  34.         temp=(TMSB<<8)|TLSB;
  35.         T=temp/16.0;
  36.         return T;
  37. }
復(fù)制代碼





作者: 起風(fēng)了~    時(shí)間: 2021-2-3 17:17
如果是網(wǎng)上買的開(kāi)發(fā)板的話,建議看看配套資料,參考一下資料
作者: lincheng15    時(shí)間: 2021-2-3 18:12
缺少調(diào)試經(jīng)驗(yàn),先查18B20時(shí)序,再用示波器抓你程序的控制時(shí)序是否和18B20數(shù)據(jù)手冊(cè)上寫(xiě)的一致,查完了就知道該懷疑軟件還是硬件了,實(shí)際調(diào)試過(guò)程中有很多時(shí)候就是硬件問(wèn)題,比如器件不小心燒壞了,或者焊接問(wèn)題,要先學(xué)解決問(wèn)題的辦法,這樣以后什么問(wèn)題都可以有方法可尋
作者: 人人學(xué)會(huì)單片機(jī)    時(shí)間: 2021-2-3 21:19
這玩意沒(méi)辦法 拿分析儀調(diào)就是了  建議你看看我的貼子 里面有18B20的代碼
作者: lovezjf234    時(shí)間: 2021-2-4 15:38
代碼顯示不全,一般沒(méi)讀出來(lái)是時(shí)序問(wèn)題或者器件ID碼識(shí)別不對(duì)(有些代碼會(huì)做這個(gè)操作)
作者: univers    時(shí)間: 2021-2-4 15:50
你有開(kāi)發(fā)板么?如果有DS18B20的例程,套用例程的就對(duì)了,之后再一個(gè)一個(gè)局部小改,再上板測(cè)試就慢慢懂了。一下來(lái)就全搞,會(huì)亂套的。其實(shí)網(wǎng)上很多DS18B20的例程。




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1