功能介绍:
0.本系统采用STM32F103C8T6作为单片机
1.采用LCD1602可以实时显示烤箱的温度和时间
2.蜂鸣器和LED组成的声光报警系统,当烤箱时间达到时作为报警提示装置
3.设计WiFi模块作为无线通信,可与手机进行数据传输
4.温度检测模块采用的是max6675+热电偶,测量温度可达几百度
5.继电器+功率电阻来模拟烤箱加热的过程
6.采用DC002作为电源接口可直接输入5V给整个系统供电
原理图:
PCB:
主程序:
#define __MIAN_C
#include "main.h"
// 局部变量,用于保存转换计算后的电压值
CreatByte Flag;
enum _MODE_DF_ dispMode;
char dis[16];
uint16_t tempBuf = 0;
float f_temp = 0;
volatile uint16_t setIndex = 0;
volatile uint16_t setTemp = 50;
volatile int16_t timeLimit[2] = {5, 0}; //默认5分钟
volatile int16_t timeLimitBuf[2] = {5, 0}; //用于缓存上次的定时时间
PID_Calibration_Def PID_Calibration;
PID_State_Def PID_State;
int main(void)
{
setFlag = 0;
// 使用HSI,SYSCLK = 4M * RCC_PLLMul_x, x:[2,3,...16],最高是64MH
HSI_SetSysClock(RCC_PLLMul_2); //使用内部8MHz晶振,并设置PLL输出为8MHz
// 端口初始化
GPIO_Config();
GENERAL_TIM_Init();
USART_Config();
MAX6675_GPIO_Init();
DelayMs(1000);
printf("AT+CIPMUX=1\r\n"); //打开多连接
DelayMs(1000);
printf("AT+CIPSERVER=1,8080\r\n"); //建立服务 端口号为8080
DelayMs(1000);
Key_GPIO_Config();
DelayMs(200);
LCD_GPIO_Init();
LCD_Init();
LCD_Clear();
DelayMs(200);
Set_PID_Parameter();
while (1)
{
if (refreshFlag == 1)
{
refreshFlag = 0;
if (startFlag == 1) //开启加热
{
PID_State.actual = f_temp; //当前温度
PID_State.target = setTemp; //目标温度
PID_State = PID_Iterate(PID_Calibration, PID_State);
if ((f_temp > setTemp - 5) && (f_temp < setTemp + 5)) //在范围内
{
BUZZER_OFF;
}
else
{
BUZZER_ON;
}
}
else
{
PID_State.output = 0;
BUZZER_OFF;
}
if (setFlag == 0)
{
RefreshData();
DispSet(setIndex);
}
}
if (sendFlag == 1)
{
sendFlag = 0;
TIM_ITConfig(GENERAL_TIM2, TIM_IT_Update, DISABLE);
SendData();
TIM_ITConfig(GENERAL_TIM2, TIM_IT_Update, ENABLE);
}
KeyProcess();
}
}
void Set_PID_Parameter(void)
{
PID_Calibration.kp = 20;
PID_Calibration.ki = 2;
PID_Calibration.kd = 10;
PID_State.actual = 0;
PID_State.target = 50;
PID_State.integral = 0;
PID_State.last_error = 0;
PID_State.previous_error = 0;
PID_State.output = 0;
}
void RefreshData(void)
{
uint8_t i;
for (i = 0; i < 10; i++) //采集10次数据
{
//获取温度
do
{
tempBuf = ReadMAX6675();
} while (GetCurrentTemp(tempBuf));
tempBuf &= 0x7ff8;
tempBuf >>= 3; //取D14~D3有效数据
f_temp = f_temp + (float)tempBuf * 1023.75 / 4096 - 0; //减去合适的环境温度
DelayMs(2);
}
f_temp = f_temp / 10;
sprintf(dis, "Temp: %6.1f", f_temp);
LCD_DispStr(0, 1, dis);
LCD_DispOneChar(12, 1, 0xdf);
LCD_DispOneChar(13, 1, 'C');
}
void SendData(void)
{
printf("AT+CIPSEND=0,29\r\n"); //发送32位数据
DelayMs(100);
printf("SetTemp:%4d'C Temp:%6.1f'C\r\n", setTemp, f_temp); //串口发送
DelayMs(100);
}
void DispSet(uint8_t setIndex)
{
sprintf(dis, "S:%4d", setTemp);
LCD_DispStr(0, 0, dis);
LCD_DispOneChar(6, 0, 0xdf);
LCD_DispOneChar(7, 0, 'C');
sprintf(dis, "%02d:%02d", timeLimit[0], timeLimit[1]);
LCD_DispStr(9, 0, dis); //显示定时时间
if (startFlag == 1) //开启状态
{
LCD_DispOneChar(15, 0, 'O');
}
else //关闭状态
{
LCD_DispOneChar(15, 0, 'C');
}
if (setIndex == 1)
{
LCD_SetCursor(10, 0, 1);
}
else if (setIndex == 2)
{
LCD_SetCursor(13, 0, 1);
}
}
/*********************************************END OF FILE**********************/