Design of threshold alarm LCD display for infrared non-contact human body thermometer based on microcontroller

  • Design requirements:

    This design consists of STC89C52 microcontroller circuit + 1602 liquid crystal display circuit + MLX90614ESF infrared non-contact temperature detection circuit + button circuit + buzzer alarm circuit.

    1. The LCD displays the ambient temperature value and the measured object temperature value detected by MLX90614ESF in real time, with E ambient temperature in the display and O object temperature in the display.

    2. You can set the temperature threshold by pressing the button. If the temperature detected by MLX90614 is higher than the set threshold, the buzzer will alarm. Otherwise, the buzzer will not alarm.

  • Introduction

1.1 Background of the topic and its significance

The infrared thermometer uses non-contact means, breaking through the traditional temperature measurement mode. It does not disturb the temperature distribution field of the measured object. It has high temperature resolution, fast response speed, wide temperature measurement range, good stability, and can measure the ambient temperature at the same time. and target temperature characteristics. This design intends to use the 51 microcontroller as the control core, which is responsible for controlling the startup temperature measurement, receiving measurement data, calculating the temperature value, and controlling the playback and display process based on the obtained key value. It is mainly composed of optical systems, photoelectric detectors, signal amplifiers and 51 microcontroller signal processing , display output and other parts are implemented. This topic can test my level of learning and mastery of microcontrollers and their peripheral circuits and software programming, computer-aided design software, etc., so that my application capabilities in hardware design and implementation, auxiliary design software, etc. can be comprehensively trained and improved.

1.2 Development and current situation of microcontroller applications

In the mid-1950s, the world’s first computer using digital computing was developed in a famous university laboratory in the United States. Since then, electronic computers have grown rapidly, mainly in the following four periods: The first generation was controlled by electron tubes The second generation is the era of transistor control, the third generation is the era of integrated circuit control, and the fourth generation is the era of very large scale integrated circuit control. The computers currently in use all use the fourth generation VLSI control method. Because they have very good performance, they are mainly characterized by high cost performance, small size, and stable performance. Exceptionally, the development of computers tends to become more powerful and larger. Minimization, system stability and functional user-friendliness. Miniaturization is the main research direction of computers at present. The main research is to integrate the components of the controller on an integrated board. Therefore, a wide range of large-scale micro-electronic computers with integrated controllers – referred to as single boards – have been born. Small digital controller, abbreviated as MCU in English, because MCU is mainly used in high-performance intelligent electronic products, mainly because most products are systems that contain embedded devices. Nowadays, the companies around the world that are capable of manufacturing digital controller MCUs are mainly large international companies. There are also some domestic listed companies that produce and research digital controller MCUs. The microcontrollers produced by each company have their own characteristics. The main ones are The application situations are also different.

1.3 The main research content and structure arrangement of this article

  1. . Mainly introduces the subject background of this design and the research status at home and abroad;
  2. . Mainly explains the selection of system solutions;

Chapter 3. Mainly introduces the composition and use of hardware circuits;

Chapter 4. Mainly introduces software design;

Chapter 5. Mainly introduces hardware debugging.

3.1 System functional analysis and architecture design

3.1.1 System function analysis

This design consists of STC89C52 microcontroller circuit + 1602 liquid crystal display circuit + MLX90614ESF infrared non-contact temperature detection circuit + button circuit + buzzer alarm circuit.

1. The LCD displays the ambient temperature value and the measured object temperature value detected by MLX90614ESF in real time, with E ambient temperature in the display and O object temperature in the display.

2. You can set the temperature threshold by pressing the button. If the temperature detected by MLX90614 is higher than the set threshold, the buzzer will alarm. Otherwise, the buzzer will not alarm.

3.1.2 Overall system structure

The specific block diagram of this system is shown below:

System schematic block diagram

3.2 Design of module circuit

3.2.1 STC89C52 microcontroller core system circuit design

STC89C52RC is a low-power, high-performance CMOS 8-bit microcontroller produced by STC Company, with 8K bytes of system programmable Flash memory. STC89C52 uses the classic MCS-51 core, but has made many improvements to make the chip have functions that traditional 51 microcontrollers do not have. On a single chip, it has a smart 8-bit CPU and in-system programmable Flash, making the STC89C52 a highly flexible and ultra-effective solution for many embedded control application systems. Has the following standard functions: 8k bytes Flash, 512 bytes RAM, 32-bit I/O port line, watchdog timer, built-in 4KB EEPROM, MAX810 reset circuit, 3 16-bit timers/counters, 4 external interrupts , a 7-vector 4-level interrupt structure (compatible with the traditional 51-vector 2-level interrupt structure), full-duplex serial port. In addition, STC89C52 can reduce to 0Hz static logic operation and supports 2 software-selectable power-saving modes. In idle mode, the CPU stops working, allowing RAM, timers/counters, serial ports, and interrupts to continue working. In the power-down protection mode, the RAM contents are saved, the oscillator is frozen, and all work of the microcontroller stops until the next interrupt or hardware reset. The maximum operating frequency is 35MHz, 6T/12T optional.

1. The main features of STC89C52 are as follows:

(1) 8K bytes program storage space;

(2) 512 bytes of data storage space;

(3) Built-in 4K bytes EEPROM storage space;

(4) You can directly use the serial port to download.

2. The main parameters of STC89C52 are as follows:

(1) Enhanced 8051 microcontroller, 6 clocks/machine cycle and 12 clocks/machine cycle can be selected arbitrarily, and the instruction code is fully compatible with traditional 8051;

(2) Working voltage: 5.5V~3.3V (5V microcontroller)/3.8V~2.0V (3V microcontroller);

(3) Working frequency range: 0~40MHz, equivalent to 0~80MHz of ordinary 8051, the actual working frequency can reach 48MHz;

(4) The user application space is 8K bytes;

(5) On-chip integrated 512-byte RAM;

(6) General-purpose I/O ports (32), after reset: P1/P2/P3 are quasi-bidirectional ports/weak pull-ups. Port P0 is an open-drain output. When used for bus expansion, there is no need to add a pull-up resistor. When used as an I/O port, a pull-up resistor is required;

(7) ISP (In-System Programmable)/IAP (In-Application Programmable), no special programmer or special emulator is required, user programs can be downloaded directly through the serial port (RxD/P3.0, TxD/P3.1), A slice can be completed in seconds;

(8) With EEPROM function;

(9) A total of 3 16-bit timers/counters. That is, timers T0, T1, T2;

(10) 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;

(11) Universal asynchronous serial port (UART), timer software can also be used to implement multiple UARTs;

(12) Working temperature range: -40~+85℃ (industrial grade)/0~75℃ (commercial grade);

(13) PDIP encapsulation.

3. STC89C52 microcontroller related pin description:

(1) VCC: supply voltage.

(2) GND: Ground.

(3) P3.0 RXD (serial input port)

(4) P3.1 TXD (serial output port)

(5) P3.2 /INT0 (external interrupt 0)

#include "1602.h"
#include "delay.h"
#include <intrins.h>

#define uchar unsigned char
#define uint unsigned int

#define _NOP() _nop_()
sbit RS = P2^4; //Define port
sbit RW = P2^5;
sbit EN = P2^6;

#define DataPort P0
#define DataPIN P0

#define CLR_RS (RS=0)
#define SET_RS (RS=1)
#define CLR_RW (RW=0)
#define SET_RW (RW=1)
#define CLR_EN (EN=0)
#define SET_EN (EN=1)

/*
LcdReset(); //LCD1602 initialization
DelayMs(10);
sprintf(temp,"11111111111111111");//Update display
DispStr(0,0,(unsigned char *)temp);//Print display
sprintf(temp,"11111111111111111");//Update display
DispStr(0,1,(unsigned char *)temp);//Print display
*/
/**********************************************
Function name: DispStr
Function: Let the LCD continuously display a string starting from a certain position
Parameters: x--column coordinates of position
          y--the row coordinate of the position
          ptr--pointer to the storage location of the string
Return value: None
*************************************************/
void DispStr(uchar x,uchar y,uchar *ptr)
{
    uchar *temp;
    uchar i,n = 0;
    
    temp = ptr;
    while(*ptr + + != '\0') n + + ; //Calculate the number of valid characters in the string
    
    for (i=0;i<n;i + + )
    {
        Disp1Char(x + + ,y,temp[i]);
        if (x == 0x10)
        {
            break;
        }
    }
}

/**********************************************
Function name: DispNchar
Function: Let the LCD display N characters continuously starting from a certain position
Parameters: x--column coordinates of position
          y--the row coordinate of the position
          n--Number of characters
          ptr--pointer to character storage location
Return value: None
*******************************************
void DispNChar(uchar x,uchar y,uchar n,uchar *ptr)
{
    uchar i;
    
    for (i=0;i<n;i + + )
    {
        Disp1Char(x + + ,y,ptr[i]);
        if (x == 0x10)
        {
           x = 0;
            y^= 1;
        }
    }
}
*/
/**********************************************
Function name: LocateXY
Function: Input the coordinate information of the displayed character position to the LCD
Parameters: x--column coordinates of position
          y--the row coordinate of the position
Return value: None
*********************************************/
void LocateXY(uchar x,uchar y)
{
    uchar temp;

    temp = x &0x0f;
    y&= 0x01;
    if(y) temp |= 0x40; //If in line 2
    temp |= 0x80;

    LcdWriteCommand(temp,1);
}

/**********************************************
Function name: Disp1Char
Function: Display a character at a certain position
Parameters: x--column coordinates of position
          y--the row coordinate of the position
          data--Character data displayed
Return value: None
*********************************************/
void Disp1Char(uchar x,uchar y,uchar data1)
{
    LocateXY(x, y);
    LcdWriteData(data1);
}

/************************************************
Function name: LcdReset
Function: Reset the 1602 LCD module
Parameters: None
Return value: None
*********************************************/
void LcdReset(void)
{
// DataDir = 0xFF; //Set the data port to output state
    LcdWriteCommand(0x38, 0); //Specified reset operation
    DelayMs(5);
    LcdWriteCommand(0x38, 0);
    DelayMs(5);
    LcdWriteCommand(0x38, 0);
    DelayMs(5);

    LcdWriteCommand(0x38, 1); //Display mode setting
    LcdWriteCommand(0x08, 1); //display off
    LcdWriteCommand(0x01, 1); //Display clear screen
    LcdWriteCommand(0x06, 1); //The whole does not move when writing characters
    LcdWriteCommand(0x0c, 1); //Display on, no cursor, no flashing
}

/*------------------------------------------------
                Clear screen function
----------------------------------------*/
void LcdClear(void)
{
LcdWriteCommand(0x01,1);
DelayMs(5);
}

/**********************************************
Function name: LcdWriteCommand
Function: Write commands to the LCD module
Parameters: cmd--command,
          chk--the flag indicating whether to judge busy, 1: judge busy, 0: not judge
Return value: None
*********************************************/
void LcdWriteCommand(uchar cmd,uchar chk)
{

    if (chk) WaitForEnable(); // Detect busy signal?
    
    CLR_RS;
    CLR_RW;
    _NOP();

    DataPort = cmd; //Write the command word to the data port
    _NOP();
    
    SET_EN; //Generate enable pulse signal
    _NOP();
    _NOP();
    CLR_EN;
}

/**********************************************
Function name: LcdWriteData
Function: Write display data to the current address of the LCD display
Parameters: data--display character data
Return value: None
*********************************************/
void LcdWriteData(uchar data1)
{
    WaitForEnable(); //Wait for the LCD to not be busy
    SET_RS;
    CLR_RW;

    SET_EN;
\t
_NOP();
    DataPort = data1; //Write display data to the data port
    _NOP();
                //Generate enable pulse signal
    _NOP();
    _NOP();
    CLR_EN;
}

/**********************************************
Function name: WaitForEnable
Function: Wait for 1602 LCD to complete internal operation
Parameters: none
Return value: None
*********************************************/
void WaitForEnable(void)
{
  unsigned int later=0;
DataPort=0xff;
    CLR_RS;
    SET_RW;
    _NOP();
    SET_EN;
    _NOP();
    _NOP();
// while((DataPIN & amp;Busy)!=0);
    while(((DataPIN & amp;0x80)!=0) & amp; & amp;(later<1000)) //Detect busy flag
    {
      DelayUs2x(2);
      later + + ;
    }
    CLR_EN;
// DataDir|=0xFF; //Switch P4 port to output state
}

image.png

image.png

image.png

Articles based on this are widely circulated