欧美极品高清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ò)的
下面附上代碼
單總線的代碼
#include <REGX52.H>
sbit OneWire_DQ=P3^7;
unsigned char OneWire_Init()
{
unsigned char i,r;
OneWire_DQ=1;
OneWire_DQ=0;
i = 247;while (--i);//延時(shí)500us 229
OneWire_DQ=1;
i = 32;while (--i);//延遲70us 31
i=OneWire_DQ;
i = 247;while (--i);//延時(shí)500us 229
return r;
}
void OneWire_Write(unsigned char Bit)
{
unsigned char i;
OneWire_DQ=0;
i = 4;while (--i);//延遲10us 3
OneWire_DQ=Bit;
i = 25;while (--i);//延遲60us 4(60)
OneWire_DQ=1;
}
unsigned char OneWire_Read()
{
unsigned char i;
unsigned char Bit;
OneWire_DQ=0;
i = 2;while (--i);//延遲5us
OneWire_DQ=1;
i = 2;while (--i);//延遲5us (9us)
Bit=OneWire_DQ;
i = 24;while (--i);//延遲50us 24
return Bit;
}
void OneWire_SendByte(unsigned char Data)
{
unsigned char i;
for(i=0;i<8;i++)
{
OneWire_Write(Data&(0x01<<i));
}
}
unsigned char OneWire_ReadByte()
{
unsigned char i;
unsigned char Byte=0x00;
for(i=0;i<8;i++)
{
if(OneWire_Read()){Byte|=(0x01<<i);}
}
return Byte;
}
復(fù)制代碼
返回?cái)?shù)據(jù)的代碼
#include <REGX52.H>
#include "OneWire.h"
#include "LCD1602.h"
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 1;
j = 110;
do
{
while (--j);
} while (--i);
}
void DS18B20_ConvertT()
{
OneWire_Init();
Delay1ms();
OneWire_Write(0xCC);
OneWire_Write(0x44);
}
float DS18B20_Read()
{
unsigned char TLSB,TMSB;
int temp;
float T;
OneWire_Init();
Delay1ms();
OneWire_Write(0xCC);
OneWire_Write(0xBE);
TLSB=OneWire_ReadByte();
TMSB=OneWire_ReadByte();// 用的LCD1602顯示的數(shù)據(jù)
LCD_ShowNum(1,1,TMSB,8);//
LCD_ShowNum(1,9,TLSB,8);
temp=(TMSB<<8)|TLSB;
T=temp/16.0;
return T;
}
復(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