Temperature alarm system based on 51 microcontroller

Publisher:丹青妙手Latest update time:2023-03-03 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Function:

Design a temperature alarm system that can set the upper and lower limits of the temperature. When the set value is reached, the buzzer will sound; the button setting has the functions of setting, confirming, canceling, reducing and increasing, and LCD1602 will display relevant temperature information in real time.

Setting interface:


When the temperature exceeds the set value, the buzzer sounds:

The temperature exceeds the set value and the buzzer sounds: The temperature exceeds the set value.

When the temperature is lower than the set value, the buzzer sounds:


Part of the program:

#include

#include "SETTEM.h" //Set the upper and lower limit header files for alarms

#include "Lcd1602.h" //LCD display module function header file

#include "DS18B20.h" //DS18B02 module function header file

#include "IntToChar.h" //Header file that stores integers converted to strings

#include "Alarm.h" //Alarm function header file


bit flag1s = 0; //1s timing flag

unsigned char T0RH = 0; //High byte of T0 reload value

unsigned char T0RL = 0; //low byte of T0 reload value


int key=0;

char Hint1[]={"Current temperature"};


void ConfigTimer0(unsigned int ms);


void main()

{

bit res;

int temp; //The current temperature value read

int intT, decT; //The integer and decimal parts of the temperature value

unsigned char len;

unsigned char str[12];

EA = 1; //Enable total interrupt

ConfigTimer0(10); //T0 timing 10ms

Start18B20(); //Start DS18B20

InitLcd1602(); //Initialize LCD

ConfigInt0(); //Set the temperature

while (1)

{

if (flag1s) //Update temperature every second

{

flag1s = 0;

res = Get18B20Temp(&temp); //Read the current temperature

if (res) //When reading is successful, refresh the current temperature display

{

intT = temp >> 4; //Separate the integer part of the temperature value

decT = temp & 0xF; //Separate the decimal part of the temperature value

len = IntToString(str, intT); //Convert the integer part to a string

str[len++] = '.'; //Add decimal point

decT = (decT*10) / 16; //Convert the decimal part of binary to 1 decimal digit

str[len++] = decT + '0'; //Convert decimal digits to ASCII characters

str[len++] = key + '0';

while (len < 6) //Use spaces to complete to 6 characters in length

{

str[len++] = ' ';

}

str[len] = ''; //Add string terminator

LcdShowStr(0, 0, Hint1); //The prompt is displayed on the LCD screen

LcdShowStr(0, 1, str); //The temperature is displayed on the LCD screen

}

else //When reading fails, an error message is prompted

{

LcdShowStr(0, 0, "error!");

}

Start18B20(); //Restart the next conversion

Alarm((float)temp*0.0625,Htem,Ltem);

}

}

}


Reference address:Temperature alarm system based on 51 microcontroller

Previous article:Car reversing anti-collision alarm system based on 51 microcontroller
Next article:Design of fingerprint access control based on microcontroller

Recommended ReadingLatest update time:2024-11-16 13:24

[C51 code] LCD1602 driver
 /************************************************LCD1602.c*************************************************************************/ #include "Atmel/AT89X51.h" #include "delay.h" #include "lcd1602.h" /*************Declare variables****************/ uchar code table ={0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02, //y
[Microcontroller]
C51_LCD1602 display
#include #include #define uchar unsigned char #define uint unsigned int   sbit rs=P2^6; sbit rw=P2^5; sbit en=P2^7;   uchar shuma ={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09}; //                   0     1     2     3     4     5     6     7     8                       void delay(uchar a)
[Microcontroller]
Any two IOs can directly drive LCD1602 without external chip
This is the circuit. Careful friends will find that there are several chip resistors and capacitors in the actual picture. The secret is here. The memory effect of the capacitor is used to convert parallel data into serial data. (Original file name: 2wire_1602.PNG)  The demonstration program is very simple and shou
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号