資源簡(jiǎn)介
DS18B20初始化程序,能夠?qū)崿F(xiàn)DS18B20的初始化
代碼片段和文件信息
#include“Ds18b20_control.h“
uint?g_iTemFlag;???????//符號(hào)標(biāo)志位
/*==================================================================
*?Function :?DS18B20_Delay
*?Description :?DS18B20延時(shí)函數(shù)
*?Input?Para :延時(shí)控制數(shù)
*?Output?Para :?
*?Return?Value:?
==================================================================*/
void?DS18B20_Delay(uint?iNum)
{
??????while(iNum--);
}
/*==================================================================
*?Function :?DS18B20_Init
*?Description :?Ds18B20初始化
*?Input?Para :?
*?Output?Para :?
*?Return?Value:?
==================================================================*/
void?DS18B20_Init()
{
//???DQ=1;????????????????????//總線拉高
?DQ=0;????????????????????//總線拉低
?DS18B20_Delay(65);???????//延時(shí)在480us到960us
?DQ=1;
?DS18B20_Delay(15);???????//延時(shí)60~240us
}
/*==================================================================
*?Function :?DS18B20_DataWrit
*?Description :?DS18B20芯片寫數(shù)據(jù)函數(shù)
*?Input?Para :?輸入8位溫度數(shù)據(jù)
*?Output?Para :?
*?Return?Value:?
==================================================================*/
void?DS18B20_DataWrit(uint?cDat?)
{
?uint?i;
?for(i=0;i<8;i++)
?{
? ?DQ=0;
?????DQ=cDat&0x01;??????????//獲取溫度數(shù)一位狀態(tài)位
?DS18B20_Delay(4);?????????//延時(shí)45us
?DQ=1;
?cDat=cDat>>1;?????????????//數(shù)據(jù)位右移一位
?}
}
/*==================================================================
*?Function :?DS18B20_DataRead
*?Description :?DS18B20讀取數(shù)據(jù)
*?Input?Para :?
*?Output?Para :?
*?Return?Value:?返回8位溫度數(shù)據(jù)
==================================================================*/
uchar?DS18B20_DataRead()
{
?????uchar?cDat=0j=0;
?uint?i;
?for(
- 上一篇:視頻地址.zip
- 下一篇:U盤升級(jí)主版本和打補(bǔ)丁.txt
評(píng)論
共有 條評(píng)論