[Proteus Simulation] [51 Microcontroller] Multi-channel temperature control system

Article directory

  • 1. Function introduction
  • 2. Software design
  • 3. Experimental phenomena
  • Contact the author

1. Function introduction

This project uses Proteus8 to simulate the 51 microcontroller controller, using buttons, LEDs, buzzers, LCD1602, DS18B20 temperature sensor, HC05 Bluetooth module, etc.

The main function:
After the system is running, LCD1602 displays the temperature collected by the first 4 channels by default, and can be switched to display the temperature of the last 4 channels through the K4 key;
The K3 key can be used to enter the threshold setting mode, the K1 and K2 keys can be used to adjust the threshold, and the K4 key can be used to confirm and return to the display interface. The collected 8-channel temperature data is transmitted to the APP for display via Bluetooth; when the 8-channel temperature exceeds or falls below the threshold, the buzzer alarms, and the APP displays which channel has a higher or lower temperature.

2. Software design

/*
Author: Hi Xiaoyi (QQ: 3443792007)

*/


//System data display
void sys_data_show(void)
{<!-- -->
u8 buf[5];
static u8 i=0;
while(1)
{<!-- -->
//Normal mode display
if(sys_ctrl.mode==0)
{<!-- -->
//Page 1
if(sys_ctrl.page==0)
{<!-- -->
//Temperature 1 display
buf[0]=sys_ctrl.temp[0]/100 + 0x30;
buf[1]=sys_ctrl.temp[0] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[0] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(3,0,buf);
//Temperature 2 display
buf[0]=sys_ctrl.temp[1]/100 + 0x30;
buf[1]=sys_ctrl.temp[1] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[1] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(11,0,buf);
//Temperature 3 display
buf[0]=sys_ctrl.temp[2]/100 + 0x30;
buf[1]=sys_ctrl.temp[2] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[2] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(3,1,buf);
//Temperature 4 display
buf[0]=sys_ctrl.temp[3]/100 + 0x30;
buf[1]=sys_ctrl.temp[3] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[3] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(11,1,buf);
}
//Page 2
else
{<!-- -->
//Temperature 5 display
buf[0]=sys_ctrl.temp[4]/100 + 0x30;
buf[1]=sys_ctrl.temp[4] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[4] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(3,0,buf);
//Temperature 6 display
buf[0]=sys_ctrl.temp[5]/100 + 0x30;
buf[1]=sys_ctrl.temp[5] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[5] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(11,0,buf);
//temperature 7 display
buf[0]=sys_ctrl.temp[6]/100 + 0x30;
buf[1]=sys_ctrl.temp[6] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[6] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(3,1,buf);
//temperature 8 display
buf[0]=sys_ctrl.temp[7]/100 + 0x30;
buf[1]=sys_ctrl.temp[7] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[7] 0 + 0x30;
buf[4]='\0';
lcd1602_show_string(11,1,buf);
}

//Serial port transmits temperature data
i + + ;
if(i%1==0)
{<!-- -->
//Temperature 1 display
buf[0]=sys_ctrl.temp[0]/100 + 0x30;
buf[1]=sys_ctrl.temp[0] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[0] 0 + 0x30;
buf[4]='\0';
UART_SendString("\r\
TP1:");
UART_SendString(buf);
UART_SendString("C ");
//Temperature 2 display
buf[0]=sys_ctrl.temp[1]/100 + 0x30;
buf[1]=sys_ctrl.temp[1] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[1] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP2:");
UART_SendString(buf);
UART_SendString("C ");
//Temperature 3 display
buf[0]=sys_ctrl.temp[2]/100 + 0x30;
buf[1]=sys_ctrl.temp[2] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[2] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP3:");
UART_SendString(buf);
UART_SendString("C ");
//Temperature 4 display
buf[0]=sys_ctrl.temp[3]/100 + 0x30;
buf[1]=sys_ctrl.temp[3] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[3] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP4:");
UART_SendString(buf);
UART_SendString("C\r\
");
\t\t\t\t
//Temperature 5 display
buf[0]=sys_ctrl.temp[4]/100 + 0x30;
buf[1]=sys_ctrl.temp[4] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[4] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP5:");
UART_SendString(buf);
UART_SendString("C ");
//Temperature 6 display
buf[0]=sys_ctrl.temp[5]/100 + 0x30;
buf[1]=sys_ctrl.temp[5] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[5] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP6:");
UART_SendString(buf);
UART_SendString("C ");
//temperature 7 display
buf[0]=sys_ctrl.temp[6]/100 + 0x30;
buf[1]=sys_ctrl.temp[6] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[6] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP7:");
UART_SendString(buf);
UART_SendString("C ");
//temperature 8 display
buf[0]=sys_ctrl.temp[7]/100 + 0x30;
buf[1]=sys_ctrl.temp[7] 0/10 + 0x30;
buf[2]='.';
buf[3]=sys_ctrl.temp[7] 0 + 0x30;
buf[4]='\0';
UART_SendString("TP8:");
UART_SendString(buf);
UART_SendString("C\r\
");
}
}
//Threshold setting display
else
{<!-- -->
//temperature lower limit display
lcd1602_show_nums(4,1,sys_ctrl.templ,2,0);
//Temperature upper limit display
lcd1602_show_nums(13,1,sys_ctrl.temph,2,0);

//Threshold setting, data position flashes
switch(sys_ctrl.mode)
{<!-- -->
case 1://lower temperature limit
lcd1602_show_string(4,1," ");
delay_ms(100);
lcd1602_show_nums(4,1,sys_ctrl.templ,2,0);
break;
case 2://temperature upper limit
lcd1602_show_string(13,1," ");
delay_ms(100);
lcd1602_show_nums(13,1,sys_ctrl.temph,2,0);
break;
}
}

break;
}
}


//System data settings
void sys_data_set(void)
{<!-- -->
u8 key=0;
static u8 oneflag=0;
\t
key=KEY_Scan(1);
\t//set up
if(key==KEY3_PRESS)
{<!-- -->
sys_ctrl.mode + + ;
if(sys_ctrl.mode>2)sys_ctrl.mode=1;
if(oneflag==0)
{<!-- -->
oneflag=1;
_parm_set_show();//Parameter setting interface display
}
}
//normal mode
if(sys_ctrl.mode==0)
{<!-- -->
//turn page
if(key==KEY4_PRESS)
{<!-- -->
sys_ctrl.page=!sys_ctrl.page;
if(sys_ctrl.page==1)sys_open_show2();//Page 2
else sys_open_show1();//Page 1
}
}
//Threshold setting mode
else
{<!-- -->
\t\t//add
if(key==KEY1_PRESS)
{<!-- -->
switch(sys_ctrl.mode)
{<!-- -->
case 1://lower temperature limit
sys_ctrl.templ + + ;
if(sys_ctrl.templ>99)sys_ctrl.templ=0;
break;
case 2://temperature upper limit
sys_ctrl.temph + + ;
if(sys_ctrl.temph>99)sys_ctrl.temph=0;
break;
}
}
\t\t//reduce
else if(key==KEY2_PRESS)
{<!-- -->
switch(sys_ctrl.mode)
{<!-- -->
case 1://lower temperature limit
sys_ctrl.templ--;
if(sys_ctrl.templ<0)sys_ctrl.templ=99;
break;
case 2://temperature upper limit
sys_ctrl.temph--;
if(sys_ctrl.temph<0)sys_ctrl.temph=99;
break;
}
}
\t\t//Sure
else if(key==KEY4_PRESS)
{<!-- -->
sys_ctrl.mode=0;
oneflag=0;
if(sys_ctrl.page==1)sys_open_show2();//Page 2
else sys_open_show1();//Page 1
}
}
}

//System function control
void sys_fun_ctrl(void)
{<!-- -->
u8 i=0;
//In normal working mode
if(sys_ctrl.mode==0)
{<!-- -->
//The temperature is higher than the upper limit, or the temperature is lower than the lower limit, the buzzer alarms
for(i=0;i<8;i + + )
{<!-- -->
if(sys_ctrl.temp[i]>sys_ctrl.temph*10 || sys_ctrl.temp[i]<sys_ctrl.templ*10)
{<!-- -->
beep_alarm(10,1000);
if(sys_ctrl.temp[i]>sys_ctrl.temph*10)
{<!-- -->
//Which temperature is too high?
UART_SendString("\r\
th");
UART_SendData(i + 0x31);
UART_SendString("high temperature\r\
");
}
else if(sys_ctrl.temp[i]<sys_ctrl.templ*10)
{<!-- -->
//Which temperature is too low
UART_SendString("\r\
th");
UART_SendData(i + 0x31);
UART_SendString("low temperature\r\
");
}
}
}
}
}


3. Experimental phenomena

Station B demo video: https://space.bilibili.com/444388619




Contact the author

Video address: https://space.bilibili.com/444388619/video
Focus on 51 microcontroller, STM32, domestic 32, DSP, Proteus, arduino, ESP32, Internet of Things software development, PCB design, video sharing, and technical exchanges.