DS18B20是常用的数字温度传感器,具有体积小,硬件开销低,抗干扰能力强,精度高的特点。主要根据应用场合的不同而改变其外观。封装后的DS18B20可用于电缆沟测温,高炉水循环测温,锅炉测温,机房测温,农业大棚测温,洁净室测温,弹药库测温等各种非极限温度场合。耐磨耐碰,体积小,使用方便,封装形式多样,适用于各种狭小空间设备数字测温和控制领域。
51单片机是对所有兼容Intel 8031指令系统的单片机的统称。该系列单片机的始祖是Intel的8004单片机,后来随着Flash rom技术的发展,8004单片机取得了长足的进展,成为应用最广泛的8位单片机之一,其代表型号是ATMEL公司的AT89系列,它广泛应用于工业测控系统之中。很多公司都有51系列的兼容机型推出,今后很长的一段时间内将占有大量市场。51单片机是基础入门的一个单片机,还是应用最广泛的一种。需要注意的是51系列的单片机一般不具备自编程能力。接下来我们一起来了解一下ds18b20温度测量c51单片机程序。
#include《reg51.h》
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
sbit DS=P2^2;
uchar A;
uint dian;
uchar smg_change[6]={10,10,10,10,10,10};
unsigned char code duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delay(unsigned int a)
{
while(a--);
}
void init_tempr()
{
uchar n;
DS=1;
delay(8);
DS=0;
delay(80); //500us
DS=1;
delay(8);
n=DS;
delay(4);
}
void write_byte(uchar dat)
{
uchar i;
for(i=0;i《8;i++)
{
DS=0;
DS=dat&0x01;
delay(4);
DS=1;
dat》》=1;
}
delay(4);
}
uchar read_byte(void)
{
uchar i,value;
for(i=0;i《8;i++)
{
DS=0;
value》》=1;
DS=1;
if(DS)
value|=0x80;
delay(4);
}
return value;
}
uchar readtempr(void)
{
uint temp, a,b;
init_tempr();
write_byte(0xcc);
write_byte(0x44);
delay(300);
init_tempr();
write_byte(0xcc);
write_byte(0xbe);
a=read_byte();
b=read_byte();
temp=b;
temp《《=4;
temp+=(a&0xf0)》》4;
dian=(a&0x0f)*10*6/10;
return temp;
}
void display()
{
uchar i;
for(i=0;i《6;i++)
{
P0=0X00;
dula=1;
dula=0;
P0=weima[i];
wela=1;
wela=0;
P0=duanma[smg_change[i]];
dula=1;
dula=0;
delay(200);
}
P0=weima[1];
wela=1;
wela=0;
P0=duanma[smg_change[1]]|0x80;
dula=1;
dula=0;
delay(200);
P0=0X00;
dula=1;
dula=0;
}
void dis_deal()
{
smg_change[0]=A/10;
smg_change[1]= A%10;
smg_change[2]=dian/10 ;
smg_change[3]=dian%10 ;
}
void main()
{
while(1)
{
A=readtempr();
dis_deal();
display();
}
}
什么是感应电机?什么是无刷电机?二者有何区...
时间:2026-10-23
多核DSP的多路同步时钟信号设计
时间:2026-10-23
什么是lcd12864?lcd12864的特性及其应用举例
时间:2026-10-23
IoT无线连接基础知识
时间:2026-10-23
光是一种电磁波,那么光的频率是多少?
时间:2026-10-22
DRAM简介
时间:2026-10-22
电容耦合是什么意思呀?
时间:2026-10-22
什么是单总线
时间:2026-10-21
STM32的CAN总线通信实现
时间:2026-10-21
什么是电源管理?有什么作用
时间:2026-10-20
电阻的单位
时间:2026-03-05
NVIDIA CPU+GPU超级芯片大升级!
时间:2026-03-09
贴片电阻怎么看阻值
时间:2026-03-05
电阻的原理和作用 电阻色环识别图 电路中电...
时间:2026-03-09
什么是室温超导?半导体时代将走向结束?芯...
时间:2026-03-09
HTCC:半导体封装的理想方式
时间:2026-03-06
什么是硅片或者晶圆?一文了解半导体硅晶圆
时间:2026-03-09
一文详解MOS管驱动电路拓扑的设计
时间:2026-03-09
半导体光刻工艺 光刻—半导体电路的绘制
时间:2026-03-09
半导体行业之ICT技术简介
时间:2026-03-09