




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 图2 51单片机内部结构 图3 51单片机双列直插封装方式的引脚 I/O口说明: 图4 晶振电路 上电复位 按键复位 图5 51单片机的两种复位电路 DS18B20介绍 2. 引脚封装 图 6 DS18B20引脚封装及定义图 3.硬件连接图7 DS18B20典型电路 4.工作原理图8 64位光刻ROM各位定义 图9 高速暂存器RAM以上这些指令分别涉及DS18B20的ROM和图10 DS18B20内部温度的存储格式 图11 串口通信电路 图12 按键电路 图13 报警电路图14 显示电路74HC595简介:图1574hc595管脚图图16 整体电路图图17 PCB布线图图18 课设实际使用P
2、CB布线图DS18B20工作程序:/*/*程序名:18B20.H */*功能:对ds18b20的控制,时期能够正确检测当前环境实时温度并转换处理温度*/*包括延时函数和温度显示数据的转换函数 */*/#define uchar unsigned char#define uint unsigned intsbit ds=P34; /引脚定义uint temp;float f_temp;uint temperature4=0;void delay (uint count)/延时函数unsigned int i;while (count)i =200;while (i>0) i-;count-
3、; void dsreset (void)/ 发送复位和初始化unsigned int i;ds = 0;i = 103;while (i>0) i-; / 延时ds = 1;i = 4;while (i>0) i-;bit tempreadbit (void)/ 读取数据的一位 uint i;bit dat;ds = 0; i+;ds = 1; i+; i+;/延时dat = ds;i = 8; while (i>0) i-;/ 延时return (dat);uchar tempread (void) /读一个字节uchar i,j,dat;dat = 0;for (i=1
4、;i<=8;i+)j = tempreadbit();dat = (j << 7) | (dat >> 1);return (dat);void tempwritebyte(uchar dat)/写一个字节 uint i;uchar j;bit testb;for(j=1;j<=8;j+)testb=dat&0x01;dat=dat>>1;if (testb)ds=0; / 写0 i+; i+; ds = 1;i = 8; while (i>0) i-; elseds = 0; / 写0 i = 8; while (i>0)
5、i-; ds = 1;i+; i+; void tempchange(void)/ ds1820开始转换 dsreset ();/ 复位delay (1);/ 延时tempwritebyte(0xcc);/ 跳过序列号命令tempwritebyte(0x44); / 发转换命令 44H, uint get_temp(void)/ 读取温度 uchar a,b;dsreset ();/ 复位delay (1);/ 延时tempwritebyte(0xcc); / 跳过序列号命令tempwritebyte(0xbe); / 发送读取命令a = tempread();/ 读取低位温度b = temp
6、read(); /读取高位温度temp=b;temp<<=8;temp=temp|a;f_temp=temp*0.0625;temp=f_temp*10+0.5;f_temp=f_temp*10+0.05;return temp;/返回测量值 void translate(uint t) /显示数据转换函数 temperature0=t/100; temperature1=t%100/10; temperature2=t%100%10; temperature3=1000; 主函数功能程序:/*/*程序名:main hanshu.c */* 功 能:实时测量温度,超过上下限报警,报
7、警温度可手动调整。K1是用来 进行*/上下限调节模式的, 当按一下K1进入上限调节模式,再按一下进入下限调节模式。在正常模式下,按一下K2进入查看上限温 度模式,显示1s左右自动退出;按一下K3进入查看下限温度模式,显示1s左右自动退出;在调节上下限 温度模式下,K2是实现加1功能,K1是实现减1功能。/*/#include <reg52.h> /头文件#include <18b20.h>#include "intrins.h"#define uchar unsigned char/宏定义#define uint unsigned intsbit S
8、T=P14;/74hc595引脚位定义sbit CP=P12;sbit DIN=P13;sbit key1=P15;/按键定义sbit key2=P16;sbit key3=P17;sbit beep=P32;/蜂鸣器定义unsigned char table=0x82,0x9f,0xa4,0x85,0x99,0xc1,0xc0,0x8b,0x80,0x81,0x02,0x1f,0x24,0x05,0x19,0x41,0x40,0x0b,0x00,0x01;/带小数点与否的09段码表uint wendushangxian=36;/初始温度上下限设定uint wenduxiaxian=0;uin
9、t k1,k2;void shuchu()/74hc595输出函数ST=0;_nop_();_nop_();ST=1;_nop_();void shuru(unsigned char a)/74hc595输入函数unsigned char i;for(i=8;i>0;i-)CP=0;a<<=1;_nop_();DIN=CY;CP=1;_nop_();void display()/显示函数 tempchange();get_temp();translate(temp);shuru(tabletemperature2);shuru(tabletemperature1+10);sh
10、uru(tabletemperature0);shuru(0xff);shuchu();void keyscan()/按键扫描函数 if(key1=0) delay(20); if(key1=0) while(!key1);/松手检测 beep=0;/按键声delay(10);beep=1; while(1) if(key2=0) delay(20); if(key2=0) beep=0;delay(10);beep=1; shuru(tablewendushangxian%10);shuru(tablewendushangxian/10); shuru(0xff); shuru(0xff);
11、 shuchu();while(!key2);/松手检测 while(1) if(key2=0) /上限值设置 + delay(20); if(key2=0) wendushangxian+;beep=0;delay(10);beep=1;if(wendushangxian=-1)|(wendushangxian=-2)|(wendushangxian=-3)wendushangxian=0;if(wendushangxian=100)wendushangxian=99;if(wendushangxian<=wenduxiaxian)wendushangxian+;beep=0;dela
12、y(10);beep=1;shuru(tablewendushangxian%10);shuru(tablewendushangxian/10); shuru(0xff); shuru(0xff); shuchu(); while(!key2); if(key3=0) /上限值设置 - delay(20); if(key3=0) wendushangxian-;beep=0;delay(10);beep=1;if(wendushangxian=100)wendushangxian=99;if(wendushangxian<=wenduxiaxian)wendushangxian+;bee
13、p=0;delay(10);beep=1;shuru(tablewendushangxian%10);shuru(tablewendushangxian/10); shuru(0xff); shuru(0xff); shuchu(); while(!key3); /松手检测 if(key1=0) delay(20); if(key1=0) delay(20); break; /确认 if(key3=0) delay(20); if(key3=0) while(1) if(key2=0) /下限值设置 + delay(20); if(key2=0) wenduxiaxian+;beep=0;de
14、lay(10);beep=1;if(wenduxiaxian=-1)|(wenduxiaxian=-2)|(wenduxiaxian=-3)wenduxiaxian=0;if(wenduxiaxian>=wendushangxian)wenduxiaxian-;beep=0;delay(10);beep=1;shuru(tablewenduxiaxian%10);shuru(tablewenduxiaxian/10); shuru(0xff); shuru(0xff); shuchu(); while(!key2); if(key3=0) /下限值设置 - delay(20); if(k
15、ey3=0) wenduxiaxian-;beep=0;delay(10);beep=1;if(wenduxiaxian=-1)|(wenduxiaxian=-2)|(wenduxiaxian=-3)wenduxiaxian=0;if(wenduxiaxian>=wendushangxian)wenduxiaxian-;beep=0;delay(10);beep=1;shuru(tablewenduxiaxian%10);shuru(tablewenduxiaxian/10); shuru(0xff); shuru(0xff); shuchu(); while(!key3); if(ke
16、y1=0) delay(20); if(key1=0) beep=0;delay(10);while(!key1)beep=1; break; if(key1=0) delay(20); if(key1=0) beep=0;delay(10);while(!key1)beep=1; break; warn1(uint k1)/上限报警函数 if(temperature0*10+temperature1)>=wendushangxian) beep=0;delay(k1);beep=1;delay(k1);else beep=1;warn2(uint k2)/下限报警函数 if(tempe
17、rature0*10+temperature1)<=wenduxiaxian)beep=0;delay(k2);beep=1;delay(k2); else beep=1;void guan_baojing()/关报警函数if(key3=0)delay(20);if(key3=0)beep=1;void main()/主函数 k2=200; beep=1; while(1) k1+=5; k2-=5; if(k1=200)k1=0;if(k2=0)k2=200; keyscan();warn1(k1);warn2(k2);guan_baojing();display();数字温度测试系统元件清单序号名称规格封装数量代号1插座双排针座IDC101JP52数码管(共阳)红色0.5英寸SMG0.54DG1DG2DG3DG43排电阻8*5.1KSIP91R184电阻1KAXIAL0.44R1R3R4R55二极管IN4001DIODE0.44D1D2D3D46蜂鸣器5VECAP11FM
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业科技公司员工保密合同
- 简易手机抵押合同范本5篇
- 购销合同轮胎3篇
- 安全施工现场培训课件
- 瓶子里的小昆虫课件
- 理财培训课件
- 电力工程采购方案(3篇)
- 安全文明施工培训感想
- 贵港港平南港区长岐塘作业区罗洪码头提档升级工程环评报告
- 环卫作业管理知识培训课件
- 2025年中国电信招聘考试行政职业能力测试预测题集
- 静脉治疗知识培训课件
- 学风建设科研诚信宣教课件
- 江西省宜春市2025年上半年事业单位公开遴选试题含答案分析
- 2025繁轩科技发展(天津)有限公司公开招聘工作人员35人备考题库及答案解析
- 2025年度水电项目工程结算与审计服务协议
- 德育副校长在新学期德育工作部署会讲话范文
- (2025年标准)学生玩耍纠纷协议书
- 南昌二中初一数学试卷
- 2025-2026秋季学年第一学期学生国旗下演讲稿(20周):第五周 76载荣光里我们茁壮成长-喜迎国庆
- 2025金融消费权益保护知识竞赛题库(+答案)
评论
0/150
提交评论