欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
DS18B20應(yīng)用,模數(shù)轉(zhuǎn)換顯示溫度
[打印本頁(yè)]
作者:
zny
時(shí)間:
2019-6-8 01:06
標(biāo)題:
DS18B20應(yīng)用,模數(shù)轉(zhuǎn)換顯示溫度
通過(guò)DS18B20的溫度檢測(cè),模數(shù)轉(zhuǎn)化顯示相對(duì)應(yīng)的溫度。
仿真圖,如圖所示。
轉(zhuǎn)換.png
(38.37 KB, 下載次數(shù): 79)
下載附件
2019-6-8 00:58 上傳
代碼源程序如下:
#include "reg51.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define out P0
sbit smg1=out^4;
sbit smg2=out^5;
sbit DQ=P3^7;
void delay5(uchar);
void init_ds18b20(void);
uchar readbyte(void);
void writebyte(uchar);
uchar retemp(void);
void main(void)
{
uchar i,temp;
delay5(1000);
while(1)
{
temp=retemp();
for(i=0;i<10;i++)
{
out=(temp/10)&0x0f;
smg1=0;
smg2=1;
delay5(1000);
out=(temp%10)&0x0f;
smg1=1;
smg2=0;
delay5(1000);
}
}
}
void delay5(uchar n)
{
do
{
_nop_();
_nop_();
_nop_();
n--;
}
while(n);
}
void init_ds18b20(void)
{
uchar x=0;
DQ =0;
delay5(120);
DQ =1;
delay5(16);
delay5(80);
}
uchar readbyte(void)
{
uchar i=0;
uchar date=0;
for (i=8;i>0;i--)
{
DQ =0;
delay5(3);
DQ =1;
date>>=1;
if(DQ)
date|=0x80;
delay5(11);
}
return(date);
}
void writebyte(uchar dat)
{
uchar i=0;
for(i=8;i>0;i--)
{
DQ =0;
DQ =dat&0x01;
delay5(12);
DQ = 1;
dat>>=1;
delay5(5);
}
}
uchar retemp(void)
{
uchar a,b,tt;
uint t;
init_ds18b20();
writebyte(0xCC);
writebyte(0x44);
init_ds18b20();
writebyte(0xCC);
writebyte(0xBE);
a=readbyte();
b=readbyte();
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
return(tt);
}
復(fù)制代碼
所有文件在下方,需要自取。
DS18B20應(yīng)用.zip
(83.46 KB, 下載次數(shù): 16)
2019-6-8 01:04 上傳
點(diǎn)擊文件名下載附件
模數(shù)轉(zhuǎn)換
下載積分: 黑幣 -5
作者:
Tumen233
時(shí)間:
2019-6-8 10:19
謝謝了 這個(gè)正好需要
作者:
xingmou2000
時(shí)間:
2019-6-8 12:12
我做的能顯示小數(shù)點(diǎn)后1位
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1