欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
ds18b20單總線驅動程序 CT107單片機綜合實訓平臺 8051 12MHz
[打印本頁]
作者:
469730443
時間:
2018-6-21 07:25
標題:
ds18b20單總線驅動程序 CT107單片機綜合實訓平臺 8051 12MHz
單片機源程序如下:
/*
程序說明: 單總線驅動程序
軟件環境: Keil uVision 4.10
硬件環境: CT107單片機綜合實訓平臺 8051 12MHz
日 期: 2011-8-9
*/
#include "reg52.h"
#include "ds18b20.h"
#include "intrins.h"
sbit DQ = P2^0; //單總線接口
//單總線延時函數
void Delay_OneWire(unsigned int t)
{
// unsigned char i;
while(t--){
// for(i=0; i<12; i++);
}
}
//通過單總線向DS18B20寫一個字節
void Write_DS18B20(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
DQ = 0;
DQ = dat&0x01;
Delay_OneWire(5);
DQ = 1;
dat >>= 1;
}
Delay_OneWire(5);
}
//從DS18B20讀取一個字節
unsigned char Read_DS18B20(void)
{
unsigned char i;
unsigned char dat;
for(i=0;i<8;i++)
{
DQ = 0;
dat >>= 1;
DQ = 1;
if(DQ)
{
dat |= 0x80;
}
Delay_OneWire(5);
}
return dat;
}
//DS18B20設備初始化
bit init_ds18b20(void)
{
bit initflag = 0;
DQ = 1;
Delay_OneWire(12);
DQ = 0;
Delay_OneWire(80);
DQ = 1;
Delay_OneWire(10);
initflag = DQ;
Delay_OneWire(5);
return initflag;
}
unsigned char Tempget()
{
unsigned char temp,low,high;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay_OneWire(200);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
low=Read_DS18B20();
high=Read_DS18B20();
temp=high<<4;
temp|=(low>>4);
return temp;
}
復制代碼
所有資料51hei提供下載:
18b20時序.zip
(1.1 KB, 下載次數: 5)
2018-6-21 07:24 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1