OneWire应用 单总线温度传感器DS18系列
OneWire DS18S20, DS18B20, DS1822 Temperature
DS18B20
The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. 分辨率9-12位,可设置报警,适用于1-Wire 总线,测量温度-55-125摄氏度
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems. 一个控制器可连接多个传感器,可应用于许多领域
FEATURES 特点
§ Unique 1-Wire Interface Requires Only One Port Pin for Communication
§ Each Device has a Unique 64-Bit Serial Code Stored in an On-Board ROM
§ Multidrop Capability Simplifies Distributed Temperature-Sensing Applications
§ Requires No External Components
§ Can Be Powered from Data Line; Power Supply Range is 3.0V to 5.5V
§ Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
§ ±0.5°C Accuracy from -10°C to +85°C
§ Thermometer Resolution is User Selectable from 9 to 12 Bits
§ Converts Temperature to 12-Bit Digital Word in 750ms (Max)

64-BIT LASERED ROM CODE 64位光刻ROM编码
Each DS18B20 contains a unique 64–bit code (see Figure 6) stored in ROM. The least significant 8 bits of the ROM code contain the DS18B20’s 1-Wire family code: 28h(8位家族编码). The next 48 bits contain a unique serial number(48位序列码). The most significant 8 bits contain a cyclic redundancy check (CRC) byte that is calculated from the first 56 bits of the ROM code(8位冗余检验码). A detailed explanation of the CRC bits is provided in the CRC Generation section. The 64-bit ROM code and associated ROM function control logic allow the DS18B20 to operate as a 1-Wire device using the protocol detailed in the 1-Wire Bus System section.
Figure 6. 64-Bit Lasered ROM Code
示例程序
1 #include <OneWire.h>
2
3
4
5 // OneWire DS18S20, DS18B20, DS1822 Temperature Example
6
7 //
8
9 // http://www.pjrc.com/teensy/td_libs_OneWire.html
10
11 //
12
13 // The DallasTemperature library can do all this work for you!
14
15 // http://milesburton.com/Dallas_Temperature_Control_Library
16
17
18
19 OneWire ds(10); // on pin 10,定义单总线设备ds,连接于10号引脚
20
21
22
23 void setup(void)
24
25 {
26
27 Serial.begin(9600);
28
29 }
30
31
32
33 void loop(void)
34
35 {
36
37 byte i;
38
39 byte present = 0;
40
41 byte type_s;
42
43 byte data[12];
44
45 byte addr[8]; //传感器的ROM,共8个字节的数据,64位
46
47 float celsius, fahrenheit;
48
49
50
51 if ( !ds.search(addr)) //查询不到ds就一直查询
52
53 {
54
55 Serial.println("No more addresses.");
56
57 Serial.println();
58
59 ds.reset_search();
60
61 delay(250);
62
63 return;
64
65 }
66
67
68
69 Serial.print("ROM ="); //查询到则显示ds的地址
70
71 for( i = 0; i < 8; i++)
72
73 {
74
75 Serial.write(' ');
76
77 Serial.print(addr[i], HEX);
78
79 }
80
81
82
83 if (OneWire::crc8(addr, 7) != addr[7]) // CRC检验失败的情况
84
85 {
86
87 Serial.println("CRC is not valid!");
88
89 return;
90
91 }
92
93 Serial.println();
94
95
96
97 // the first ROM byte indicates which chip ,根据addr[0]决定DS18系列的型号
98
99 switch (addr[0])
100
101 {
102
103 case 0x10:
104
105 Serial.println(" Chip = DS18S20"); // or old DS1820
106
107 type_s = 1;
108
109 break;
110
111 case 0x28: //0x28是DS18B20的家族编码
112
113 Serial.println(" Chip = DS18B20");
114
115 type_s = 0;
116
117 break;
118
119 case 0x22:
120
121 Serial.println(" Chip = DS1822");
122
123 type_s = 0;
124
125 break;
126
127 default:
128
129 Serial.println("Device is not a DS18x20 family device.");
130
131 return;
132
133 }
134
135
136
137 ds.reset(); //复位
138
139 ds.select(addr); // 选择设备
140
141 ds.write(0x44,1);
142
143 // start conversion, with parasite power on at the end,
144
145 //传感器内部温度变换保存在暂存器,0x44是传感器的协议编码
146
147
148
149 delay(1000); // maybe 750ms is enough, maybe not
150
151 // we might do a ds.depower() here, but the reset will take care of it.
152
153
154
155 present = ds.reset(); //返回1表示有设备存在
156
157 ds.select(addr);
158
159 ds.read(0xBE); // Read Scratchpad 读暂存器,0xBE是传感器的协议编码
160
161
162
163 Serial.print(" Data = ");
164
165 Serial.print(present,HEX);
166
167 Serial.print(" ");
168
169 for ( i = 0; i < 9; i++)
170
171 { // we need 9 bytes
172
173 data[i] = ds.read();
174
175 Serial.print(data[i], HEX);
176
177 Serial.print(" ");
178
179 }
180
181 Serial.print(" CRC=");
182
183 Serial.print(OneWire::crc8(data, 8), HEX);
184
185 Serial.println();
186
187
188
189 // convert the data to actual temperature
190
191
192
193 unsigned int raw = (data[1] << 8) | data[0];
194
195 if (type_s) //DS18S20对应的温度转换
196
197 {
198
199 raw = raw << 3; // 9 bit resolution default
200
201 if (data[7] == 0x10)
202
203 {
204
205 // count remain gives full 12 bit resolution
206
207 raw = (raw & 0xFFF0) + 12 - data[6];
208
209 }
210
211 }
212
213 else //DS18B20,DS1822对应的温度转换
214
215 {
216
217 byte cfg = (data[4] & 0x60);
218
219 if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
220
221 else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
222
223 else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
224
225 // default is 12 bit resolution, 750 ms conversion time
226
227 }
228
229 celsius = (float)raw / 16.0; //摄氏温度
230
231 fahrenheit = celsius * 1.8 + 32.0; //华氏温度
232
233 Serial.print(" Temperature = ");
234
235 Serial.print(celsius);
236
237 Serial.print(" Celsius, ");
238
239 Serial.print(fahrenheit);
240
241 Serial.println(" Fahrenheit");
242
243 }
OneWire应用 单总线温度传感器DS18系列的更多相关文章
- 【蓝桥杯单片机11】单总线温度传感器DS18B20的基本操作
[蓝桥杯单片机11]单总线温度传感器DS18B20的基本操作 广东职业技术学院 欧浩源 单总线数字温度传感器DS18B20几乎成了各类单片机甚至ARM实验板的标配模块来,在蓝桥杯的往届省赛和国赛中,这 ...
- 玩转X-CTR100 l STM32F4 l DS18B20单总线温度传感器
我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器 扩展DS1 ...
- EFM32JG系列MCU内部温度传感器使用方法
在很多电子类应用场合中,我们经常需要采集产品工作的周围环境温度,一般采取的方式有两种: 1)外加温度传感器 2)采用MCU内部温度传感器 外加温度传感器会增加产品的成本以及布板空间,所以在很多场合,我 ...
- 「雕爷学编程」Arduino动手做(39)——DS18B20温度传感器
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...
- Arduion学习(三)驱动温度传感器
一.实验目的: 1.将温度值打印显示在串口监视器 1.将温度值打印显示在串口,不同温度段显示不同的灯光,并在温度过高或过低时利用蜂鸣器报警. 二.实验准备: 1.查阅相关资料,了解本次实验所用到的引脚 ...
- 单片机学习(十二)1-Wire通信协议和DS18B20温度传感器
目录 一.DS18B20 1. DS18B20简介 2. 电路原理图 3. 内部结构 内部完整结构框图 存储器结构 二.单总线(1-Wire BUS) 1. 单总线简介 2. 电路规范 3. 单总线的 ...
- DS18B20温度传感器知识点总结
2018-01-1818:20:48 感觉自己最近有点凌乱,一个很简单的问题都能困扰自己很久.以前能很好使用和调试的DS18B20温度传感器,今天愣是搞了很久,妈卖批. 仅仅一个上拉电阻就困扰了我很久 ...
- Arduino入门笔记(6):温度传感器及感温杯实验
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino板 :https://item.taob ...
- 树莓派 Zero W+温度传感器DS18B20
树莓派 Zero W+温度传感器DS18B20 作者:陈拓chentuo@ms.xab.ac.cn 2018.05.28/2018.06.01 0. 概述 用树莓派 Zero W读取DS18B20温 ...
随机推荐
- windows-服务器-配置一个及多个-Apache-Tomcat
问题:如何在一台服务器上发布了几个Tomcat的系统???怎么配置环境变量?怎么设置Tomcat? 2020/8月更新,由于之前的java的环境变量有点绕,此次新加一个流程设计图 一.需求: 一台wi ...
- 6 vue-element.ui 左侧导航栏
<template> <div> <el-menu :default-active="'/'+activeIndex2" mode="ver ...
- 在Python程序中执行linux命令
import commands print commands.getstatusoutput('ls') 输出: (0, '1.py\nwork.nfs') 参考文档: https://blog.cs ...
- jackson序列化与反序列化的应用实践
jackson序列化与反序列化的应用实践 源码地址: https://github.com/zhouweixin/serializable 1 相关概念 序列化: 把对象转换为字节序列的过程称为对象的 ...
- adb命令装包failure问题
图片摘自CSDN,待验证
- [LeetCode]23. 合并K个排序链表(优先队列;分治待做)
题目 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6 ] 输出: 1 ...
- 程序员你是如何降低NPE的?
程序员,如果系统突然报了一个空指针异常,你肯定像吞了一只苍蝇一样尴尬. 那么如何在日常开发过程中降低NPE? 问题 回答 现状 返回空值会出现大量的空指针异常 目的 改进方法的返回值,降低出现空指针异 ...
- 在CentOS 7服务器中使用Jexus发布.net core webapi
环境: 服务器:CentOS 7 64位 .net core 2.1 Jexus独立版 官网:https://www.jexus.org/ 按照官网安装独立版命令:curl https://jexus ...
- Python3使用钉钉机器人推送消息(签名方式)
import time import hmac import hashlib import base64 import urllib import json import requests impor ...
- 关于java基础_方法的简单习题
package day05; import java.util.Arrays; /** * 方法作业 * @author ASUS * */ public class Demo6 { /* * 1.定 ...