1、智能温度报警系统 摘要: 随着时代的进步和发展,单片机技术已经普及到我们生活,工作,科研,各个领域,已经成为一种比较成熟的技术 ,本文将介绍一种基于单片机控制的数字温度计,本温度计属于多功能温度计,可以设置上下报警温度,当温度不在设置范围内时,可以报警。 关键词: 单片机,数字控制,温度计, DS18B20, AT89S51 ABSTRACT Along with the progress and developments of the ages, a machine technique has already make widely available we are living, work
2、, the research, each realm, has already become a kind of to compare the mature technique, this text will introduce a kind of numerical thermometer that controls according to a machine, this thermometer belongs to the multi-function thermometer, can establish the top and bottom to report to the polic
3、e the temperature, being the temperature not within the scope of establish, can report to the police. Key Word: numeral control, thermometer, DS18B20, AT89S52 引言 随着人们生活水平的不断提高 ,单片机控制无疑是人们追求的目标之一,它所给人带来的方便也是不可否定的,其中数字温度计就是一个典型的例子,但人们对它的要求越来越高,要为现代人工作、科研、生活、提供更好的更方便的设施就需要从数单片机技术入手,一切向着数字化控制,智能化控制方向发展。
4、 本设计所介绍的数字温度计与传统的温度计相比,具有读数方便,测温范围广,测温准确,其输出温度采用数字显示,主要用于对测温比较准确的场所,或科研实验室使用,该设计控制器使用单片机 AT89S51,测 温传感器使用 DS18B20,用 3 位共阳极 LED 数码管以串口传送数据 ,实现温度显示 ,能准确达到以上要求。 智能温度报警系统 : 主要参数 序号 参数 数值 备注 1 工作电压 4V6V 直流 2 功率 #include #include code unsigned char seg7code11= 0xc0,0xf9,0xa4,0xb0,0x99,0x92, 0x82,0xf8,0x80
5、,0x90,0x40; /显示段码 sbit TMDAT =P31; /DS18B20 的数据输入 /输出脚 DQ,根据情况设定 sbit jia=P21; sbit jian=P20; sbit hong=P10; /红色警告灯 sbit sheng=P11; /蜂鸣器 sbit lan=P12; /兰色灯 bit write=0; /写 24C08 的标志; j=30; unsigned int sdata;/测量到的温度的整数部分 unsigned char xiaoshu1;/小数第一位 unsigned char xiaoshu2;/小数第 二位 unsigned char xiao
6、shu;/两位小数 bit fg=1; /温度正负标志 /24C08 读写驱动程序 / sbit scl=P34; / 24c08 SCL sbit sda=P35; / 24c08 SDA void delay1(unsigned char x) unsigned int i; for(i=0;i 1); return (dat); void tmwbyte (unsigned char dat) /写一个字节 unsigned char j,i; bit testb; for (j=1;j 1; if (testb) TMDAT = 0; /写 0 i+; i+; TMDAT = 1; f
7、or(i=0;i0x7f) /最高位为 1 时温度是负 a=a; b=b+1; /补码转换,取反加一 fg=0; /读取温度为负时 fg=0 sdata = a/16+b*16; /整数部分 xiaoshu1 = (a /小数第一位 xiaoshu2 = (a/小数 xiaoshu=xiaoshu1*10+xiaoshu2; /小数 void DS18B20PRO(void) tmstart(); /yanshi(5); /如果是不断地读取的话可以不延 tmrtemp(); /读取温度 ,执行完毕温度将存于 void Led() if(fg=1) /温度为正时显示的数据 P2=P2 P0=se
8、g7codesdata/10; /输 Delay(2); P2=P2|0xf0; P2=P2 P0=seg7codesdata%10|0x80; /输出个 Delay(2); P2=P2|0xf0; P2=P2 P0=seg7codexiaoshu1; /输出小数点 Delay(2); P2=P2|0xf0; P2=P2 P0=seg7codexiaoshu2; /输出小 Delay(1); P2=P2|0xf0; Delay(2); P2=P2|0xf0;P2=P2 P0=seg7codej/10; /输出十位 Delay(2); P2=P2|0x0f; P2=P2 P0=seg7codej
9、%10|0x80; /输出个位 Delay(1); P2=P2|0x0f; /* P2=P2 P0=seg7codesdata/10; /输出十位 Delay(8); P2=P2|0xf0;P2=P2 P0=seg7codesdata%10|0x80; /输出个位 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codexiaoshu1; /输出小数点 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codexiaoshu2; /输出小 Delay(4); P2=P2|0xf0; Delay(8); P2=P2|0xf0;P2=P2 P0=seg7c
10、odej/10; /输出十位 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codej%10|0x80; /输出个位 Delay(4); P2=P2|0xf0; */ if(sdata=j) lan=1; hong=0; sheng=0; ; if(fg=0) /温度为负时显示的数据 P2=P2 P0=seg7code11; /负号 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codesdata/10|0x80; /输出十位 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codesdata%10; /输出个位 Delay(8); P2=P2|0xf0; P2=P2 P0=seg7codexiaoshu1; /输出小 Delay(4); P2=P2|0xf0; main() fg=1; x24c08_init(); /初始化 24C08 j=x24c08_read(2);/读出保存的数据 while(1) DS18B20PRO(); Led(); if(jia=0) Delay(200);j+; if(jian=0) Delay(200);j-; x24c08_write(2,j);