基于单片机的粮仓温湿度控制系统设计毕业设计


    







    题 目 基单片机粮仓温湿度控制系统设计
    学生姓名 学号
    学院 物理电信工程学院
    专业班级 电子信息工程专业级班
    指导教师
    完成点



    2016年6月5日




    基单片机粮仓温湿度控制系统设计

    (XX学院 物理电信工程学院 电子信息工程专业12级班)
    指导老师:

    [摘] 影响粮食安全储存参数粮仓温度湿度粮仓温湿度测量方法相应智控制直粮食储存重问题设计采STC89C52单片机系统检测报警显示调控等模块进行点控制传统温湿度控制利温度计湿度表湿度试纸等测试器材通工进行检测符合温湿度求库房进行通风降温湿等操作种方法费时费力效率低机性误差时解决问题设计通动检测时报警动调控等功解决设计仅针粮仓譬蔬菜棚花圃实验室医院等需温湿度检测控制领域适
    [关键词] 粮仓温湿度点检测控制单片机 


    Design of temperature and humidity control system for granany based on single chip microcomputer

    Author:
    Tutor

    Abstract Grain is a necessity for human the grain storage is very essential to the maintenance of social stability and keep the economy sustainable developmented And the main  parameters to the grain safe storage is the temperature and humidity  This design uses the STC89C52 system of single chip microcomputer to cotrol the modules about the detection alarm control and the key And it could automatic measurement and control without people and improve effciency and quality of work very well DHT11 temperature and humidity sensors and OLED display shows real time data and pass to the staff with instant and accurate While the traditional temperature and humidity control is use of Thermometer humidity table humidity dipstick test equipment Through the artificial testing Not in conformity with the requirements of the temperature and humidity supply cooling ventilation to wet operation This artificial testing timeconsuming the efficiency is low This design is by automatic detection instant alarm automatic regulation of functions such as a good solution to these problems At last this design not only against the granary but also for most such as vegetable greenhouses flowers garden laboratories hospitals could also be applicabled
    Keywords Granary automatic detection and control temperature and humidity Singlechip






    目录
    1引言 1
    11 背景意义 1
    12现状发展趋势 1
    13研究容 1
    2系统总体方案设计 2
    21设计求 2
    22系统基方案 2
    221传感器方案 2
    222显示器方案 2
    223单片机芯片方案 2
    23总体设计框图 3
    3系统硬件设计 4
    31控模块 4
    311 STC89C52芯片 4
    312 STC89C52芯片脚引线功 4
    313 控模块电路原理图 5
    32温湿度检测模块 6
    321 DHT11传感器简介 6
    322 DHT11传感器模块电路 7
    33显示模块 8
    331 OLED显示屏简介 8
    34报警模块 9
    341蜂鸣器介绍 9
    342蜂鸣器工作原理 9
    35温湿度调控模块 9
    351继电器 9
    352 温湿度调控模块 10
    4系统软件设计 11
    41程序设计 11
    42传感器模块设计 12
    43 软件调试 12
    5系统安装调试 14
    6结展 17
    致谢 18
    参考文献 19
    附录A英文文献 20
    附录B中文译文 25
    附录C系统原理图 28
    附录D实物图 29
    附录E元器件清单 30
    附录F C语言程序 31


    1 引言
    11 背景意义
    粮食储存国家针战争饥荒突发事件做预防准备粮食储存安全关重目前国部分区种型粮仓存程度粮食变质问题国家粮食保护法必须定期检查粮仓点温湿度便时采取相应措施许粮仓目前采取工检测方法仅粮仓工作员工作量增工作效率低尤型粮仓温度检测务时彻底完成会造成粮食面积变质关资料统计国年粮食变质损失粮食达数亿斤直接造成巨济损失
    影响粮食安全储藏参数粮仓温度湿度粮食正常储藏程中果粮食受潮会导致发芽新陈代谢加快产生呼吸热粮食温度突然升高引起粮食霉变造成许挽回损失研究设计单片机控制核心基数字温度湿度传感器动检测系统粮库粮仓中点位温度湿度变化情况进行实时动测试旦出现异常现象便时处理效提高事预见性工作效率着重实际推广价值理研究意义
    12 现状发展趋势
    早期粮情监测采温湿度计测量法根验放粮仓测温点理员定期读数确定粮仓温湿度高低决定否进行调控种方法储粮定作温湿度计精度工读数时误差等素影响检测时仅效率低精度差局部温湿度高易时发现导致局部粮食发霉变质引起面积坏粮情况时发生
    年着单片机日益成熟计算机广泛应粮食测控系统准确性求越越高寻找测控系统配置佳性价成前热门研究容外国粮仓情况监测技术已达非常成熟步监测系统中广泛应高科技数字式传感器种半导体集成电路微控制器等新技术核心传感器心集成半导体温度监测芯信号转换芯接口芯片储存芯片等仅完成检测外完成预设范围温度报警功数字温度传感器直接传出数字信号解决长距离传输问题传输程中干扰衰减导致精度降低等问题会解决影响粮仓温湿度检测技术重素传感器技术发展
    13研究容
    设计STC89C52型单片机作系统硬件核心具线编程功功耗低等特点检测部分采四组DHT11温湿度传感器时反应粮仓四监控点温度湿度变化反馈单片机单片机处理控制相应继电器工作完成诸升温特定温度降温特定温度湿度控制方面










    2 系统总体方案设计
    21 设计求
    (1)设计出粮仓温湿度控制系统总体方案设想智项目设计结构规划
    (2)硬件设计:实现粮仓温湿度采集控制单片机控制器扩展必外部电路设计制作控制系统
    (3)软件设计:项功设计流程
    (4)发挥部分:点分布式
    22 系统基方案
    221 传感器方案
    方案:选DS18B20温度传感器作温度检测模块DS18B20线式数字温度传感器具独特单线式接口方式测量范围—10℃~85℃误差范围\+05℃高精度达00625℃选HS1101湿度传感器作湿度检测模块HS1101电容式湿度传感器测量相湿度范围0~100RH误差\+2RH
    方案二: 选DHT11作设计温湿度检测模块DHT11款集成型数字温湿度体传感器
    应专温湿度传感技术数字模块采集技术具高性长期稳定性电阻式感湿元件NTC测温元件传感器基组成部分该产品品质优良响应速度快抗干扰力强性价极高测量范围20~90RH0℃~50℃测温精度\+2℃测湿精度\+5RH完全符合次毕业设计求
    述分析方案然精度更精确稍显复杂方案二便实现方案高精度测量满足设计求简便易行稳定具超高性价选择方案二
    222 显示器方案
    方案:采12864 OLED屏显示模块128×64点阵汉字图形型OLED显示模块显示汉字图形置8192中文汉字(16X16点阵)128字符(8X16点阵)64X256点阵显示RAM(GDRAM)CPU直接接口
    方案二:采HJ1602液晶显示屏HJ1602A 种工业字符型液晶够时显示16x02 32字符(16列2行)1602显示字母数字符号显示16*2字符寄存器止32显示效果字符显示字符左右右左显示等等显示效果简单
    总结:编程方面两者难度差异较OLED屏幕略复杂相1602液晶屏OLED 12864占单片机脚少屏幕亮度高显示更加清晰显示容更更形象具体实现显示功
    223 单片机芯片方案
    方案:AT89C51美国ATMEL公司生产低电压高性CMOS型8位单片机器件采ATMEL公司高密度非易失性存储技术生产兼容标准MCS51指令系统片置通8位中央处理器(CPU)Flash存储单元功强片4K程序存储器FLASH工艺种单片机开发设备求低开发时间缩短写入单片机程序进行加密保护劳动成果者AT89C51目前售价8031低市场供应充足AT89C51构成真正单片机应系统缩系统体积增加系统性降低系统成程序长度4K四IO口全部提供户5V电压编程擦写时间仅需lOms[1]
    方案二:STC89C52STC公司生产功耗低性高CMOS8位微控制器具 8K编程Flash存储器STC89C52MCS51核做提高芯片具传统51单片机具备功芯片拥8位CPU编程FlashSTC89C52嵌入式控制系统提供灵活效解决方案具标准功:8k字节Flash512字节RAM门狗定时器32位IO 口线置4KB EEPROMMAX810复位电路316位定时器计数器2外部中断全双工串行口外STC89C52降0Hz静态逻辑操作 支持2种软件选择节电模式空闲模式CPU停止工作允许RAM定时器计数器串口中断继续工作断电保护模式RAM容保存冻结振荡器单片机工作停止直中断硬件复位高运作频率35MHz6T12T选[2]载程序方面直接串口载STC89C51系列单片机指令系统AT89C51系列完全兼容实际操作AT89C51系列许优点:
    (1)AT89C51带ISP载载器行STC89C52USB转串口载载软件免费载源充足
    (2)STC单片机执行指令速度快约AT330倍需调试STC时注意加长延时约AT10—30倍
    (3)STC单片机工作环境求较低电压低5伏时然正常工作甚3伏4伏间工作样环境AT法工作
    (4)STC单片机EA\VPP 端口默认悬空高电需添加VCC
    较两种方案基STC89C52单片机相简便市面STC单片机量货源充足选择方案二作控模块核心[3]
    23 总体设计框图







    STC89C52
    控模块
    综方案述:采STC89C52作控制系统12M晶振提供时钟信号IIC通信OLED 12864显示屏作显示部分独立键进行控制系统工作条件设定蜂鸣器作报警发声系统图21示
    温度控制模块
    湿度控制模块





    温湿度检测模块(DHT11)




    显示模块
    (OLED12864)
    时钟模块
    (12M晶振)






    报警模块(蜂鸣器)
    键模块





    图 21 基单片机粮仓温湿度控制系统框图

    3 系统硬件设计
    31 控模块
    311 STC89C52芯片
    STC89C52STC公司生产功耗低性高CMOS8位微控制器具 8K编程Flash存储器STC89C52MCS51核做提高芯片具传统51单片机具备功[4]STC89C52具列性:
    ⑴ 增强型8051单片机6 时钟机械周期12 时钟机械周期供选择代码指令完兼容般8051
    ⑵ 工作电压:55V~33V(5V 单片机)38V~20V(3V 单片机)
    ⑶ 频率范围:0~40 MHz相普通8051 0~80 MHz实际工作频率达48 MHz 
    ⑷ 应程序写入空间8K字节
    ⑸ 片集成512 字节RAM
    ⑹ 通IO 口(32)复位:P0P1P2P3 准双口弱拉 P0口开路输出总线扩展时需加拉电阻作 IO 口时需 加 拉 电 阻
    ⑺ ISPIAP 需 专 编 程 器 需 专  仿 真 器通串口(RxDP30TxDP31)直 接 载 户 程 序数秒完成片 
    ⑻ 具EEPROM 功 
    ⑼ 具   门 狗 功  
    ⑽ 316位定时器定时器T0T1T2
    ⑾ 外部中断2路 降 中 断 低 电 触发低电触发中断方式唤醒Power Down 模式
    ⑿ 通 异 步 串 行 口(UART) 定 时 器  软 件 实 现 UART
    ⒀ 工作温度范围:40~+85℃(工业级)0~75℃(商业级)
    ⒁ PDIP封装
    312 STC89C52芯片脚引线功
    (1)STC89C52脚图31示



















    图31 STC89C52单片机脚图
    (2)脚功
    VCC:接+5V电源正端
    GND 接+5V电源端
    P0口:P00P07统称P0口接片外存储器扩展IO口时作准双IO口接片外存储器扩展IO口时P0口分时复低8位址总线双数总线[4]
    P1口:P1口8位双IO口部提供拉电阻P1口缓器接受输出4TTL门电流P1口脚写入1时部拉高输入拉电阻缘P1口拉低电时输出电流[5]
    P10P11第二功:P10作定时计数器2计数脉输入端T2P11作定时计数器2外部控制端T2EX
    P2口:P20P27统称P2口般作准双IO口接片外寄存器扩展IO 口寻址范围超256B时P2口作高8位址总线
    P3口:P30P37统称P3口部带拉电阻8位双IO口作准双IO口外P3口具第二功P3口条引脚均独立定义第功输入输出第二功[6]
    RST复位输出引脚该引脚保持两周期高电C51处初始化(复位)工作状态
    EAVPP片外存储器访问允许信号低电效EA保持低电期间否部程序存储器外部程序存储器(0000HFFFFH)工作注意:加密位LB1编程时EA部锁定RESETEA端保持高电期间部程序存储器工作第二功VPPEPROM编程电源输入
    ALE址锁存效信号输出端访问片外程序存储器期间ALE机器周期两次进行信号输出降控制锁存P0输出低8位址访问片外程序寄存器期间ALE端诉频率出现作外输出时钟脉定时目注意访问片外数寄存器期间ALE脉会跳空时作时钟输出
    PSEN:该引脚低电时片外程序存储器选通片外程序存储器取指期间机器周期PSEN两次效访问片外数存储器时两次效PSEN信号会出现
    XTAL1:反震荡放器输入部时钟工作电路输入( 外接振荡器时引脚接振荡器信号)
    XTAL2:反振荡器输出(外接振荡器时引脚悬浮)[7]
    P3口第二功表31示

    表31 P3端口特殊功
    端口引脚 兼功
    P30 RXD (串行口输入端)
    P31 TXD (串行口输出端)
    P32 (外部中断0请求输入端低电效)
    P33 (外部中断1请求输入端低电效)
    P34 T0 (定时计数器0计数脉输入端)
    P35 T1 (定时计数器1计数脉输入端)
    P36 (外部数存储器写选通信号输出端低电效)
    P37 (外部数存储器读选通信号输出端低电效)
    313 控模块电路原理图
    单片机程序模块通DHT11传感器采集信号读取数信号进行分析处理处理信号发送1602液晶显示模块完成信息接收发送连接蜂鸣器控制报警系统图32示


    图32 STC89C52模块电路原理图
    32 温湿度检测模块
    321 DHT11传感器简介
    DHT11传感器种校准输出数字信号温湿度传感器采数字式模块采集温湿度传感技术具非常高性长期稳定性传感器电阻式感湿元件NTC测温元件组成该产品品质卓越响应速度快抗干扰力强性价极高[8]DHT11传感器非常严格校验室中进行校验校验系数通程序方式存储OTP存中传感器部检测处理信号时需调校验系数采单线制串行接口系统集成快捷简单体积功耗低信号传输距离较长成类应场合极佳选产品 4 针单排引脚封装连接方便特殊封装形式根户需求提供
    DHT11传感器实物图图33示:












    图33 DHT11传感器实物图
    (1)引脚介绍:
    Pin1:(VDD)电源引脚供电电压3~55VPin2:(DATA)串行数单总线
    Pin3(NC)空脚请悬浮Pin4(VDD)接端电源负极
    (2)接口说明 :
    建议连接线长度短20米时5K拉电阻20米时根实际情况合适拉电阻
    DHT11应电路图34示


    图34 DHT11典型应电路
    (3)数帧描述:
    DATA 单片机 DHT11间步通信采单总线数格式次通信时间4ms左右通信数会分数整数部分操作流程
    次完整数传输40bit先出高位数格式8bit湿度整数数8bit湿度数数加8bi温度整数数8bit温度数数数传输正确时校验数等8bit湿度整数数+8bit湿度数数+8bi温度整数数+8bit温度数数结果末8位
    例:接受40bit数:
    0000 0010 1000 1100 0000 0001 0101 1111 1110 1110
    湿度数 温度数 校验
    0000 0010 + 1000 1100 + 0000 0001 + 0101 1111 1110 1110
    湿度652RH 温度351℃
    温度低0℃时温度数高位置1
    例:101℃表示1000 0000 0110 0101
    (4)电气特性:VDD5VT 25℃非特殊标注表32示
    表32 DHT11电气特性
    参数
    条件
    Min
    Typ
    max
    单位
    供电
    供电电流
    采样周期
    DC
    测量



    3
    05
    02
    100
    1
    5
    55
    25
    1
    150
    V
    mA
    mA
    uA

    注采样周期间隔低1秒钟
    322 DHT11传感器模块电路
    DHT11传感器连接STC89C51系列单片机相较简单单片机P20口发收串行数数口连接传感器Pin2(单总线串行数)测量范围电路20米建议加5K拉电阻传感器Pin2口电源间连接5K电阻传感器电源端口Pin1Pin4分接单片机VDDGND端传感器第三脚悬浮放置DHT11传感器原件电路图图35示:

    图35 DHT11电路图
    33显示模块
    331 OLED显示屏简介
    OLED种机发光二极发光需背光源屏幕度高厚度较薄视角度广快响应速度环境温度范围较该屏特点:
    ⑴ 096寸 OLED 黄蓝白蓝三种颜色选中黄蓝屏 14 部分黄光 34 蓝固定区域显示固定颜色颜色显示区域均修改白光纯白黑底白字蓝色纯蓝黑底蓝字
    ⑵ 分辨率 128*64
    ⑶ 种接口方式OLED 裸屏总种接口包括:68008080 两种行接口方式3 线 4 线串行 SPI 接口方式 IIC 接口方式(需 2 根线控制 OLED ) 五种接口通屏 BS0~BS2 配置
    ⑷两种接口 Demo 板接口分七针 SPIIIC 兼容模块四针IIC 模块
    图36示IIC四针OLED屏幕















    图 36 OLED屏正面反面
    IIC OLED引脚说明表33
    表33 IIC OLED 12864 显示屏脚说明
    脚名称 脚说明
    GND 电源
    VCC 电源正(3~55V)
    SCL OLED D0 脚 IIC 通信中时钟脚
    SDA OLED D1 脚 IIC 通信中数脚
    34报警模块
    341蜂鸣器介绍
    蜂鸣器体化结构电子式讯响器直流电压供电广泛应电话机报警器复印机计算机印机汽车电子设备定时器等产品中作发声器[9] 分电磁式蜂鸣器压电式蜂鸣器两种类型
    342蜂鸣器工作原理
    图38示蜂鸣器工作原理图

    图38 蜂鸣器工作原理图
    单片机IO口驱动力够蜂鸣器发出声音通三极放驱动电流蜂鸣器发出声音果程序控制单片机输出高电三极导通集电极电流通蜂鸣器蜂鸣器发出声音输出低电时三极截止没电流流蜂鸣器蜂鸣器会发出声音[10]
    35 温湿度调控模块
    351继电器
    电磁式继电器般铁芯线圈衔铁触点等组成设计五角继电器直流输入2830V输入电流10A图395角继电器实物图图310原理图







    图39 五角继电器实物图






    图310 五角继电器原理图
    45两端加相应电压时线圈会电流产生电磁效应衔铁会磁力吸引作克服弹簧拉力吸铁芯带动衔铁动触点2点吸合线圈断电电磁吸力消失衔铁会弹簧反作力返回3点1点原3点吸合样吸合释放达开关目[11]
    352 温湿度调控模块
    图310位温湿度调控模块原理图







    图310 温湿度调控模块原理图
    单片机IO口输出高电时通三极放集电极电流通45点电磁圈产生磁场会1点单刀双掷开关吸引3点常开点导通实现继电器功外部电器P1开始正常工作单片机IO口输出低电时三极截止45点电磁圈没电流会产生磁场1点开关身弹性形变弹回2点常闭点









    4 系统软件设计
    41程序设计
    设计硬件部分做认识需建立程序框架流程图整设计划分软件模块逐模块实现功终子模块合理连接起构成总程序程序首先整系统进行初始化然采集温湿度指令传系统流程图图41示:

    开始


    初始化



    延时


    温湿度检测



    显示屏显示



    温度高限
    Y


    N
    温度低限
    蜂鸣器报警
    应继电器工作


    N
    Y
    蜂鸣器报警
    应继电器工作





    湿度高限
    Y

    蜂鸣器报警
    应继电器工作

    湿度低限
    N

    N
    Y
    蜂鸣器报警
    应继电器工作




    图 41 程序流程图
    42 传感器模块设计
    DHT11传感器模块软件流程图图42示

    DHT11电



    延时1S
     


    保持高电



    检测记录信号




    输出低电




    延时



    输出低电



    数输出






    图42 DHT11传感器模块程序流程图
    43 软件调试
    设计Keil C环境开发Keil C软件支持C语言编程调试运方便做C语言单片机设计首选[12]设计首务安装学软件简单学解Keil C便环境开始设计需软件程序进行设计工作编译完Keil C运STC_ISP_V480软件烧录开发板实现实物程序连接[13]
    烧录前STC_ISP_V480进行必设置第步:设置MCU TypeSTC89C52RC第二步:开编写编译程序文件hex缀文件第三步:选择应COM端口电脑设备理处查COM选项第四步:点击Download载等提示请MCU电时开开发板开关行烧录[14]
    Keil C程序运行图4344示

    图43 keil C运行图

    图44 程序烧录运行图
    完成程序调试烧录烧洗单片机放入硬件电路板中进行软硬件组合调试







    5 系统安装调试
    51 硬件安装
    硬件部分通万板电路焊接部分拼接起组成控制模块报警模块显示模块键模块调控模块
    焊接程中器件较前期设计块万板已满足元器件排布选择加入第二块万板进行焊接工作焊接程中导线细容易断裂导致整体线路接触良常出现短路断路等问题复查中量更换前焊接细线换较粗漆包线作导线仅线路稳定性提升较粗导线提供定固定作整体线路更加稳固布局设计缺陷次设计OLED 显示屏幕引脚短需加装块排母电路板连接屏幕固定导致会出现接触良情况加粗排母引脚该问题较解决设计功需点检测4组检测模块直接焊接电路板采杜邦线连接检测模块电路板排针进行连接解决检测模块分开分布问题焊接继电器电路时元器件短缺需2K电阻缺失测试决定双4K电阻联接入电路达样效果缺点占电路板空间
    图51硬件外观图

    图51 硬件外观图
    图51中A键进入温湿度设定界面B键进行温度湿度切换CD键分加减图中数字显示屏旁12344DHT11温湿度检测模块图中标号相调控模块应监测点温湿度调控端
    52 组合调试
    调试分硬件调试软件调试硬件调试检测硬件电路否短路断路虚焊等显示电路键盘电路继电器调控电路次设计硬件电路搭接实物前检查器件性否符合求导线否导通器件否性完等通编制调试程序分相应硬件单元电路功进行检查次进行软件调试先验证子程序正确性子程序连接起进行整体调试逐渐发现错误改正错误进行软硬件结合调试检查硬件电路软件编程否匹配进行软硬件结合调试发现诸问题:
    ⑴硬件检查中单片机系统复位键存连焊情况导致键短路法
    ⑵电路板电源模块双面板漏锡电源模块短路继电器调控模块中继电器出口端模拟电器未加入电源电路导致继电器工作电器正常工作
    重新调整电路问题解决
    基础部件组合调试完成开始进行系统功终调试调试程中发现检测数超预设限数报警模块调控模块开始工作存调控模块全部工作时电路板会出现跳闸断电情况硬件电路程序程进行次检查调整试验发现电路板电源输入线热导致输入VCC稳定引起电路板跳闸更换材质更电源连线该问题解决
    组合调试系统设计功正常工作设计安装调试结束
    图52系统正常工作时屏幕显示状态

    图52 正常工作屏显状态
    温度超设定值时报警模块调控模块开始工作蜂鸣器报警相应继电器工作风扇工作模拟降温红色二极发光指示图53示1234号检测端温度超限应风扇全部工作

    图53 温度控制工作
    湿度超设定值时报警模块调控模块开始工作蜂鸣器报警相应继电器工作加热片工作模拟湿黄色二极发光指示图54示1234号检测端湿度超限应加热片全部工作

    图54湿度控制工作
    温湿度超设定值时报警模块调控模块开始工作蜂鸣器长鸣报警相应继电器工作风扇工作模拟降温加热片工作模拟湿二极发光指示图55示

    图55 温湿度控制时工作
    6 结展
    次验证调试设计完成
    系统单片机核心部件利软件编程终实现设计求然系统存足温湿度测量够精确特湿度波动误差较尝试种改进方法然太理想反映出设计目求预期结果相差
    两月奋斗确定题目查找资料理学实验编程调试切理知识动手力提高解单片机硬件结构软件编程方法单片机工作方式认知时外围设备传感器显示屏键盘蜂鸣器继电器等定解学会项工程应该设计:首先分析需设计系统实现什功需什器件然针设计购买相应硬件选硬件时仅选济更重更精确更方便完成系统求次硬件驱动软件实现弄清楚更实现硬件协调更通控制器件实现硬件功通种测试调试设计更完成系统求
    水限次设计中存定足例湿度控制方面温度时刻发生着变化湿度变化体取决温度湿度控制点困难时湿度变化波动较造成报警频繁湿度限值设定带麻烦
    粮仓温湿度控制已成21世纪热门研究话题智化控制温湿度已发展成种必然着世界济发展生活水提高社会进步直墨守陈规恪守前利力资源控制温湿度方法仅浪费量力资源财力资源控制系统相单化采动控制办法节省力资源更体现时俱进思想世界进步种进步该体现方面




















    致 谢
    毕业期两月毕业设计程中收获许感悟许
    首先非常感谢院领导毕业生毕业设计程中支持帮助次特感谢XX老师选题阶段设计阶段制作阶段予指导帮助老师忙教学科研务重然抽出时间定期召集组学指导督促找家存问题加解决帅老师提供丰富学资源良学环境毕业设计带方便完成毕业设计程中提供指导性意见明确完成设计帅老师严谨问题求严格正样毕业生毕设态度转变衷心感谢帅老师予帮助教育感谢学编写调试程遇困难时正学帮助利克服困难毕业设计完成离开学帮助真诚感谢
    总学老师学校次毕业设计程中受帮助启发没毕业设计坚持感谢受益匪浅

























    参考文献
    [1] 陈明荧8051单片机课程设计实训教材[M] 北京:清华学出版社2003.
    [2] 徐新艳单片机原理应实践[M] 北京:高等教育出版社2005.
    [3] 吴金戌沈庆阳郭庭吉8051单片机实践应[M] 北京:清华学出版社2002
    [4] 张毅刚MCS51单片机应设计[M] 哈尔滨工业学出版社2004
    [5] 冯博琴微型计算机原理接口技术[M] 北京:清华学出版社2004
    [6] 张毅刚MCS51单片机应设计[M] 哈尔滨工业学出版社2004
    [7] 张淑清姜万录等单片微型计算机接口技术应[M] 国防工业出版社2003
    [8] 吴金戌沈庆阳郭庭吉8051单片机实践应[M] 北京:清华学出版社2001
    [9] 冯博琴微型计算机原理接口技术[M] 清华学出版社2004
    [10] 王振红李洋郝承祥ISD4004语音芯片工作原理智控制系统中应[J] 电子器件200225(1)
    [11] 王千实电子电路全[M] 电子工业出版社2001
    [12] 赵亮侯国锐单片机C语言编程实例[M] 北京民邮电出版社2003
    [13] RLGeigerPEAllenNRStraderVLSIDesign Techniques for Analog And Digitial CiruitsMcGrawHill Inc1990
    [14] ANALOG DEVICESThe technology of AT89C51[EBOL]White PaperSpe282000
    [15] VK Gryzhov VGKorol’kovEVGryzhov ADAkshinskyFlexible Converter of Analog Signal into Discrete Digital One with the Example of Double Integration Voltmeter [J]Automation and Remote Control201475(4)




















    附录 A 英文文献
    Temperature Control Using a Microcontroller
    An Interdisciplinary Undergraduate Engineering Design Project
    James S McDonald
    Department of Engineering Science
    Trinity University
    San Antonio TX 78212
    Abstract
    This paper describes an interdisciplinary design project which was done under the author’s supervision by a group of four senior students in the Department of Engineering Science at Trinity University The objective of the project was to develop a temperature control system for an airfilled chamber The system was to allow entry of a desired chamber temperature in a prescribed range and to exhibit overshoot and steadystate temperature error of less than 1 degree Kelvin in the actual chamber temperature step response The details of the design developed by this group of students based on a Motorola MC68HC05 family microcontroller are described The pedagogical value of the problem is also discussed through a description of some of the key steps in the design process It is shown that the solution requires broad knowledge drawn from several engineering disciplines including electrical mechanical and control systems engineering
    1 Introduction
    The design project which is the subject of this paper originated from a realworld application A prototype of a microscope slide dryer had been developed around an OmegaTM model CN390 temperature controller and the objective was to develop a custom temperature control system to replace the Omega system The motivation was that a custom controller targeted specifically for the application should be able to achieve the same functionality at a much lower cost as the Omega system is unnecessarily versatile and equipped to handle a wide variety of applications
    The mechanical layout of the slide dryer prototype is shown in Figure 1 The main element of the dryer is a large insulated airfilled chamber in which microscope slides each with a tissue sample encased in paraffin can be set on caddies In order that the paraffin maintain the proper consistency the temperature in the slide chamber must be maintained at a desired (constant) temperature A second chamber (the electronics enclosure) houses a resistive heater and the temperature controller and a fan mounted on the end of the dryer blows air across the heater carrying heat into the slide chamber This design project was carried out during academic year 1996–97 by four students under the author’s supervision as a Senior Design project in the Department of Engineering Science at Trinity University
    The purpose of this paper is to describe the problem and the students’ solution in some detail and to discuss some of the pedagogical opportunities offered by an interdisciplinary design project of this type The students’ own report was presented at the 1997 National Conference on Undergraduate Research [1] Section 2 gives a more detailed statement of the problem including performance specifications and Section 3 describes the students’ design Section 4 makes up the bulk of the paper and discusses in some detail several aspects of the design process which offer unique pedagogical opportunities Finally Section 5 offers some conclusions
    2 Problem Statement
    The basic idea of the project is to replace the relevant parts of the functionality of an Omega CN390 temperature controller using a customdesigned system The application dictates that temperature settings are usually kept constant for long periods of time but it’s nonetheless important that step changes be tracked in a reasonable manner Thus the main requirements boil down to
    ·allowing a chamber temperature setpoint to be entered
    ·displaying both setpoint and actual temperatures and
    ·tracking step changes in setpoint temperature with acceptable rise time steadystate error and overshoot Although not explicitly a part of the specifications in Table 1 it was clear that the customer desired digital displays of setpoint and actual temperatures and that setpoint temperature entry should be digital as well (as opposed to say through a potentiometer setting)
    3 System Design
    The requirements for digital temperature displays and setpoint entry alone are enough to dictate that a microcontrollerbased design is likely the most appropriate Figure 2 shows a block diagram of the students’ design
    The microcontroller a MotorolaMC68HC705B16 (6805 for short) is the heart of the system It accepts inputs from a simple fourkey keypad which allow specification of the setpoint temperature and it displays both setpoint and measured chamber temperatures using twodigit sevensegment LED displays controlled by a display driver All these inputs and outputs are accommodated by parallel ports on the 6805 Chamber temperature is sensed using a precalibrated thermistor and input via one of the 6805’s analogtodigital inputs Finally a pulsewidth modulation (PWM) output on the 6805 is used to drive a relay which switches line power to the resistive heater off and on
    Figure 3 shows a more detailed schematic of the electronics and their interfacing to the 6805 The keypad a Storm 3K041103 has four keys which are interfaced to pins PA0{ PA3 of Port A configured as inputs One key functions as a mode switch Two modes are supported set mode and run mode In set mode two of the other keys are used to specify the setpoint temperature one increments it and one decrements The fourth key is unused at present The LED displays are driven by a Harris Semiconductor ICM7212 display driver interfaced to pins PB0{PB6 of Port B configured as outputs The temperaturesensing thermistor drives through a voltage divider pin AN0 (one of eight analog inputs) Finally pin PLMA (one of two PWM outputs) drives the heater relay
    Software on the 6805 implements the temperature control algorithm maintains the temperature displays and alters the setpoint in response to keypad inputs Because it is not complete at this writing software will not be discussed in detail in this paper The control algorithm in particular has not been determined but it is likely to be a simple proportional controller and certainly not more complex than a PID Some control design issues will be discussed in Section 4 however
    4 The Design Process
    Although essentially the project is just to build a thermostat it presents many nice pedagogical opportunities The knowledge and experience base of a senior engineering undergraduate are just enough to bring him or her to the brink of a solution to various aspects of the problem Yet in each case realworld considerations complicate the situation significantly
    Fortunately these complications are not insurmountable and the result is a very beneficial design experience The remainder of this section looks at a few aspects of the problem which present the type of learning opportunity just described Section 41 discusses some of the features of a simplified mathematical model of the thermal properties of the system and how it can be easily validated experimentally Section 42 describes how realistic control algorithm designs can be arrived at using introductory concepts in control design Section 43 points out some important deficiencies of such a simplified modelingcontrol design process and how they can be overcome through simulation Finally Section 44 gives an overview of some of the microcontrollerrelated design issues which arise and learning opportunities offered
    41 MathematicalModel
    Lumpedelement thermal systems are described in almost any introductory linear control systems text and just this sort of model is applicable to the slide dryer problem Figure 4 shows a secondorder lumpedelement thermal model of the slide dryer The state variables are the temperatures Ta of the air in the box and Tb of the box itself The inputs to the system are the power output q(t) of the heater and the ambient temperature T¥ ma and mb are the masses of the air and the box respectively and Ca and Cb their specific heats μ1 and μ2 are heat transfer coefficients from the air to the box and from the box to the external world respectively
    It’s not hard to show that the (linearized) state equationscorresponding to Figure 4 Taking Laplace transforms of (1) and (2) and solving for Ta(s) which is the output of interest gives the following openloop model of the thermal system
    where K is a constant and D(s) is a secondorder polynomialK tz and the coefficients of D(s) are functions of the variousparameters appearing in (1) and (2)Of course the various parameters in (1) and (2) are completely unknown but it’s not hard to show that regardless of their values D(s) has two real zeros Therefore the main transfer function of interest (which is the one from Q(s) since we’ll assume constant ambient temperature) can be writtenMoreover it’s not too hard to show that 1tp1 <1tz <1tp2 ie that the zero lies between the two poles Both of these are excellent exercises for the student and the result is the openloop polezero diagram of Figure 5
    Obtaining a complete thermal model then is reduced to identifying the constant K and the three unknown time constants in (3) Four unknown parameters is quite a few but simple experiments show that 1tp1 _ 1tz1tp2 so that tztp2 _ 0 are good approximations Thus the openloop system is essentially firstorder and can therefore be written where the subscript p1 has been dropped
    Simple openloop step response experiments show thatfor a wide range of initial temperatures and heat inputs K _014 _W and t _ 295 s1
    42 Control System Design
    Using the firstorder model of (4) for the openloop transfer function Gaq(s) and assuming for the moment that linear control of the heater power output q(t) is possible the block diagram of Figure 6 represents the closedloop system Td(s) is the desired or setpoint temperatureC(s) is the compensator transfer function and Q(s) is the heater output in watts
    Given this simple situation introductory linear control design tools such as the root locus method can be used to arrive at a C(s) which meets the step response requirements on rise time steadystate error and overshoot specified in Table 1 The upshot of course is that a proportional controller with sufficient gain can meet all specifications Overshoot is impossible and increasing gains decreases both steadystate error and rise time
    Unfortunately sufficient gain to meet the specifications may require larger heat outputs than the heater is capable of producing This was indeed the case for this system and the result is that the rise time specification cannot be met It is quite revealing to the student how useful such an oversimplified model carefully arrived at can be in determining overall performance limitations
    43 Simulation Model
    Gross performance and its limitations can be determined using the simplified model of Figure 6 but there are a number of other aspects of the closedloop system whose effects on performance are not so simply modeled Chief among these are
    ·quantization error in analogtodigital conversion of the measured temperature and
    · the use of PWM to control the heater
    Both of these are nonlinear and timevarying effects and the only practical way to study them is through simulation (or experiment of course)
    Figure 7 shows a SimulinkTM block diagram of the closedloop system which incorporates these effects AD converter quantization and saturation are modeled using standard Simulink quantizer and saturation blocks Modeling PWM is more complicated and requires a custom Sfunction to represent it
    This simulation model has proven particularly useful in gauging the effects of varying the basic PWM parameters and hence selecting them appropriately (Ie the longer the period the larger the temperature error PWM introduces On the other hand a long period is desirable to avoid excessive relay chatter among other things) PWM is often difficult for students to grasp and the simulation model allows an exploration of its operation and effects which is quite revealing
    44 The Microcontroller
    Simple closedloop control keypad reading and display control are some of the classic applications of microcontrollers and this project incorporates all three It is therefore an excellent allaround exercise in microcontroller applications In addition because the project is to produce an actual packaged prototype it won’t do to use a simple evaluation board with the IO pins jumpered to the target system Instead it’s necessary to develop a complete embedded application This entails the choice of an appropriate part from the broad range offered in a typical microcontroller family and learning to use a fairly sophisticated development environment Finally a custom printedcircuit board for the microcontroller and peripherals must be designed and fabricated
    Microcontroller Selection In view of existing local expertise the Motorola line of microcontrollers was chosen for this project Still this does not narrow the choice down much A fairly disciplined study of system requirements is necessary to specify which microcontroller out of scores of variants is required for the job This is difficult for students as they generally lack the experience and intuition needed as well as the perseverance to wade through manufacturers’ selection guides
    Part of the problem is in choosing methods for interfacing the various peripherals (eg what kind of display driver should be used) A study of relevant Motorola application notes [2 3 4] proved very helpful in understandingwhat basic approaches are available and what microcontrollerperipheral combinations should be considered
    The MC68HC705B16 was finally chosen on the basis of its availableAD inputs and PWMoutputs as well as 24 digital IO lines In retrospect this is probably overkill as only one AD channel one PWM channel and 11 IO pins are actually required (see Figure 3) The decision was made to err on the safe side because a complete development system specific to the chosen part was necessary and the project budget did not permit a second such system to be purchased should the first
    prove inadequate
    Microcontroller Application Development Breadboarding of the peripheral hardware development of microcontroller software and final debugging and testing of a custom printedcircuit board for the microcontroller and peripherals all require a development environment of some kind The choice of a development environment like that of the microcontroller itself can be bewildering and requires some faculty expertise Motorola makes three grades of development environment ranging from simple evaluation boards (at around 100) to fullblown realtime incircuit emulators (at more like 7500) The middle option was chosen for this project the MMEVS which consists of _ a platform board (which supports all 6805family parts) _ an emulator module (specific to Bseries parts) and _ a cable and target head adapter (packagespecific) Overall the system costs about 900 and provides with some limitations incircuit emulation capability It also comes with the simple but sufficient software development environment RAPID [5]
    Students find learning to use this type of system challenging but the experience they gain in realworld microcontroller application development greatly exceeds the typical firstcourse experience using simple evaluation boards
    PrintedCircuit Board The layout of a simple (though definitely not trivial) printedcircuit board is another practical learning opportunity presented by this project The final board layout with package outlines is shown (at 50 of actual size) in Figure 8 The relative simplicity of the circuit makes manual placement and routing practical—in fact it likely gives better results than automatic in an application like this—and the student is therefore exposed to fundamental issues of printedcircuit layout and basic design rules The layout software used was the very nice package pcb2 and the board was fabricated inhouse with the aid of our staff electronics technician
    5 Conclusion
    The aim of this paper has been to describe an interdisciplinary undergraduate engineering design project a microcontroller based temperature control system with digital setpoint entry and setpointactual temperature display A particular design of such a system has been described and a number of design issues which arise—from a variety of engineering disciplines—have been discussed Resolution of these issues generally requires knowledge beyond that acquired in introductory courses but realistically accessible to advance undergraduate students especially with the advice and supervision of faculty
    Desirable features of the problem from a pedagogical viewpoint include the use of a microcontroller with simple peripherals the opportunity to usefully apply introductorylevel modeling of physical systems and design of closedloop controls and the need for relatively simple experimentation (for model validation) and simulation (for detailed performance prediction) Also desirable are some of the technologyrelated aspects of the problem including practical use of resistive heaters and temperature sensors (requiring knowledge of PWM and calibration techniques respectively) microcontroller selection and use of development systems and printedcircuit design
    Acknowledgements
    The author would like to acknowledge the hard work dedication and ability shown by the students involved in this project Mark Langsdorf Matt Rall PamRinehart and David Schuchmann It is their project and credit for its success belongs to them




















    附录 B 中文译文
    单片机温度控制:跨学科科生工程设计项目
    JamesSMcDonald
    工程科学系三学德克萨斯州
    圣安东尼奥市78212

    文描述作者领导四三学高年级学生组成团队进行跨学科工程项目设计该项目目标设计气室温度控制系统该系统求:实际气室温度阶跃响应时规定范围温度进入气室稳定时温度误差超调量必须少绝温度组学生开发设计基摩托罗拉MC68HC05系列单片机该问题教学价值通某步骤关键描述文说明研究结果表明解决该方案需具广泛工程学科知识包括相关电子机械控制系统工程知识
    1 引言
    该设计项目实际应问题关显微镜载玻片干燥剂温控器——欧米茄CN390温度控制器设计目标研发定义通温度控制系统取代欧米茄系统更低成实现相功定义控制器欧米茄系统样需够全方位处理种问题
    该载玻片干燥机机械布局图1示干燥机体足够绝缘充气室里面次存放着薄纸包着石蜡石蜡保持适稳定性载玻片气室温度必须维持稳定第二气筒(电子围绕元件)设电阻加热器温度控制器安装干燥机风扇风吹加热器热量带载玻片气室
    199697学年文作者带领四位三学工程科学系高年级学生开展项目研究文目说明提出问题详细阐述学生解决方案讨种类型跨学科设计项目教学方面应问题份学生报告1997年全国科毕业生研讨会提出讨第2节出该设计更详细情况包括性规格第3节具体 学生设计第4节文体讨该设计教学应方面实施问题第5节全文总结
    2 问题阐述
    该项目基思想设计定义温度控制系统取代相关欧米茄CN390温度控制器温度时通常保持稳定常数重阶跃变化合理踪求:
    ·空气室温度进行设定
    ·时显示设定值实际温度
    ·设定温度值情况接受范围踪阶跃变化稳态误差超调量
    表1部分说明明确清楚反映数字显示器设定值实际温度求温度应该通数值输入设定(通电位器设置)
    3系统设计
    根微控设计数字温度显示单点输入求合适图2学生设计框图
    摩托罗拉MC68HC705B16(简称6805)系统核心通简单4键键盘温度进行设定时两显示驱动控制7段LED数码显示定值气室温度测量值输入输出信号6805行口相连气室温度值预校准热敏电阻测量通6805数模转换输入6085脉宽度调制(PWM)输出驱动继电器控制线性电阻加热器闭合断开
    图3更详细显示6805接口电子器件暴风3K041103型号四键键盘通PA0PA3端口进行数输入中重功进行模式切换两种模式:固定模式运行模式固定模式两键设定温度增加减少第四键暂作LED显示屏哈里斯半导体ICM7212进行驱动通PB0PB6端口芯片相连作输出热敏电阻电压分频器驱动通AN0针脚(八模拟输入端口中)相连PLMA针脚(两PWM输出端口中)驱动加热继电器
    单片机原理图关软件实现温度控制算法保持温度显示改变键盘输入响应会文详细讨文重点没编译完成软件部分没确定控制算法简单例控制PID算法简单控制设计问题第四节讨
    4 设计程
    然该项目质建立恒温器许契机供教学鉴高级工程科教育知识够学生具解决问题力然情况实际情况理问题参项目设计获设计方面宝贵验节余部分着眼方面:41节讨系统特征简化系统热性数学模型简单理证明42节介绍确定实际控制算法43节指出控制设计程序足通模拟环境指出样克服问题44节出单片机设计相关概述出现问题值鉴处
    41数学模型
    集总元件热系统符合线性控制适载玻片干燥机问题图4显示二阶集总元件热量模型载玻片干燥机状态变量温度Ta箱空气温度Tb箱子身温度该系统输入功率等q(t)热量环境温度Tmamb分应空气箱子质量
    CaCb分应热量m1m2分空气箱子间箱子外界间传热系数
    拉普拉斯变换(1)(2)等式整理Ta(s)趣推出开环热系统方程
    中K常数D(s)二阶项式Ktz系数D(s)(1)(2)等式中出现系数功相然(1)(2)等式中种参数未知情况难证明D(s)参数值关具两零点传递函数写成(假设环境温度常数)
    外推出1tp1<1tz<1tp2零点两极间开环零极点图5示
    获取完整热模型(3)式中常数K3未知时间常数四未知参数少简单实验表明1tp1<<1tz1tp2统基阶函数tztp2似0
    初始温度热量值范围设置简单开环阶跃响应实验结果表明K≈014oWτ≈295S
    42 控制系统设计
    (4)式阶开环传递函数Gaq(s)假定加热器输出函数q(t)线性图6系统框图代表闭环系统Td(s)设定温度函数C(s)传递函数Q(s)热量输出单位瓦特
    图6简化闭环系统框图鉴种简单情况前面指线性控制设置例根轨迹法设计法C(s)中符合求阶跃响应应升时间稳态误差超调量符合表格1示然足够增益例控制器满足种求超调量改变增加增益减少稳态误差升时间幸果获足够增益需生产超实际生产力容量加热器系统实际问题会致升时间符合求求学生利仔细计算简化模型整体性达佳控制
    43 模型仿真
    该设计部分性限制功应该图6简化模型完成数闭环系统方面影响非够简单仿真中:
    ·量化误差模拟数模转换
    ·测量温度PWM控制加热器
    两种非线性时变唯切实行方法通仿真(实验)加研究
    图7Simulink仿真闭环系统框图显示Simulink情况闭环系统框图中包括AD转换标准Simulink量化饱块建立饱量化模型建立PWM调制模型较复杂需定义S函数表示
    种仿真模型已证明衡量PWM基参数设计影响适参数选择中特(时间越长PWM调制会产生更温度误差方面时间越长继电器抖动机率越)PWM调制方法难学生掌握仿真模型允许研究测试运行明显影响
    44单片机
    简单闭环控制键盘输入显示控制典单片机应技术设计项目包含述三方面优秀全面单片机应练
    外该项目源现实会简单输入输出设计完成相反项目需制定完整嵌入式应需量单片机型号中选取适芯片学着相复杂开发环境必须设计选取印刷电路板单片机外接元件
    单片机选择
    现实际验常选摩托罗拉公司单片机芯片选择应该局限研究表明系统求符合工作需求单片机学生困难缺乏良验判断力通制造商产品选择指南决定单片机选择部分问题种外围设备(例应该种显示驱动程序?)连接方法选择摩托罗拉相关应研究[234]中证明非常基阐述实性连接方法单片机外围连接组合方式终求基础选择MC68HC705B16现AD输入PWM输出24数字IO线样选择必项目需AD通道PWM通道11IO引脚(见图3)该决定安全方面选择完整开发系统必该项目预算中没足够资金次购买元件
    单片机应开发
    外围设备电路硬件软件开发终调试单片机定印刷电路板外设需某种形式发展环境
    单片机身开发环境选择令困惑需教师专业知识摩托罗拉三级发展环境包括简单评估板(约100美元)全面实时线仿真器(约7500元)中间选项选项目MMEVS中包括:
    ·台板(支持6805family部分)
    · 模拟器模块(具体B系列部分)
    · 电缆头目标适配器(简明包装)
    学生发现学类系统挑战现实世界微控制器应获验超第典型简单评估板验
    印刷电路板
    简单(然布局绝)印刷电路板工程提供现实学机会图8显示板布局包轮廓(50实际)相简单电路手工安置路实践方面更实际提供更结果样应程动性学生接触基印刷电路布局问题基设计规排版软件非常漂亮包装印刷电路板板制作部电子技术员帮助完成
    5 结
    文目描述跨学科科工程设计项目:基单片机温度控制系统包括设定点输入数字设定值实际温度显示文已描述样系统设计讨许工程问题问题解决通常需入门课程求知识尤老师建议监督实际促进学生发展
    教学方法观点问题理想特征包括微控制器外围设备简单效运导水物理系统建模设计闭环控制需相简单实验模拟(详细性
    预测)取技术相关方面问题包括热敏电阻温度传感器(分需知识
    脉宽调制校准技术)实际单片机选择开发系统印制电路设计
    鸣谢
    作者感谢参项目学生马克朗·斯道夫马特洛尔戴维•舒克曼表现出辛勤工作奉献力工程工程成功全赖

    附录C 系统原理图











































    附录D 实物图












    附录E 元器件清单
    元器件名称 型号 数量 功
    蜂鸣器 Bell 1 报警
    电容 10uF 1
    电容 20uF 2
    发光二极 8 报警提示
    继电器 RelaySPDT 8 调控段外部电器开关
    显示屏 OLED12864 1 显示模块实时显示
    电源接口 Header 2 2
    PNP三极 9012 9 放电流
    电阻 2K 17 拉电阻
    电阻 10K 5 保护电路
    键 SWPB 5
    单片机 STC89C52 1
    温湿度传感器 DHT11 4
    晶振 12M 1 起振单片机





















    附录F 粮仓温湿度控制系统C语言程序
    #include reg51h
    #include codetabh
    #include lq12864h
    #include intrinsh

    #define uchar unsigned char
    #define uint unsigned int
    sbit dht_datP1^0 IO 口选注意 P3 口
    sbit dht1_datP1^1
    sbit dht2_datP1^2
    sbit dht3_datP1^3
    sbit jdq1 P2^0
    sbit jdq2 P2^1
    sbit jdq3 P2^2
    sbit jdq4 P2^3
    sbit jdq5 P2^4
    sbit jdq6 P2^5
    sbit jdq7 P2^6
    sbit jdq8 P2^7
    sbit beep P1^4

    sbit key1 P3^4
    sbit key2 P3^5
    sbit key3 P3^7
    sbit key4 P3^6

    uchar Tmax30Hmax65
    uchar setflag0rhflag0
    uchar dht_t1[4]{0000}dht_t2[4]{0000} 次温度整数部分温度数部分
    uchar dht_d1[4]{0000}dht_d2[4]{0000} 次湿度整数部分湿度数部分
    uchar dht_chk[4]{0000} 校验选择否具体参数手册
    uchar dht_num[4]{0000} while 循环中计数超时跳出循环
    #ifndef __INF_NEC__
    #define __INF_NEC__
    extern void dht_delay_10us()
    extern void dht_delay_10ms(uchar t)
    extern uchar dht_readat()
    extern void dht_getdat()
    extern void dht_init()
    #endif
    void dht_delay_10us() 调定量精确 10us重
    {
    uchar i0
    for(i0i<1i++)
    }
    void dht_delay_10ms(uchar t) 概 10ms 行粗略延时
    {
    uchar i0j0k0
    for(i0i{
    for(j0j<40j++)for(k0k<75k++)
    }
    }
    void dht_init() DHT11 初始化函数忘写程序时先加
    {
    dht_delay_10ms(100) DHT11 电前准备时间概 1s
    dht_dat1 总线准备
    }
    ***********************************************第DHT11*****************************
    ***********************************************第DHT11*****************************
    ***********************************************第DHT11*****************************
    ***********************************************第DHT11*****************************
    uchar dht_readat() 接收 8 位数先高位低位
    {
    uchar i0dat0
    for(i0i<8i++)
    {
    dht_num[0]2
    while((dht_dat0)&&(dht_num[0]++))
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    datdat<<1
    if(dht_dat1)
    {
    dht_num[0]2
    datdat|0x01
    while((dht_dat1)&&(dht_num[0]++))
    }
    }
    return dat
    }

    void dht_getdat() 1 DHT11 开始信号然读取次数五 8 位字节
    {
    uchar i0
    dht_dat0
    dht_delay_10ms(4)
    dht_dat1 单片机起始脉信号
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    dht_dat1 稍作延时等 DHT11 返回响应(响应低电)
    if(dht_dat0) 响应接收数否作处理
    {
    dht_num[0]2while((dht_dat0)&&(dht_num[0]++))
    dht_num[0]2while((dht_dat1)&&(dht_num[0]++))
    dht_d1[0]dht_readat()
    dht_d2[0]dht_readat()
    dht_t1[0]dht_readat()
    dht_t2[0]dht_readat()
    dht_chk[0]dht_readat()次读出五数
    }
    dht_dat1 释放总线
    dht_delay_10ms(10) 稍作延时
    }

    **************************************************************************************

    ***********************************************第2DHT11*****************************
    ***********************************************第2DHT11*****************************
    ***********************************************第2DHT11*****************************
    ***********************************************第2DHT11*****************************
    uchar dht2_readat() 接收 8 位数先高位低位
    {
    uchar i0dat0
    for(i0i<8i++)
    {
    dht_num[1]2
    while((dht1_dat0)&&(dht_num[1]++))
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    datdat<<1
    if(dht1_dat1)
    {
    dht_num[1]2
    datdat|0x01
    while((dht1_dat1)&&(dht_num[1]++))
    }
    }
    return dat
    }

    void dht2_getdat() 1 DHT11 开始信号然读取次数五 8 位字节
    {
    uchar i0
    dht1_dat0
    dht_delay_10ms(4)
    dht1_dat1 单片机起始脉信号
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    dht1_dat1 稍作延时等 DHT11 返回响应(响应低电)
    if(dht1_dat0) 响应接收数否作处理
    {
    dht_num[1]2while((dht1_dat0)&&(dht_num[1]++))
    dht_num[1]2while((dht1_dat1)&&(dht_num[1]++))
    dht_d1[1]dht2_readat()
    dht_d2[1]dht2_readat()
    dht_t1[1]dht2_readat()
    dht_t2[1]dht2_readat()
    dht_chk[1]dht2_readat()次读出五数
    }
    dht1_dat1 释放总线
    dht_delay_10ms(10) 稍作延时
    }

    **************************************************************************************

    ***********************************************第3DHT11*****************************
    ***********************************************第3DHT11*****************************
    ***********************************************第3DHT11*****************************
    ***********************************************第3DHT11*****************************
    uchar dht3_readat() 接收 8 位数先高位低位
    {
    uchar i0dat0
    for(i0i<8i++)
    {
    dht_num[2]2
    while((dht2_dat0)&&(dht_num[2]++))
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    datdat<<1
    if(dht2_dat1)
    {
    dht_num[2]2
    datdat|0x01
    while((dht2_dat1)&&(dht_num[2]++))
    }
    }
    return dat
    }

    void dht3_getdat() 1 DHT11 开始信号然读取次数五 8 位字节
    {
    uchar i0
    dht2_dat0
    dht_delay_10ms(4)
    dht2_dat1 单片机起始脉信号
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    dht2_dat1 稍作延时等 DHT11 返回响应(响应低电)
    if(dht2_dat0) 响应接收数否作处理
    {
    dht_num[2]2while((dht2_dat0)&&(dht_num[2]++))
    dht_num[2]2while((dht2_dat1)&&(dht_num[2]++))
    dht_d1[2]dht3_readat()
    dht_d2[2]dht3_readat()
    dht_t1[2]dht3_readat()
    dht_t2[2]dht3_readat()
    dht_chk[2]dht3_readat()次读出五数
    }
    dht2_dat1 释放总线
    dht_delay_10ms(10) 稍作延时
    }
    **************************************************************************************

    ***********************************************第4DHT11*****************************
    ***********************************************第4DHT11*****************************
    ***********************************************第4DHT11*****************************
    ***********************************************第4DHT11*****************************
    uchar dht4_readat() 接收 8 位数先高位低位
    {
    uchar i0dat0
    for(i0i<8i++)
    {
    dht_num[3]2
    while((dht3_dat0)&&(dht_num[3]++))
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    datdat<<1
    if(dht3_dat1)
    {
    dht_num[3]2
    datdat|0x01
    while((dht3_dat1)&&(dht_num[3]++))
    }
    }
    return dat
    }

    void dht4_getdat() 1 DHT11 开始信号然读取次数五 8 位字节
    {
    uchar i0
    dht3_dat0
    dht_delay_10ms(4)
    dht3_dat1 单片机起始脉信号
    dht_delay_10us()dht_delay_10us()dht_delay_10us()dht_delay_10us()
    dht3_dat1 稍作延时等 DHT11 返回响应(响应低电)
    if(dht3_dat0) 响应接收数否作处理
    {
    dht_num[3]2while((dht3_dat0)&&(dht_num[3]++))
    dht_num[3]2while((dht3_dat1)&&(dht_num[3]++))
    dht_d1[3]dht4_readat()
    dht_d2[3]dht4_readat()
    dht_t1[3]dht4_readat()
    dht_t2[3]dht4_readat()
    dht_chk[3]dht4_readat()次读出五数
    }
    dht3_dat1 释放总线
    dht_delay_10ms(10) 稍作延时
    }

    void baojing()
    {

    if(dht_t1[0]>Tmax){jdq10beep0dht_delay_10ms(5)}else{jdq11beep1dht_delay_10ms(5)}
    if(dht_d1[0]>Hmax){jdq20beep0dht_delay_10ms(5)}else{jdq21beep1dht_delay_10ms(5)}

    if(dht_t1[1]>Tmax){jdq30beep0dht_delay_10ms(5)}else{jdq31beep1dht_delay_10ms(5)}
    if(dht_d1[1]>Hmax){jdq40beep0dht_delay_10ms(5)}else{jdq41beep1dht_delay_10ms(5)}

    if(dht_t1[2]>Tmax){jdq50beep0dht_delay_10ms(5)}else{jdq51beep1dht_delay_10ms(5)}
    if(dht_d1[2]>Hmax){jdq60beep0dht_delay_10ms(5)}else{jdq61beep1dht_delay_10ms(5)}

    if(dht_t1[3]>Tmax){jdq70beep0dht_delay_10ms(5)}else{jdq71beep1dht_delay_10ms(5)}
    if(dht_d1[3]>Hmax){jdq80beep0dht_delay_10ms(5)}else{jdq81beep1dht_delay_10ms(5)}
    }

    **************************************************************************************
    void display()
    {
    OLED_P8x16Str(100Monitoring)
    OLED_P8x16Str(00R1)Dis_Num(240dht_t1[0]2)OLED_P8x16Str(400C )Dis_Num(640dht_d1[0]2) OLED_P8x16Str(800RH )
    OLED_P8x16Str(02R2)Dis_Num(242dht_t1[1]2)OLED_P8x16Str(402C )Dis_Num(642dht_d1[1]2) OLED_P8x16Str(802RH )
    OLED_P8x16Str(04R3)Dis_Num(244dht_t1[2]2)OLED_P8x16Str(404C )Dis_Num(644dht_d1[2]2) OLED_P8x16Str(804RH )
    OLED_P8x16Str(06R4)Dis_Num(246dht_t1[3]2)OLED_P8x16Str(406C )Dis_Num(646dht_d1[3]2) OLED_P8x16Str(806RH )
    }

    void keyscan()
    {
    if(key10)
    {
    dht_delay_10us()
    if(key10)
    {
    while(key1)
    setflagsetflag+1
    setflagsetflag2
    }
    }

    if(setflag0)
    {
    display()
    }

    if(setflag1)
    {
    OLED_P8x16Str(00 Seting )
    OLED_P8x16Str(02 Temper ) Dis_Num(762Tmax2) OLED_P8x16Str(922C )
    OLED_P8x16Str(04 Humdity) Dis_Num(764Hmax2) OLED_P8x16Str(924RH)
    OLED_P8x16Str(06 )

    if(key20)
    {
    dht_delay_10us()
    if(key20)
    {
    while(key2)
    rhflagrhflag+1
    rhflagrhflag2
    }
    }

    if(rhflag0)
    {
    OLED_P8x16Str(02S)
    if(key30)
    {
    dht_delay_10us()
    if(key30)
    {
    while(key3)
    TmaxTmax+1
    if(Tmax>35){Tmax35}
    if(Tmax<10){Tmax10}
    }
    }

    if(key40)
    {
    dht_delay_10us()
    if(key40)
    {
    while(key4)
    TmaxTmax1
    if(Tmax>35){Tmax35}
    if(Tmax<10){Tmax10}
    }
    }
    }

    if(rhflag1)
    {
    OLED_P8x16Str(04S)
    if(key30)
    {
    dht_delay_10us()
    if(key30)
    {
    while(key3)
    HmaxHmax+5
    if(Hmax>80){Hmax80}
    if(Hmax<10){Hmax10}
    }
    }

    if(key40)
    {
    dht_delay_10us()
    if(key40)
    {
    while(key4)
    HmaxHmax5
    if(Hmax>80){Hmax80}
    if(Hmax<10){Hmax10}
    }
    }
    }
    }

    }

    void main()
    {
    OLED_Init()
    dht_init()
    while(1) 限循环
    {
    dht_getdat()
    dht2_getdat()
    dht3_getdat()
    dht4_getdat()
    baojing()
    keyscan()
    display()
    }
    }
    文档香网(httpswwwxiangdangnet)户传

    《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
    该内容是文档的文本内容,更好的格式请下载文档

    下载文档到电脑,查找使用更方便

    文档的实际排版效果,会与网站的显示效果略有不同!!

    需要 8 香币 [ 分享文档获得香币 ]

    下载文档

    相关文档

    基于单片机的空调温度控制系统设计毕业设计

     毕业设计  题 目 基于单片机的空调温度控制系统设计 学生姓名 学 号 学 院 计算机与信息工程系 专业班级 指导...

    5年前   
    2543    0

    基于单片机的土壤温湿度检测计设计毕业设计

    基于单片机的土壤温湿度检测计设计毕业设计 目 录 1 绪论 1 1.1选题背景及意义 1 1.2设计任务与要求 1 2 总体方案设计 2 3单元模块设计 5 3.1各单元...

    5年前   
    1816    0

    基于单片机智能小车毕业设计

    毕 业 设 计(论 文)设计(论文)题目: 基于单片机的智能小车 ...

    6个月前   
    197    0

    基于单片机的室内温湿度

    本文采用STC89C52单片机、DHT11传感器、1602LCD显示屏和继电器控制等模块,完成温湿度测试和控制任务,其关键部分为(1)温湿度传感器DHT11实时测试温度、湿度。(2)判断采集的数...

    3年前   
    684    0

    基于单片机温室大棚温湿度采集系统设计

    温度和湿度是在农业生产中常见的和基本的参数之一,它们会大幅度影响作物产量和品质,现代科学和技术在提高农业生产力方面发挥着重要作用,以确定温度和湿度,实时显示、储存和监测。国内生产,产品质量与节能...

    4年前   
    564    0

    基于单片机温湿度测量系统的研究与设计

    温湿度的测量应用范围是很广的,对温湿度测量系统的研究也具有深远意义,本课题针对国内外对温湿度测量系统的研究与发展状况,分析了目前温湿度测量系统存在的主要问题,设计了一种基于单片机的温湿度测量系统...

    2年前   
    391    0

    毕业设计(论文)基于PLC的停车场车位控制系统设计

    基于PLC的停车场车位控制 系统设计 系 别:机电与自动化学院 专 业 班:电气工程及其自动化xx班 姓 名: 学 号:20xx113xx 指导教师: 201x年6月 基于...

    5年前   
    3079    0

    基于PLC的组合机床电气控制系统设计毕业设计

    基于PLC的组合机床电气控制系统设计摘 要应用组合机床加工大批量零件,快捷高效,生产效率高是机械加工的发展方向。本次设计任务是制定三面铣组合机床用来对Z512W型台式钻床主轴箱的Ф80、Ф90...

    4个月前   
    161    0

    基于PLC的造纸机控制系统设计毕业设计

    X职业技术学院毕 业 设 计 (论 文) 题目名称: 姓 名: ...

    4年前   
    1072    0

    基于FPGA的电梯控制系统设计毕业设计论文

    毕 业 设 计 [论 文]题 目: 基于FPGA的电梯控制系统设计 学 院: 电气与信息工程学院 ...

    3年前   
    1263    0

    毕业设计论文基于PLC的停车场车位控制系统设计

    基于PLC的停车场车位控制系统设计系 别:机电与自动化学院专 业 班:电气工程及其自动化班姓 名: 学 号:指导教师: 2011年X月基于PLC的停车场车位控制系统设计Des...

    6个月前   
    288    0

    基于单片机的温湿度控制器设计课程设计报告

    《智能仪器仪表设计与调试》课程设计报告 学 院: 电气与信息工程学院 专业班级: 测控10-01 学生姓名: 学 ...

    1年前   
    303    0

    基于AT89S51单片机无线传输系统设计毕业设计

    毕业论文(设计) 题 目: 单片机无线传输系统设计 完 成 人: ...

    4年前   
    871    0

    基于51单片机的智能窗户设计毕业设计

    基于51单片机的智能窗户设计【摘 要】 随着电子技术的发展和人民生活水平的不断提高,智能窗已经越来越多地被用到了现代智能化建筑中,提供住户一个安全、方便的环境。据统计,在未来的几年内,安装智...

    5个月前   
    113    0

    基于单片机的智能鱼缸的设计与实现毕业设计

    近年来嵌入式发展迅速,智能家居也进入了人们的生活。智能鱼缸却没有快速发展。我根据市场上相关设备现状的分析和研究,从系统集成角度进行设计和开发,提出了一套多功能的智能观赏鱼缸控制系统的设计方案。

    5年前   
    4251    0

    基于单片机的语音门铃设计毕业设计

    在现代电子产品中, 由于电子音乐门铃具有悦耳动听,价格低廉,耗电少等优点,在现代家居中的应用越来越流行。本毕业设计是基于单片机的“叮咚”门铃,通过单片机控制输出频率,由音频功率放大器LM386放...

    4年前   
    1255    0

    基于单片机的电子密码锁设计毕业设计

     ####工业大学城市学院 毕业设计说明书 作 者: 李xx 学 号: 09xx 系: 信息工程 ...

    5年前   
    1430    0

    基于51单片机压力检测系统设计毕业设计

     学号: xx 大 学 毕业设计(论文) (xxxx届) 题 目 ...

    5年前   
    2715    0

    基于单片机的彩灯控制器设计毕业设计

     题目: 基于单片机的节日彩灯控制器的设计 作 者 姓 名: 学 号: ...

    3年前   
    558    0

    基于单片机的鱼缸控制器设计毕业设计论文

    基于单片机的鱼缸控制器设计 摘 要 本文是基于单片机的鱼缸控制器的设计,目前市场上有各种各样的观赏类的鱼缸,进入了不同的应用场合,如家庭、宾馆和商场等等,但现有的鱼缸一般需要人为的...

    5年前   
    2456    0

    文档贡献者

    文***品

    贡献于2021-05-13

    下载需要 8 香币 [香币充值 ]
    亲,您也可以通过 分享原创文档 来获得香币奖励!
    下载文档

    该用户的其他文档