欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
單片機測量溫度DS18B20 LCD1602顯示
[打印本頁]
作者:
花Q花Q
時間:
2019-6-16 11:35
標(biāo)題:
單片機測量溫度DS18B20 LCD1602顯示
最常用的溫度傳感器 上至128° 下至-55°
//數(shù)字式溫度計
#include
<reg51.h>
#include
<intrins.h>
#define
uchar
unsigned char
#define
uint
unsigned int
sbit LED = P3^
0
;
//滅掉一顆LED
int
temp;
int
wendu;
uchar data
disdata
[
5
];
//定義開關(guān)入口
sbit DQ = P1^
7
;
//DS18B20的接入口
sbit lcden=P2^
1
;
sbit lcdrs=P2^
0
;
sbit LED1=P3^
0
;
sbit LED2=P3^
7
;
//聲明區(qū)
void
write_com
(uchar
com
);
void
delay
(
uint
);
//定義區(qū)
void
delay
(
uint
i
)
{
while
(i--);
}
void
delay_1
(
int
z
)
{
int
x,y;
for
(x=
0
;x<z;x++)
for
(y=
0
;y<
122
;y++);
}
//液晶函數(shù)
void
init
()
{
lcden=
0
;
write_com
(
0x38
);
//設(shè)置顯示模式為5*7八位數(shù)據(jù)接口
write_com
(
0x0c
);
//開顯示,顯示光標(biāo)光標(biāo)不閃爍
write_com
(
0x06
);
//光標(biāo)指針自動加1
write_com
(
0x01
);
//清屏
write_com
(
0x80
+
2
);
//顯示數(shù)據(jù)的地址
}
void
write_com
(uchar
com
)
{
lcdrs=
0
;
P0=com;
delay_1
(
10
);
lcden=
1
;
delay_1
(
10
);
lcden=
0
;
}
void
write_data
(uchar
date
)
{
lcdrs=
1
;
P0=date;
delay_1
(
10
);
lcden=
1
;
delay_1
(
10
);
lcden=
0
;
}
//以上為液晶要用到的函數(shù)
//ds18b20溫度傳感器所需函數(shù),分為初始化 讀字節(jié) 寫字節(jié) 讀取溫度4個函數(shù)
void
Init_DS18B20
()
//初始化
{
uchar x=
0
;
DQ=
1
;
_nop_
();
_nop_
();
DQ=
0
;
delay
(
70
);
DQ=
1
;
delay
(
15
);
x=DQ;
delay
(
35
);
}
uchar
Read_OneChar
()
//讀一個字節(jié)
{
uchar i;
uchar temp=
0
;
for
(i=
0
;i<
8
;i++)
{
DQ=
1
;
_nop_
();
DQ=
0
;
_nop_
();
_nop_
();
DQ=
1
;
_nop_
();
temp>>=
1
;
if
(DQ)
temp|=
0x80
;
delay
(
60
);
}
return
(temp);
}
void
Write_OneChar
(uchar
dat
)
//寫一個字節(jié)
{
uchar i;
for
(i=
0
;i<
8
;i++)
{
DQ=
0
;
_nop_
();
DQ=dat&
0x01
;
delay
(
10
);
DQ=
1
;
dat>>=
1
;
}
}
int
ReadTemp1
()
//讀取溫度
{
uchar Temp1L=
0
;
uchar Temp1H=
0
;
int
t;
Init_DS18B20
();
Write_OneChar
(
0xCC
);
Write_OneChar
(
0x44
);
delay
(
250
);
LED =
0
;
Init_DS18B20
();
Write_OneChar
(
0xCC
);
Write_OneChar
(
0xBE
);
Temp1L=
Read_OneChar
();
Temp1H=
Read_OneChar
();
if
(Temp1H&
0xF0
)
//顯示負(fù)數(shù)
{
Temp1L=~Temp1L;
Temp1H=~Temp1H;
t=(Temp1H*
256
+Temp1L)/
16
*(-
1
)-
1
;
}
else
t=(Temp1H*
256
+Temp1L)*
0.0625
;
return
(t);
}
void
display
()
{
wendu=
ReadTemp1
();
delay
(
100
);
if
(wendu<
0
)
{
wendu=-wendu;
disdata
[
0
]=
'-'
;
}
else
disdata
[
0
]=wendu/
1000
+
0x30
;
//百位數(shù)
disdata
[
1
]=wendu%
1000
/
100
+
0x30
;
//十位數(shù)
disdata
[
2
]=wendu%
100
/
10
+
0x30
;
//個位數(shù)
disdata
[
3
]=wendu%
10
+
0x30
;
//小數(shù)位
write_com
(
0xc2
);
write_data
(
disdata
[
0
]);
write_com
(
0xc3
);
write_data
(
disdata
[
1
]);
write_com
(
0xc4
);
write_data
(
disdata
[
2
]);
write_com
(
0xc5
);
write_data
(
disdata
[
3
]);
}
void
main
()
{
init
();
while
(
1
)
{
ReadTemp1
();
display
();
delay
(
800
);
}
}
DS18B20仿真.png
(194.19 KB, 下載次數(shù): 61)
下載附件
2019-6-16 11:34 上傳
作者:
3022488273wcl
時間:
2020-5-25 06:35
特別感謝作者
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1