51 microcontroller kitchen fireproof infrared combustible gas detection alarm LCD display design

1. Foreword

In the past two years, the requirements and difficulty of graduation projects and graduation defenses have continued to increase. Traditional graduation projects lack innovation and highlights, and often fail to meet the requirements for graduation defenses. In the past two years, junior students and junior students have constantly told Senior Xiaohong to do it himself The project system does not meet the teacher’s requirements. In order for everyone to pass the graduation project smoothly and with the least amount of energy, Senior Xiaohong shared a high-quality graduation project. Today I want to share a kitchen fireproof infrared combustible gas detection alarm LCD design based on a 51 microcontroller.

2. Introduction

Air quality PM2.5 detection and alarm system for indoor environment detection based on STM32 microcontroller

1. The microcontroller collects the temperature and smoke status values in real time and displays them on the LCD1602 liquid crystal in real time.
2. The six-pin switch 1 controls the alarm and is used for emergency situations. Turn it to the top to alarm, and turn it to the bottom to not alarm. Six pin switch
3. Control the switch of the rolling shutter door. Under normal circumstances, turn it to the top to open, and turn it to the bottom to close the rolling shutter door.
4. If the infrared detects someone and the temperature exceeds the threshold 45 or smoke is detected on the right side, the alarm will sound; if no one is present, the microcontroller drives the rolling shutter door to force it open to prevent dangerous fire situations.

3. Composition

This design consists of STC89C52 microcontroller circuit + switch detection circuit + infrared detection circuit + stepper motor drive circuit + buzzer alarm circuit + smoke MQ-135 circuit + temperature DS18B20 circuit + lcd1602 liquid crystal circuit + power supply circuit.

4. Realize the effect

Overall display

5. Design principle

5.1 Introduction to STC89C52RC

The STC89C52RC microcontroller has a wide range of uses and is the first choice chip for every electronic equipment designer. This chip is deeply loved by the majority of users. This microcontroller is enhanced and modified based on the 8051 microcontroller. It is fully compatible with the traditional 8051 microcontroller when writing instruction codes, so it is more convenient to write programs. Its advantages are high reliability, affordable price and low power consumption. The main technical advantage of the STC89C52RC microcontroller chip is the use of Flash memory technology. The use of this technology not only reduces the manufacturing cost, but also It is fully compatible with the 8051 microcontroller in terms of software and hardware. It is also manufactured using high-density non-volatile memory manufacturing technology and combines a multi-functional 8-bit CPU and flash memory in a single chip, so it can be accepted by most users in China. . The electrically rewritable nature of its program makes development and testing easier, and also provides a highly flexible and cheap solution for many embedded control systems.

There are 12 clocks/machine cycles and 6 clocks/machine cycles inside the chip, and we can choose at will. Its working voltage is: 5.5V ~ 3.3V (5V microcontroller) / 3.8V ~ 2.0V (3V microcontroller). Its working frequency is between 0 and 40MHz, which is more convenient than the ordinary 8051 microcontroller. In actual use, its working frequency can reach 48MHz. The application space we can use is 8K bytes, and 512 bytes of RAM are integrated on the chip. There are 32 general-purpose I/O ports on the chip, that is, 4 groups are P1, P2, P3, and P4. Each group has 8 I/O ports. The four groups of interfaces after reset are quasi-bidirectional ports/weak pull-ups. When used as bus expansion, there is no need to add a pull-up resistor, but when used as an I/O port, a pull-up resistor is required. The built-in ISP (In-System Programmable) and IAP (In-Application Programmable) technologies within the chip make programming and simulation very easy, eliminating the trouble of using a dedicated programmer and a dedicated emulator, and can also be used directly Download the user program through the serial port (RxD/P3.0, TxD/P3.1), the download speed is very fast, which makes the programming of the program easier. There is also a watchdog function. 4 external interrupts, falling edge interrupt or low level trigger circuit, Power Down mode can be woken up by external interrupt low level trigger interrupt. There are three 16-bit timers/counters, namely timers T0, T1, and T2. Universal asynchronous serial port (UART), timer software can also be used to implement multiple UARTs.

STC89C52RC pin function description:

VCC (40 pin): supply voltage

VSS (20 pin): ground

P0 port (P0.0~P0.7, pins 39~32): Port P0 is an open-drain 8-bit bidirectional I/O port. As an output port, each pin can drive 8 TTL loads. When “1” is written to port P0, it can be used as a high-impedance input. When accessing external program and data memory, Port P0 can also provide a multiplex bus for the lower 8-bit address and 8-bit data. At this time, the internal pull-up resistor of port P0 is effective. When programming Flash ROM, the P0 port receives the instruction byte; when verifying the program, the instruction byte is output. During verification, an external pull-up resistor is required.

P1 port (P1.0~P1.7, pins 1~8): Port P1 is an 8-bit bidirectional I/O port with internal pull-up resistor. The output buffer of P1 can drive (sink or source current mode) 4 TTL inputs. When writing 1 to the port, the port is pulled to a high potential through the internal pull-up resistor, which can be used as an input port. When port P1 is used as an input port, because of the internal pull-up resistor, those pins that are externally pulled low will output a current.

P2 port (P2.0~P2.7, 21~28 pins): P2 port is an 8-bit bidirectional I/O port with internal pull-up resistor. The output buffer of P2 can drive (sink or source current mode) 4 TTL inputs. When writing 1 to the port, the port is pulled to a high level through the internal pull-up resistor, and then it can be used as an input port. When P2 is used as an input port, because of the internal pull-up resistor, those pins that are pulled low by external signals will output a current.

When accessing external program memory and external data memory with a 16-bit address (such as executing the “MOVX @DPTR” instruction), P2 sends the high 8-bit address. When accessing an external data memory with an 8-bit address (such as executing the “MOVX @R1” instruction), the contents of the P2 port pin (that is, the contents of the P2 register in the special purpose register (SFR) area) will not be used during the entire access. Change. During Flash ROM programming and program verification, P2 also receives high-order addresses and some control signals.

P3 port (P3.0~P3.7, pins 10~17): P3 is an 8-bit bidirectional I/O port with internal pull-up resistor. The P3’s output buffer can drive (sink or source current mode) 4 TTL inputs. When writing 1 to the port, the port is pulled to a high potential through the internal pull-up resistor, and it can be used as an input port. When P3 is used as an input port, because of the internal pull-up resistor, those pins that are pulled low by external signals will input a current.

The chip pin diagram of the STC89C52RC microcontroller is as shown in the figure.

Figure STC89C52RC microcontroller pin diagram

Crystal oscillator circuit

There is a crystal oscillator circuit in every single-chip microcomputer system, and the crystal oscillator plays a decisive role in the entire single-chip microcomputer system. It combines the internal circuit of the microcontroller to generate a clock frequency. With this basic microcontroller, the microcontroller can execute all instructions and complete the required functions. At the same time, the speed of the clock frequency directly affects the running speed of the microcontroller. The higher the clock frequency, the faster the corresponding microcontroller runs. Crystal oscillator is actually a crystal resonance technology that converts electrical energy and mechanical energy into each other, providing stable and accurate single-frequency oscillation for its microcontroller.

A crystal oscillator circuit generally consists of two capacitors, also called load capacitors. The working state of the microcontroller is generally in a parallel resonance state. The size of the load capacitance will be determined according to the requirements of the crystal oscillator. The frequency of the crystal oscillator is tested under the load capacitance it provides, so as to reduce the occurrence of errors. At the same time, it can also ensure the error caused by temperature drift. The same capacitor value is selected to ensure the normal operation of the crystal oscillator circuit. If the values of the two capacitors are different, or even the difference is too large, it will easily cause resonance imbalance and lead to shutdown. Vibrate or simply not vibrate.

In this design, XTAL1 and XTAL2 are externally connected to quartz crystals as timing components. There is a high-gain reverse amplifier inside the STC89C52RC chip to form an oscillator, thereby achieving self-oscillation and generating a clock. The operating frequency of the crystal oscillator is generally selected between 1.2~12MHZ, and the value of capacitors C1 and C2 is generally between 10PF~40PF. Here I chose an operating frequency of 12MHZ and two 22PF capacitors to form a crystal oscillator circuit. The crystal oscillator circuit of the STC89C52RC microcontroller is shown in Figure 3.2.

Figure crystal oscillator circuit

Reset circuit

The reset circuit is also an important part of the microcontroller. When the microcontroller starts running, it must first perform a reset operation. However, the microcontroller cannot complete it alone, so it must be combined with an external circuit to perform the reset operation. Figure 3.3 is the reset circuit diagram. The RST pin is the input for the reset signal. It is valid when the high level is input for more than two consecutive machine cycles. When the crystal oscillator frequency is 12MHZ, the reset signal should last for more than 2us to complete the reset operation. When we add a reset circuit and the microcontroller is powered on, the RST pin will first maintain a high level for a short period of time and then change to a low level. This is the process of resetting the microcontroller.

Figure reset circuit

6. Part of the core code

#include<reg52.h> //Include the header file. Generally, no changes are needed. The header file contains the definition of special function registers.
#include <stdio.h>
#include "delay.h"
#include "18b20.h"
#include "1602.h"

sbit A1=P1^0; //Define the stepper motor connection port
sbit B1=P1^1;
sbit C1=P1^2;
sbit D1=P1^3;

sbit buzzer=P1^6; //Pin definition
sbit yanwu=P2^2;
sbit sw1=P2^1;
sbit sw2=P2^0;
sbit hw=P2^3;
#define Coil_A1 {A1=1;B1=0;C1=0;D1=0;}//A phase is powered on and other phases are powered off
#define Coil_B1 {A1=0;B1=1;C1=0;D1=0;}//Phase B is powered on and other phases are powered off
#define Coil_C1 {A1=0;B1=0;C1=1;D1=0;}//C phase is powered on and other phases are powered off
#define Coil_D1 {A1=0;B1=0;C1=0;D1=1;}//D phase is powered on and other phases are powered off
#define Coil_OFF {A1=0;B1=0;C1=0;D1=0;}//All power off

#define TIMELATERNUM 2000 //Stepper motor rotation time

unsigned char zfFlag = 0; //forward and reverse flag
unsigned int timeLater = 0; //time delay

unsigned long time_3ms=0; //Timer count

xdata unsigned char dis0[16];//Define the temporary storage array of the display area
xdata unsigned char dis1[16];

unsigned char ReadTempFlag; //Define read time flag
int temp; //temperature reading value
float temperature; //Actual temperature value

bit disFlag = 0; //Update display

void Init_Timer0(void); //Function declaration

void main (void)
{
Init_Timer0(); //Timer 0 initialization

LCD_Init(); //Initialize LCD
DelayMs(20); //Delay helps stability
LCD_Clear(); //Clear the screen
buzzer = 0;DelayMs(20);buzzer = 1;