《单片机毕业设计温度传感器设计.pdf》由会员分享,可在线阅读,更多相关《单片机毕业设计温度传感器设计.pdf(45页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、第 1 页 共 45 页引言随着“信息时代”的到来,作为获取信息的手段传感器技术得到了显著的进步,其应用领域越来越广泛,对其要求越来越高,需求越来越迫切。传感器技术已成为衡量一个国家科学技术发展水平的重要标志之一。因此,了解并掌握传感器的基本结构、工作原理及特性是非常重要的。为了提高对传感器的认识和了解,尤其是对温度传感器的深入研究以及其用法与用途,基于实用、广泛和典型的原则而设计了本系统。本文利用单片机结合传感器技术而开发设计了红外抄表系统。文中把传感器理论与单片机实际应用有机结合,详细地讲述了利用温度传感器DS18B20 测量环境温度,以及实现红外数据传输的过程。本设计应用性比较强,只要对
2、电路部分稍加改装,就可以实现抄读其它的数字仪表设备:如数字电度表,数字水表等等。设计后的系统具有操作方便,控制灵活等优点。其主要功能和指标如下:1、利用温度传感器(DS18B20)测量某一点环境温度;2、测量范围为 55 99,精度为 0.5;3、用 4 位数码管进行显示实际温度值显示;4、手持端通过红外发射管发射测温信号;5、测温端通过红外发射管发送到手持端;6、手持端可以随时查看指定待测物体的温度值。设计的核心是环境温度的测量以及红外数据的发射和接收,和温度的显示。文中对每个部分功能、实现过程作了详细地介绍。第 2 页 共 45 页1 方案选择该系统主要由温度测量和数据采集和发送三部分组成
3、。下面列举两种实现方案:方案一:温度检测可以使用低温热偶或铂电阻,数据采集部分则使用带有A/D通道的单片机。考虑到一般的A/D输入通道都只能接收大信号,所以还要设计相应的放大电路。而模拟信号在长距离传输过程中,抗电磁干扰是令人伤脑筋的问题。此方案的软件简单,但硬件复杂,且检测点数追加时,各敏感元件参数的不一致性,都将会导致误差的产生,难以完全清除,而且成本会有较大增长幅度。方案二:使用单片机和数字式单总线温度传感器构成。其具有下列特点:具有高的测量精度和分辨率,测量范围大;抗干扰能力强,稳定性好;信号易于处理、传送和自动控制;便于动态及多路测量,读数直观;安装方便,维护简单,工作可靠性高。单总
4、线温度传感器可以采用DALLAS 公司生产的 DS18B20系列,这类温度传感器直接输出数字信号,且多路温度传感器可以挂在1 条总线上,共同占用单片机的1 个 I/O口即可实现。在提升单片机I/O 口驱动能力的前提下,理论上可以任意扩充检测的温度点数。比较两个方案后可以发现,方案二更适合于用作本系统的实施方案。尽管方案二不需要 A/D,但考虑到系统扩充等因素,单片机可以选用AT98C2051。文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM
5、5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5
6、M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:
7、CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3
8、HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 Z
9、C5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编
10、码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D
11、3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5第 3 页 共 45 页2 硬件部分采用方案二的硬件设计比较简单,系统构成如图1 所示。图 1 温度测试系统和手持接收系统组成框图2.1 DS18B20 介绍DALLAS公司的DS18B20单总线数字传感器工作温度范围是-55 125,在-3085范围内温度测量精度为0.5;具有温度报警功能,用户可设置最高和最低报警温度,且设置值掉电不丢失;采用DALLAS公司特有的单总线通信协议,只用一条数据线就可实现与MCU 的通信;此外,DS18B20 能够直接从数据线获得
12、电源,无需外部电池供电。DS18B20 通过使用在板(on_board)温度测量专利技术来测量温度。其温度测量电路是通过计数时钟周期来实现的,DS18B20 有两个温度系数振荡器,温度测量时对高温度系数振荡器产生的门开同期内,低温度系数振荡器经历的时钟周期的个数进行计数而得到的。DS18B20 数字温度传感器提供9 位(二进制)温度读数,指示器件温度,所以无需A/D 转换。信息经过单线接口送入DS18B20 或从 DS18B20送出,因此从主机CPU到DS18B20 仅需一条线连接,而且 DS18B20 的电源可由数据线本身提供(相对于外部电源,转换时间要延长)。因此每一个DS18B20 在出
13、厂时已经给定了唯一的序号因此从理论上说任意多个DS18B20可以连接在一条单线总线上。DS18B20的测量范围从-55到DS18B20 数码管红外发射红外接收AT89C51 红外接收红外发射按键数码管AT89C51 文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B
14、8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5
15、文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1
16、M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q
17、5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8
18、A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10
19、K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5第 4 页 共 45 页AT89C51 DS18
20、B20+125,增量为 0.5(最高精度可达0.1),转换速度小于1s(典型值)。而在本遥测系统中采用外部电源供电温度测量工作方式,其中电阻R是上拉电阻,使得单线总线的空闲状态是高电平。它与CPU(AT89C51)的接法如图 2。5 V R 地图 2 DS18B20 与单片机的连接由于 DS18B20 只有一根数据线。因此它和主机(单片机)通信是需要串行通信,而AT89C51有两个串行端口,所以可以不用软件来模拟实现。经过单线接口访问DC18B20必须遵循如下协议:初始化、ROM 操作命令、存储器操作命令和控制操作。要使传感器工作,一切处理均从序列开始。主机发送(Tx)-复位脉冲(最短为480
21、s 的低电平信号)。接着主机便释放此线并进入接收方式(Rx)。总线经过 4.7K 的上拉电阻被拉至高电平状态。在检测到I/O引脚上的上升沿之后,DS18B20 等待 15-60s,并且接着发送脉冲(60-240s 的低电平信号)。然后以存在复位脉冲表示DS18B20 已经准备好发送或接收,然后给出正确的 ROM命令和存储操作命令的数据。DS18B20 通过使用时间片来读出和写入数据,时间片用于处理数据位和进行何种指定操作的命令。它有写时间片和读时间片两种。写时间片:当主机把数据线从逻辑高电平拉至逻辑低电平时,产生写时间片。有两种类型的写时间片:写1 时间片和写 0 时间片。所有时间片必须有60
22、 微秒的持续期,在各写周期之间必须有最短为1 微秒的恢复时间。读时间片:从 DS18B20 读数据时,使用读时间片。当主机把数据线从逻辑高电平拉至逻辑低电平时产生读时间片。数据线在逻辑低电平必须保持至少1 微秒;来自 DS18B20的输出数据在时间下降沿之后的15 微秒内有效。为了读出从读时间片开始算起15 微秒的状态,主机必须停止把引脚驱动拉至低电平。在时间片结束时,I/O 引脚经过外部的上拉电阻拉回高电平,所有读时间片的最短持续期为60 微秒,包括两个读周期间至少1s 的恢复时间。一旦主机检测到 DS18B20 的存在,它便可以发送一个器件ROM 操作命令。所有 ROM文档编码:CH4E1
23、0K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9
24、D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y
25、5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4
26、E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5
27、C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M
28、9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:C
29、H4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5第 5 页 共 45 页操作命令均为 8 位长。DS18B20 的引脚定义和封装形式如图3 所示。DQ为数字信号输入/输出端;GND 为电源地;VDD 为外接电源。DS18B20 的光刻 ROM 中存有 64位序列号,它可以看作是该DS18B20 的地址序列码。64 位光刻 ROM
30、的排列是:开始 8 位(28H)是产品类型标号,接着的48 位是该 DS18B20自身的序列号,最后 8 位是前面 56 位的循环冗余校验码(CRC=X8+X5+X4+1)。光刻 ROM的作用是使每一个DS18B20 拥有惟一的地址序列码,以确保在一根总线上挂接多个DS18B20。所有的串行通讯,读写每一个bit位数据都必须严格遵守器件的时序逻辑来编程,同时还必须遵守总线命令序列,对单总线的DS18B20 芯片来说,访问每个器件都要遵守下列命令序列:首先是初始化;其次执行 ROM 命令;最后就是执行功能命令(ROM 命令和功能命令后面以表格形式给出)。如果出现序列混乱,则单总线器件不会响应主机
31、。当然,搜索ROM 命令和报警搜索命令,在执行两者中任何一条命令之后,要返回初始化。基于单总线上的所有传输过程都是以初始化开始的,初始化过程由主机发出的复位脉冲和从机响应的应答脉冲组成。应答脉冲使主机知道,总线上有从机,且准备就绪。在主机检测到应答脉冲后,就可以发出ROM 命令。这些命令与各个从机设备的唯一64 位 ROM 代码相关。在主机发出 ROM 命令,以访问某个指定的DS18B20,接着就可以发出 DS18B20 支持的某个功能命令。这些命令允许主机写入或读出DS18B20 便笺式 RAM、启动温度转换。软件实现DS18B20 的工作严格遵守单总线协议:(1)主机首先发出一个复位脉冲,
32、信号线上的DS18B20 器件被复位。(2)接着主机发送 ROM 命令,程序开始读取单个在线的芯片ROM 编码并保存在单片机数据存储器中,把用到的 DS18B20 的 ROM 编码离线读出,最后用一个二维数组保存ROM编码,数据保存在X25043中。(3)系统工作时,把读取了编码的DS18B20 挂在总线上。发温度转换命令,再总线复位。(4)然后就可以从刚才的二维数组匹配在线的温度传感器,随后发温度读取命令就可以获得对应的温度值了。在主机初始化过程,主机通过拉低单总线至少480us,来产生复位脉冲。接着,主机释放总线,并进入接收模式。当总线被释放后,上拉电阻将单总线拉高。在单总线器件检测到上升
33、沿后,延时1560us,接着通过拉低总线60-240us,以产生应答脉冲。写时序均起始于主机拉低总线,产生写1 时序的方式:主机在拉低总线后,接着必须在 15us 之内释放总线。产生写0 时序的方式:在主机拉低总线后,只需在整个时序期间保持低电平即可(至少 60us)。在写字节程序中的写一个bit 位的时候,没有按照通常的分别写0 时序和写 1时序,文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文
34、档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M
35、7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5
36、B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A
37、5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K
38、1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6
39、Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U
40、8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5第 6 页 共 45 页而是把两者结合起来,当主机拉低总线后在15us 之内将要写的位c 给 DO:如果 c 是高电平满足 15us 内释放总线的要求,如果c 是低电平,则 DO c 这条语句仍然是把总线拉在低电平,最后都通过延时58us 完成一个写时序(写时序0 或写时序 1)过程。每个读时隙都由主机发起,至少拉低总线1us,在主机发起读时序之后,单总线器件才开始在总线上发送0 或 1。所有读时序至少需要60us。单片机通过命令实现对DS18B20 的控制,其支持的主要命令如表1 所示。表 1 DS18B
41、20 主要命令及其功能说明命令码功能说明命令码功能说明33H 读 ROM 中的 64 位地址序列码BEH 读 9 字节暂存寄存器55H 只有地址码匹配的DS18B2才能接收后续的命令4EH 写入温度上/下限,紧随其后是 2 字节数据,对应上限和下限值F0H 锁定总线上DS18B20的个数和识别其 ROM 中的 64 位地址序列码48H 将 9 字节暂存寄存器的第3 和4 字节复制到EEPROM 中ECH 只有温度超过上限或下限的DS18B20才做出响应B8H 将 EEPROM 的内容恢复到暂存寄存器的第3 和 4 字节44H 启动 DS18B20进行温度转换,结果存入9 字节的暂存寄存器B4H
42、 读 供 电 模 式,寄 生 供 电 时DS18B20 发送0,外接电源时DS18B20发送 1 CCH 忽略地址序列码,适合单片DS18B20 2.2 单片机的选择(1)AT89C51 的特性及引脚说明主要特性与MCS-51 兼容4K字节可编程闪烁存储器寿命:1000写/擦循环数据保留时间:10年全静态工作:0Hz-24Hz 三级程序存储器锁定文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编
43、码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D
44、3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8
45、 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文
46、档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M
47、7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5
48、B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A
49、5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5第 7 页 共 45 页128*8位内部 RAM 32可编程 I/O 线两个 16位定时器/计数器5个中断源可编程串行通道低功耗的闲置和掉电模式片内振荡器和时钟电路AT89C51 的引脚功能,图 4所示:图 4 AT89C51 的引脚功能图管脚说明VCC:供电电压。GND:接地。P0口:P0口为一个 8位漏级开路双向 I/O 口,每个管脚可吸收 8TTL门电流。当 P1口的管脚写“1”时,被定义为高阻输入。P0能够用于外部程序数据存储器,它可以被定义为数据/地址的第八位。在 FLASH 编程时,P0口作为原码输
50、入口,当 FLASH 进行校验时,P0输出原码,此时 P0外部电位必须被拉高。P1口:P1口是一个内部提供上拉电阻的8位双向 I/O 口,P1口缓冲器能接收输出4TTL门电流。P1口管脚写入“1”后,电位被内部上拉为高,可用作输入,P1口被外部文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M7D3 HM5C9D6Q5B8 ZC5M9Y5U8A5文档编码:CH4E10K1M