DS18B10 (Programmable Resolution 1-Wire Digital Thermometer 可编程分辨率1线数字温度计)驱动理解

DS18B20驱动程序探索

前言

本文通过理解DS18B20的驱动程序,更好的理解DS18B20的功能,其中驱动程序为蓝桥杯官方提供的驱动,解释则通过摘录芯片手册中的内容。

DS18B20初始化方法

下面展示一些 内联代码片

#include "reg52.h"
sbit DQ = P1^4; // 单总线接口:单片机的P1.4端连接在DS18B20的DQ端

// DS18B20设备初始化
bit init_ds18b20(void)
{
  	bit initflag = 0; 
  	DQ = 1;
  	Delay_OneWire(12);
  	DQ = 0;
  	Delay_OneWire(80);
  	DQ = 1;
  	Delay_OneWire(10); 
    initflag = DQ;     
  	Delay_OneWire(5);
  
  	return initflag;
}

1. DQ为何物?

下图是DS1802不同型号的管脚排列:

DS18B10 (Programmable Resolution 1-Wire Digital Thermometer 可编程分辨率1线数字温度计)驱动理解
这里看到(DS18B20)的管脚图,由接地端GND,电源端VDD,和数字信号输入/输出端DQ三个端口组成。下面是芯片手册中的解释:
DS18B10 (Programmable Resolution 1-Wire Digital Thermometer 可编程分辨率1线数字温度计)驱动理解

2. DS18B20设备初始化流程:

//芯片手册的描述
INITIALIZATION PROCEDURE—RESET AND PRESENCE PULSES
All communication with the DS18B20 begins with an initialization sequence that consists of a reset pulse 
from the master followed by a presence pulse from the DS18B20. This is illustrated in Figure 13. When 
the DS18B20 sends the presence pulse in response to the reset, it is indicating to the master that it is on 
the bus and ready to operate. 
During the initialization sequence the bus master transmits (TX) the reset pulse by pulling the 1-Wire bus 
low for a minimum of 480µs. The bus master then releases the bus and goes into receive mode (RX). 
When the bus is released, the 5kΩ pullup resistor pulls the 1-Wire bus high. When the DS18B20 detects 
this rising edge, it waits 15µs to 60µs and then transmits a presence pulse by pulling the 1-Wire bus low 
for 60µs to 240µs.

DS18B10 (Programmable Resolution 1-Wire Digital Thermometer 可编程分辨率1线数字温度计)驱动理解

上一篇:控制信号(单脉冲信号)的跨时钟域传输问题


下一篇:视频流