Design of thermal insulation kettle controller based on single-chip microcomputer

Collect and like, your attention is the driving force for my creation

Article directory

    • summary
  • 1. Overall system design
    • 1 Overall circuit design
    • 2 General schematic diagram of the circuit
  • 2. Main program flow chart
    • Simulation circuit diagram
  • 3. Main code
  • 4. Content screenshots
  • 5. Article Table of Contents

Summary

The times are changing rapidly every moment, and science and technology are constantly developing every minute. This is something you and I can see for sure. Many professional machines in modern society are moving closer to more or less sophisticated technologies, becoming more digital and intelligent. So if you want to achieve more intelligent control, whether it is modern scientific agriculture or more complex industries, the adjustment, measurement and control of temperature are crucial for these production-related industries. On the other hand, as living standards continue to improve today, the service industry needs to use a large number of digital intelligent technologies to meet people’s pursuit of high-quality life. The application of advanced electronic technology not only makes people’s lives more convenient, but also reduces resource and energy consumption to a certain extent.
The very traditional temperature measurement system used in the past, the basic principles and measurement methods are slightly behind the current measurement technology. It is conceivable that the errors generated will definitely be more than the more precise and accurate electronic measurement technology today. There are many, and the butterfly effect caused by a little error will lead to a significant reduction in the performance of the entire system or device. Traditional measurement techniques often produce large switching errors caused by multi-point measurements, errors caused by signal conditioning circuits, reading errors, etc. Therefore, this paper designs an intelligent temperature measurement and control alarm system with digital measurement and control. The alarm system uses DS18B20 as the temperature sensor, LCD digital tube for display, and software programming for debugging. The development direction of sensors used in this design is to be more miniaturized, integrated and digital. Looking at real life, I thought of making a thermos cup with a temperature measurement and control alarm system to serve people.
The microcontroller we used this time is an STM32 model, the temperature sensor used is a DS18B20 model, the temperature display device used is a 1602 version of the LCD liquid crystal output device, and the last alarm used is a buzzer. The thermos cup designed using these devices is not only convenient for reading the temperature of the liquid in the cup, but most importantly, it can set the temperature range and alarm when the temperature is not within the set range. It meets people’s requirements for appropriate control of water temperature, especially taking good care of infants and young children. It is easy to operate and small in size. It can also use a bus to connect more than two functional components, which can save voltage and energy. It can be tested even in harsh environments and is very durable.

1. Overall system design

1 Overall circuit design

The device we use to detect temperature is the DS18B20 temperature sensor. Generally, sensors are used in the design circuits of microcontrollers. The DS18B20 temperature sensor has many advantages. It can detect temperature quickly and conveniently, and can also convert the detected temperature into an electrical signal, which fully meets the standards we require.
Figure 2.1 is the overall circuit design block diagram of the temperature measurement and control system of this thermos cup. The microcontroller STM32 is used as the control device, the DS18B20 is used as the temperature detection device, and then the LCD1602 liquid crystal display tube is used to display the measured temperature value. LCD1602 display circuit, DB18B20 temperature sensor, microcontroller interface circuit, oscillation circuit, reset circuit, power supply circuit and alarm circuit constitute the hardware part of the circuit.

2 General schematic diagram of the circuit

The schematic diagram is as follows:

Figure 2-2 Overall design block diagram of the circuit design of the thermos cup temperature automatic control system
In Figure 2.2, there are three independent keys used to adjust the upper and lower limit alarm settings of the thermos cup temperature automatic measurement and control system. The function of the buzzer alarm circuit in the picture is to send an alarm when the temperature is not within the set range. The main program sends instructions at this time so that the LED digital tube will not display the measured temperature value. This sets a limit value for the triggering range of the alarm device. When the temperature is not within the measurement range, no measured value appears on the digital tube, so the alarm device is limited to the trigger range.
We also designed a reset circuit in order to increase manual reset and make it easier to operate. When we want to run and debug the program, we only need to press the button and there is no need to restart the power button.

2. Main program flow chart

The entire system designed in the software part has three modules in addition to the main control program, including a temperature detection module, an information conversion and transmission module and an output module.
DS18B20 has powerful temperature measurement capabilities, and the time required is very short. One measurement can be performed every second, including the time required for signal conversion and transmission results. After the figure data processing program ends, the flow to the main program can always display the temperature on the digital tube, so that you can know whether to adjust the upper and lower limits at the beginning of use. The flow chart is as follows:

Figure 4-1 Keyboard display system circuit diagram
The digital tube can output the upper and lower limits of temperature specified by the user in the current environment. When the detected temperature exceeds the specified upper limit, an alarm will be triggered. At this time, D4 will flash, and then the program will issue a command to open the radiator. Command to cool down. When the temperature drops until the temperature value is lower than the set lower limit temperature value, the alarm will sound. At this time, the D3 light will light up, and the system will issue a command to turn on the heater to heat up. This system can achieve intelligent temperature measurement and control.

Simulation circuit diagram

As shown in Figure 5.1.

Figure 5-1 Simulation circuit diagram

3. Main code

Main program:
source code:
#include <reg52.h> //Call the microcontroller header file
#define uchar unsigned char //Unsigned character macro definition variable range 0~255
#define uint unsigned int //Unsigned integer macro definition variable range 0~65535
#include <intrins.h>
sbit dq = P1^5; //18b20 IO port definition
sbit fengshan = P1^4; //Fan IO port definition
uint temperature; //
bit flag_300ms;
bit flag_lj_en; //Button continuous addition enable
bit flag_lj_3_en; //Enable after pressing the button 3 times to add. The larger the number added, the greater the number.
uchar key_time,key_value; //Intermediate variable used for continuous addition
bit key_500ms;


uchar code table_num[]="0123456789abcdefg";

sbit rs=P1^0; //Register selection signal H: Data register L: Instruction register
sbit rw=P1^1; //Register selection signal H: Data register L: Instruction register
sbit e =P1^2; //Chip select signal falling edge trigger


uchar menu_1; //Menu design variables
uint t_high = 350,t_low = 100;
sbit relay1 = P1^6; //Temperature alarm relay IO port definition
sbit relay2 = P1^3; //Humidity alarm relay IO port definition


/******************************1ms delay function********************** *******/
void delay_1ms(uint q)
{<!-- -->
uint i,j;
for(i=0;i<q;i + + )
for(j=0;j<110;j + + );
}



/****************************************************** *********************
* Name: delay_uint()
* Function: small delay.
* Input: None
* Output: None
*************************************************** *********************/
void delay_uint(uint q)
{<!-- -->
while(q--);
}

/****************************************************** *********************
* Name: write_com(uchar com)
* Function: 1602 command function
* Input: input command value
* Output: None
*************************************************** *********************/
void write_com(uchar com)
{<!-- -->
e=0;
rs=0;
rw=0;
P0=com;
delay_uint(25);
e=1;
delay_uint(100);
e=0;
}

/****************************************************** *********************
* Name: write_data(uchar dat)
* Function: 1602 write data function
* Input: Data that needs to be written to 1602
* Output: None
*************************************************** *********************/
void write_data(uchar dat)
{<!-- -->
e=0;
rs=1;
rw=0;
P0=dat;
delay_uint(25);
e=1;
delay_uint(100);
e=0;
}

/****************************************************** *********************
* Name: write_string(uchar hang,uchar add,uchar *p)
* Function: Change the value of a certain bit in the liquid crystal. If you want the first line and the fifth character to start displaying "ab cd ef", call this function as follows
write_string(1,5,"ab cd ef;")
* Input: row, column, 1602 data needs to be entered
* Output: None
*************************************************** *********************/
void write_string(uchar hang,uchar add,uchar *p)
{<!-- -->
if(hang==1)
write_com(0x80 + add);
else
write_com(0x80 + 0x40 + add);
while(1)
{<!-- -->
if(*p == '\0') break;
write_data(*p);
p + + ;
}
}

/******************************Display specific characters on lcd1602************************ ****/
void write_zifu(uchar hang,uchar add,uchar date)
{<!-- -->
if(hang==1)
write_com(0x80 + add);
else
write_com(0x80 + 0x40 + add);
write_data(date);
}

/******************************Display two decimal numbers on lcd1602************************ *****/
void write_sfm3_18B20(uchar hang,uchar add,uint date)
{<!-- -->
if(hang==1)
write_com(0x80 + add);
else
write_com(0x80 + 0x40 + add);
write_data(0x30 + date/100);
write_data(0x30 + date/10);
write_data('.');
write_data(0x30 + date);
}

/******************************lcd1602 initialization settings****************************** */
void init_1602()
{<!-- -->
write_com(0x38); //
write_com(0x0c);
write_com(0x06);
delay_uint(1000);
write_string(1,0," temp: . ");
write_string(2,0,"H: . L: . ");
write_zifu(1,12,0xdf); //Display degree
write_zifu(2,6, 0xdf); //Display degree
write_zifu(2,14,0xdf); //Display degree

}

/******************************18b20 initialization function****************************** ******/
void init_18b20()
{<!-- -->
bit q;
dq = 1; //Bring the bus high
delay_uint(1); //15us
dq = 0; //Give reset pulse
delay_uint(80); //750us
dq = 1; //Put the bus high and wait
delay_uint(10); //110us
q = dq; //Read 18b20 initialization signal
delay_uint(20); //200us
dq = 1; //Put the bus high and release the bus
}

/****************Write the data in 18b20******************/
void write_18b20(uchar dat)
{<!-- -->
uchar i;
for(i=0;i<8;i + + )
{<!-- --> //Writing data starts with the low bit
dq = 0; //Bring the bus low and the gap begins when writing
dq = dat & amp; 0x01; //Write data to 18b20 bus
delay_uint(5); // 60us
dq = 1; //Release the bus
dat >>= 1;
}
}

/******************Read the data in 18b20******************/
uchar read_18b20()
{<!-- -->
uchar i,value;
for(i=0;i<8;i + + )
{<!-- -->
dq = 0; //Bring the bus low and the read time gap begins
value >>= 1; //read data starting from the low bit
dq = 1; //Release the bus
if(dq == 1) //Start reading and writing data
value |= 0x80;
delay_uint(5); //60us Reading a time gap must be maintained for at least 60us
}
return value; //return data
}

/******************Read the temperature value. What is read is a decimal***************/
uint read_temp()
{<!-- -->
uint value;
uchar low; //If the interrupts are too frequent when reading the temperature, you should turn off the interrupts, otherwise it will affect the timing of 18b20
init_18b20(); //Initialize 18b20
write_18b20(0xcc); //Skip 64-bit ROM
write_18b20(0x44); //Start a temperature conversion command
delay_uint(50); //500us

init_18b20(); //Initialize 18b20
write_18b20(0xcc); //Skip 64-bit ROM
write_18b20(0xbe); //Issue a read register command

low = read_18b20(); //Read temperature low byte
value = read_18b20(); //Read temperature high byte

value <<= 8; //Shift the high bit of temperature to the left by 8 bits
value |= low; //Put the low temperature bit read out into the lower eight bits of value
value *= 0.625; //Convert to temperature value decimal
return value; //Return the read temperature with decimals
}

/******************Timer 0 initialization program******************/
void time_init()
{<!-- -->
EA = 1; //Enable total interrupt
TMOD = 0X01; //Timer 0, timer 1 working mode 1
ET0 = 1; //Enable timer 0 interrupt
TR0 = 1; //Allow timer 0 timing
}

/************************Independent key program******************/
uchar key_can; //Key value

void key() //Independent key program
{<!-- -->
static uchar key_new;
key_can = 20; //Restore by key value
P3 |= 0xf0;
if(key_500ms == 1) //continuous addition
{<!-- -->
key_500ms = 0;
key_new = 1;
}
if((P3 & amp; 0xf0) != 0xf0) //Button pressed
{<!-- -->
delay_1ms(1); //Button debounce
if(((P3 & amp; 0xf0) != 0xf0) & amp; & amp; (key_new == 1))
{<!-- --> //Confirm that the button is pressed
key_new = 0;
switch(P3 & 0xf0)
{<!-- -->
case 0xd0: key_can = 3; break; //Get the k1 key value
case 0xb0: key_can = 2; break; //Get the K2 key value
case 0x70: key_can = 1; break; //Get the k3 key value
}
flag_lj_en = 1; //continuous addition enable
}
}
else
{<!-- -->
if(key_new == 0)
{<!-- -->
key_new = 1;
flag_lj_en = 0; //Turn off continuous addition enable
key_value = 0; //Clear
key_time = 0;
}
}
}

/****************Key display function****************/
void key_with()
{<!-- -->
if(key_can == 1) //Set key
{<!-- -->
menu_1 + + ;
if(menu_1 >= 3)
{<!-- -->
menu_1 = 0;
}
if(menu_1 == 0)
{<!-- -->
write_com(0x0c); //Close the cursor
}
}
if(menu_1 == 1) //Set high temperature alarm
{<!-- -->
if(key_can == 2)
{<!-- -->
if(flag_lj_3_en == 0)
t_high + + ; //The button will be automatically added three times if it is pressed but not released.
else
t_high + = 10; //If the button is pressed and not released, it will automatically increase three times and then it will automatically increase 10 each time.
if(t_high > 990)
t_high = 990;
}
if(key_can == 3)
{<!-- -->
if(flag_lj_3_en == 0)
t_high -- ; //The button will automatically decrease three times if it is pressed and not released.
else
t_high -= 10; //If the button is pressed and not released, it will automatically decrease three times and then automatically decrease by 10 each time.
if(t_high <= t_low)
t_high = t_low + 1;
}
write_sfm3_18B20(2,2,t_high);
write_com(0x80 + 0x40 + 2); //Move the cursor to the seconds digit
write_com(0x0f); //display cursor and flash
}
if(menu_1 == 2) //Set low temperature alarm
{<!-- -->
if(key_can == 2)
{<!-- -->
if(flag_lj_3_en == 0)
t_low + + ; //Automatically add three times if the button is pressed but not released
else
t_low + = 10; //If the button is pressed but not released, it will automatically increase three times and then it will automatically increase 10 each time.
if(t_low >= t_high)
t_low = t_high - 1;
}
if(key_can == 3)
{<!-- -->
if(flag_lj_3_en == 0)
t_low -- ; //The button will automatically decrease three times if it is pressed but not released.
else
t_low -= 10; //If the button is pressed but not released, it will automatically increase three times and then it will automatically increase 10 each time.
if(t_low <= 10)
t_low = 10;
}
write_sfm3_18B20(2,10,t_low);
write_com(0x80 + 0x40 + 10); //Move the cursor to the seconds digit
write_com(0x0f); //display cursor and flash
}
}

/******************Alarm function****************/
void clock_h_l()
{<!-- -->
static uchar value;
if((temperature <= t_low) || (temperature >= t_high))
{<!-- -->
value + + ; //Eliminate the interference when the actual distance changes around the set distance
if(value >= 2)
{<!-- -->
if(temperature <= t_low)
relay1 = 0; //Open relay
if(temperature >= t_high)
relay2 = 0; //Open relay
fengshan = 1;
}
}
else
{<!-- -->
fengshan = 0; //Fan rotation
value = 0;
relay1 = 1; //Close relay
relay2 = 1; //Close relay
}
\t\t\t
}

/******************Main function******************/
void main()
{<!-- -->
init_1602(); //1602 initialization
time_init(); //Initialize timer
while(1)
{<!-- -->
\t\t\t
if(flag_300ms == 1) //process the temperature program once every 300ms
{<!-- -->
flag_300ms = 0;
temperature = read_temp(); //Read the temperature value first
clock_h_l(); //alarm function
write_sfm3_18B20(1,8,temperature);
}
key(); //key program
if(key_can < 10)
{<!-- -->
key_with(); //Set alarm temperature
}
}
}

/****************Timer 0 Interrupt Service Routine******************/
void time0_int() interrupt 1
{<!-- -->
static uchar value;
TH0 = 0x3c;
TL0 = 0xb0; // 50ms
value + + ;
if(value % 6 == 0)
{<!-- -->
flag_300ms = 1; //300ms
value = 0;
}
if(flag_lj_en == 1) //Press the button to enable
{<!-- -->
key_time + + ;
if(key_time >= 10) //500ms
{<!-- -->
key_value + + ;
if(key_value > 3)
{<!-- -->
key_value = 10;
flag_lj_3_en = 1; //After 3 times, increase the value continuously for 1.5 seconds.
}
}
}
}


4. Content screenshots



5. Article directory

Table of contents

Abstract…………………………………………………………………Ⅰ
Abstract……………………………………………………………………Ⅱ
1Introduction………………………………………………………………… 1
2 Overall system design………………………………………………4
2.1 Overall circuit design…………………………………………2
2.2 General schematic diagram of the circuit…………………………………………2
3 Hardware circuits of each part of the system…………………………………………4
3.1 Display circuit………………………………………………………………2
3.2 Interface circuit between temperature sensor and microcontroller…………………………2
3.3 Oscillation circuit……………………………………………………2
3.4 Reset circuit……………………………………………………2
3.5 Alarm circuit………………………………………………………………2
3.6 Keyboard display circuit…………………………………………2
4 Software part design………………………………………………………………4
4.1 Main program flow chart…………………………………………2
4.2 Flow chart of each subroutine…………………………………………2
5 System Test………………………………………………………………4
5.1 System test……………………………………………………2
5.2 Test results……………………………………………………2
6Conclusion………………………………………………………………60
References……………………………………………………………… 61
Acknowledgments………………………………………………………………62
Appendix………………………………………………………………62