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-05-01
什么是触发器?触发器的作用是什么?
时间:2026-05-01
什么是电源?电源是如何进行分类的?
时间:2026-05-01
电驱动NVH的特点和结构
时间:2026-05-01
什么是霍尔传感器?
时间:2026-05-01
电负性的计算方法
时间:2026-04-30
电导的定义_电导的单位_电导怎么算
时间:2026-04-30
什么是计数器_计数器的作用
时间:2026-04-30
什么是欧姆定律_欧姆定律公式
时间:2026-04-30
RAID是什么?RAID有哪些?
时间:2026-04-30
电阻的原理和作用 电阻色环识别图 电路中电...
时间:2026-03-09
NVIDIA CPU+GPU超级芯片大升级!
时间:2026-03-09
什么是室温超导?半导体时代将走向结束?芯...
时间:2026-03-09
石英灯电子变压器电路原理
时间:2026-03-06
什么是硅片或者晶圆?一文了解半导体硅晶圆
时间:2026-03-09
半导体光刻工艺 光刻—半导体电路的绘制
时间:2026-03-09
一文详解MOS管驱动电路拓扑的设计
时间:2026-03-09
汽车芯片业应汲取的教训
时间:2026-03-09
压敏电阻型号的含义
时间:2026-03-05
半导体行业之ICT技术简介
时间:2026-03-09