当前位置:网站首页>(13) Simple temperature alarm device based on 51 single chip microcomputer
(13) Simple temperature alarm device based on 51 single chip microcomputer
2022-07-28 08:38:00 【Meursault639】
Catalog
A temperature measuring device was just made in the afternoon , We continue to work in the evening . Now that you can measure the temperature , Let's combine the previous knowledge points , To make a temperature alarm device !
Demand analysis
Temperature alarm device plays an extremely important role in many places , Such as the storage of laboratory instruments or drugs , Remind the occurrence of fire and so on , For example, the relative humidity is often greater than 95%、 No fireworks 、 There is a lot of dust 、 Under normal circumstances, there is smoke and dust retention 、 The kitchen 、 Boiler Room 、 Generator room 、 Drying workshop 、 Smoking Room 、 Other halls and public places that are not suitable for installing smoke detectors . meanwhile , We hope that the temperature range can be regulated , It's better to have memory function , This can prevent the need to readjust the safe temperature range after power failure .
Function realization
Get the temperature we use DS18B20 To achieve , For details, please see the article introduced before (1 Bar message ) ( Twelve )51 Single chip microcomputer ---- use DS18B20 Shallow measurement ( jiang ) The outdoor temperature in the West _Meursault639 The blog of -CSDN Blog ;
To display the temperature, we use LCD1602 To achieve ;
We can adjust the safe temperature range by pressing the key , But you have to use a timer to scan , Otherwise, the acquisition temperature will be affected ;
The alarm function is realized by buzzer ;
Memory function we use AT24C02 To achieve , You can also refer to the previous writing , Timer scanning is also included (1 Bar message ) ( 11、 ... and )51 Single chip microcomputer —— use AT24C02 Realize the storage of stopwatch data ( Attached with achievement display )_Meursault639 The blog of -CSDN Blog ;
Code implementation
#include <REGX52.H>
#include "LCD1602.h"
#include "DS18B20.h"
#include "Delay.h"
#include "AT24C02.h"
#include "Key.h"
#include "Time0.h"
#include "Buzzer.h"
float T,TShow;// temperature , Show the temperature
char TL,TH;
unsigned char KeyNum;
void main()
{
DS18B20_ConvertT();// Switch the primary temperature before power on , Prevent errors in reading data for the first time
Delay(1000); // Wait for the conversion to complete
TH=AT24C02_ReadByte(0); // Read temperature threshold data
TL=AT24C02_ReadByte(1);
if(TH>125 || TL<-55 || TH<=TL)
{
TH=20; // If the threshold is illegal , Set to the default value
TL=15;
}
LCD_Init();
LCD_ShowString(1,1,"T:");
LCD_ShowString(2,1,"TH:");
LCD_ShowString(2,9,"TL:");
LCD_ShowSignedNum(2,4,TH,3);
LCD_ShowSignedNum(2,12,TL,3);
Timer0_Init();
while(1)
{
KeyNum=Key();
// Temperature reading and display
DS18B20_ConvertT();// Conversion temperature
T = DS18B20_ReadT();// Reading temperature
if(T < 0){
LCD_ShowChar(1,3,'-');// Show minus sign
TShow = -T;// Change the temperature to a positive number
}else{
LCD_ShowChar(1,3,'+');// Show positive sign
TShow = T;
}
LCD_ShowNum(1,4,TShow,3);// Display temperature integer part
LCD_ShowChar(1,7,'.');
LCD_ShowNum(1,8,(unsigned long)(TShow*100)%100,2);// Display decimal part of temperature , Keep two decimal places
// Threshold judgment and display
if(KeyNum)
{
if(KeyNum==1) //K1 Key ,TH Self increasing
{
TH++;
if(TH>125){TH=125;}
}
if(KeyNum==2) //K2 Key ,TH Self reduction
{
TH--;
if(TH<=TL){TH++;}
}
if(KeyNum==3) //K3 Key ,TL Self increasing
{
TL++;
if(TL>=TH){TL--;}
}
if(KeyNum==4) //K4 Key ,TL Self reduction
{
TL--;
if(TL<-55){TL=-55;}
}
LCD_ShowSignedNum(2,4,TH,3); // Display threshold data
LCD_ShowSignedNum(2,12,TL,3);
AT24C02_WriteByte(0,TH); // Write to At24C02 Kept in
Delay(5);
AT24C02_WriteByte(1,TL);
Delay(5);
}
if(T>TH) // Cross border judgment
{
LCD_ShowString(1,13,"OV:H");
Buzzer_Time(100);
}
else if(T<TL)
{
LCD_ShowString(1,13,"OV:L");
Buzzer_Time(100);
}
else
{
LCD_ShowString(1,13," ");
}
}
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count;
TL0 = 0x66; // Set the initial timing value
TH0 = 0xFC;;
T0Count++;
if(T0Count>=20)
{
T0Count=0;
Key_Loop(); // Every time 20ms Call the key driver function once
}
}Each module has been introduced in the previous article , If there are interested students , It's OK to find me to play with the complete code , I will continue to improve this , I also hope the boss can give some advice .
Running results
Temperature alarm
边栏推荐
- The cooperation between starfish OS and metabell is just the beginning
- 二维数组及操作
- CarSim simulation quick start (XIII) - steering system
- 5张图告诉你:同样是职场人,差距怎么这么大?
- PMP practice once a day | don't get lost in the exam -7.13
- 微服务架构 Sentinel 的服务限流及熔断
- Win the bid! Nantah general gbase 8s won the bid for the 2022 database framework project of NARI Group
- leetcode/排序数组中两个数字之和
- Usage of qmap
- Shell编程规范与变量
猜你喜欢

How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)

SQL Server查询结果导出到EXCEL表格

CAT1 4g+ Ethernet development board 232 data is sent to the server through 4G module TCP

uniapp---- 获取当前位置的经纬度等信息的详细步骤(包含小程序)

单片机IO口控制12V电压通断,MOS和三极管电路
![[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial](/img/67/5373c45716ade5fbd1d3a980d8e5da.png)
[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial

2022 Niuke multi school second problem solving Report

Shell编程规范与变量

Export SQL server query results to excel table

MySQL how to add users and set permissions?
随机推荐
Creation of status bar (29)
Can‘t connect to server on ‘IP‘ (60)
网络安全漏洞分析与漏洞复现
[Qt5] a method of multi window parameter transmission (using custom signal slot) and case code download
How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)
CarSim simulation quick start (XII) - Driver Model (2)
postgresql查询【表字段类型】和库中【所有序列】
C轮融资已完成!思迈特软件领跑国内BI生态赋能,产品、服务竿头一步
2022牛客多校第二场解题报告
Redis 基本知识,快来回顾一下
Use of namespaces
CarSim simulation quick start (XIII) - steering system
2022 Niuke multi school second problem solving Report
‘全局事件总线’&‘消息订阅与发布’
sql server时间字段排序
When unity switches to another scene, he finds that the scene is dimmed
【软考软件评测师】2013综合知识历年真题
一篇文章搞懂数据仓库:元数据分类、元数据管理
SQL Server查询结果导出到EXCEL表格
数字签名和CA证书