本设计:
基于Labview的空气质量监测系统设计_STM32F103C8T6(程序+原理图+PCB)
原理图:Altium Designer
程序编译器:keil 5
编程语言:C语言
编号C0028
C0028 网盘链接
本设计通过下位机和上位机结合来实现系统监测的各项功能。上位机软件使用Labview虚拟仪器进行设计,下位机采用STM32F103C8T6单片机控制。下位机主要有温湿度传感器、光照传感器、显示器、无线传输模块等组成。温湿度传感器可以采集室内温湿度,然后反馈给单片机,单片机处理后在显示器上显示相关参数。同时,光照传感器的工作原理与温湿度模块相同。
1.上位机实现功能
通信波特率设置为115200,上位机通过USB无线串口转NRF24L01模块来接受下位机传来的环境参数信息,实时显示当前温湿度和光照强度,当环境参数大于设定阈值时,上位机显示界面中的报警指示灯亮起,同时下位机的蜂鸣器报警模块会响起,启动降温模块。当环境参数回归正常时,报警自动取消,降温模块停止工作。
2.下位机实现功能
单片机STM32F103C8T6通过DHT11温湿度传感器和光敏二极管分别采集当前环境中的温湿度和光强信息,通过OLED屏进行实时显示,并且将采集到的环境数据通过NRF24L01无线通信模块实时发送至上位机端。当环境参数大于设定阈值时,蜂鸣器模块进行报警,雾化器模块进行降温处理。当环境参数回归正常时,报警自动取消,雾化器模块停止工作。
原理图(提供源文件):
PCB(提供源文件):
源程序(提供源文件):
https://docs.qq.com/sheet/DS0xIa0llTmtNakRW
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "oled.h"
#include "adc.h"
#include "24l01.h"
#include "dht11.h"
#define beep PAout(11)// PA11
#define wet PAout(12)// PA12
#define set_jia PCin(13)// PC13温度阈值加
#define set_jian PCin(15)// PC15温度阈值减
uint16_t Light_adc,Light,Light_shi,Light_ge;
u8 temperature,Temp_shi,Temp_ge;
u8 humidity,Humi_shi,Humi_ge;
u8 Temp_set=26,Temp_set_shi,Temp_set_ge;
void System_Init(void);
void CHinese(u8 x,u8 y,u8 no,u8 z);
void beep_wet_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PA端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;//端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化
}
void key_init()
{
// +//PC13
// -//PC15
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能PC端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15;//端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//设置成上拉输入
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); //根据设定参数初始化
}
int main(void)
{
u8 tmp_buf[33];
u8 TX_buf[32];
u8 RX_buf[32];
System_Init();
while(1)
{
if(set_jia==0)
{
Temp_set++;
if(Temp_set>40) Temp_set=26;
while(!set_jia);
}
if(set_jian==0)
{
Temp_set--;
if(Temp_set<16) Temp_set=26;
while(!set_jian);
}
DHT11_Read_Data(&temperature,&humidity);//读取温湿度值
Temp_shi=temperature/10;
Temp_ge=temperature%10;
Humi_shi=humidity/10;
Humi_ge=humidity%10;
Temp_set_shi=Temp_set/10;
Temp_set_ge=Temp_set%10;
Light_adc = Get_Adc_Average(ADC_Channel_1,10);//0.0244
Light=100-Light_adc*0.0244;
Light_shi=Light/10;
Light_ge=Light%10;
OLED_ShowString(2,0,"Index",16);
OLED_ShowString(52,0,"Value",16);
OLED_ShowString(100,0,"Set",16);
CHinese(8,2,13,0);
CHinese(24,2,14,0);
OLED_ShowString(40,2,":",16);
CHinese(8,4,15,0);
CHinese(24,4,16,0);
OLED_ShowString(40,4,":",16);
CHinese(8,6,17,0);
CHinese(24,6,18,0);
OLED_ShowString(40,6,":",16);
OLED_ShowNum(62,2,Light,2,16);
OLED_ShowString(78,2,"%",16);
OLED_ShowNum(62,4,temperature,2,16);//显示温度
OLED_ShowString(78,4,"C",16);
OLED_ShowNum(100,4,Temp_set,2,16);//显示温度阈值
OLED_ShowString(116,4,"C",16);
OLED_ShowNum(62,6,humidity,2,16);//显示湿度
OLED_ShowString(78,6,"%",16);
NRF24L01_TX_Mode();
if(NRF24L01_TxPacket(TX_buf)==TX_OK)
{
TX_buf[0]=8;//发送的总字节数
TX_buf[1]=Light_shi+'0';
TX_buf[2]=Light_ge+'0';
TX_buf[3]=Temp_shi+'0';
TX_buf[4]=Temp_ge+'0';
TX_buf[5]=Humi_shi+'0';
TX_buf[6]=Humi_ge+'0';
TX_buf[7]=Temp_set_shi+'0';
TX_buf[8]=Temp_set_ge+'0';
TX_buf[9]=0x0A;//换行
}
if(temperature>Temp_set)
{
beep=1;
wet=1;
}
else
{
beep=0;
wet=0;
}
}
}
void System_Init()
{
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
beep_wet_init();
Adc_Init();
DHT11_Init();
key_init();
OLED_Init(); //初始化OLED
OLED_Clear();
NRF24L01_Init(); //初始化NRF24L01
while(NRF24L01_Check())
{
OLED_ShowString(0,0,"NRF24L01 Error",16);
delay_ms(200);
OLED_Clear();
delay_ms(200);
}
OLED_ShowString(0,0,"NRF24L01 OK",16);
delay_ms(500);
OLED_Clear();
CHinese(0,1,0,0);//行0246
CHinese(16,1,1,0);
CHinese(32,1,2,0);
CHinese(48,1,3,0);
CHinese(64,1,4,0);
CHinese(80,1,5,0);
CHinese(96,1,6,0);
CHinese(112,1,7,0);
CHinese(48,3,8,0);
CHinese(64,3,9,0);
delay_ms(3000);
OLED_Clear();
}
void CHinese(u8 x,u8 y,u8 no,u8 z)
{
unsigned char Hzk1[][16]={
{0x10,0x94,0x53,0x32,0x1E,0x32,0x52,0x10,0x00,0x7E,0x42,0x42,0x42,0x7E,0x00,0x00},
{0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00},//"智",0
{0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00},
{0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00},//"能",1
{0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00},
{0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00},//"环",2
{0x10,0x10,0xFF,0x10,0x10,0x20,0xA4,0xAC,0xB5,0xA6,0xB4,0xAC,0xA4,0x20,0x20,0x00},
{0x10,0x30,0x1F,0x08,0x88,0x80,0x4F,0x3A,0x0A,0x0A,0x7A,0x8A,0x8F,0x80,0xE0,0x00},//"境",3
{0x00,0x00,0x7E,0x00,0x00,0xFF,0x00,0x40,0x30,0x0F,0x04,0x14,0x64,0x04,0x00,0x00},
{0x40,0x40,0x7E,0x42,0x42,0x7E,0x42,0x42,0x42,0x7E,0x42,0x42,0x7E,0x40,0x40,0x00},//"监",4
{0x10,0x60,0x02,0x8C,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0xFF,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x80,0x47,0x30,0x0F,0x10,0x27,0x00,0x47,0x80,0x7F,0x00,0x00},//"测",5
{0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x48,0x28,0x09,0x0E,0x28,0x48,0xA8,0x18,0x00},
{0x02,0x42,0x81,0x7F,0x00,0x40,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00},//"控",6
{0x40,0x50,0x4E,0x48,0x48,0xFF,0x48,0x48,0x48,0x40,0xF8,0x00,0x00,0xFF,0x00,0x00},
{0x00,0x00,0x3E,0x02,0x02,0xFF,0x12,0x22,0x1E,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00},//"制",7
{0x00,0x00,0x22,0x32,0x2A,0xA6,0xA2,0x62,0x21,0x11,0x09,0x81,0x01,0x00,0x00,0x00},
{0x00,0x42,0x22,0x13,0x0B,0x42,0x82,0x7E,0x02,0x02,0x0A,0x12,0x23,0x46,0x00,0x00},//"系",8
{0x20,0x30,0xAC,0x63,0x30,0x00,0x88,0xC8,0xA8,0x99,0x8E,0x88,0xA8,0xC8,0x88,0x00},
{0x22,0x67,0x22,0x12,0x12,0x80,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x40,0x71,0x00},//"统",9
{0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,0x40,0xC0,0x50,0x48,0x46,0x40,0x40,0x00},
{0x80,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00},//"光",13
{0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00},
{0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00},//"强",14
{0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},//"温",15
{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00},
{0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},//"度",16
{0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00},
{0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00},//"湿",17
{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00},
{0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},//"度",18
};
u8 t,adder=0;
OLED_Set_Pos(x,y);
for(t=0;t<16;t++)
{
if(z==0)
OLED_WR_Byte(Hzk1[2*no][t],OLED_DATA);
if(z==1)
OLED_WR_Byte(~Hzk1[2*no][t],OLED_DATA);
adder+=1;
}
OLED_Set_Pos(x,++y);
for(t=0;t<16;t++)
{
if(z==0)
OLED_WR_Byte(Hzk1[2*no+1][t],OLED_DATA);
if(z==1)
OLED_WR_Byte(~Hzk1[2*no+1][t],OLED_DATA);
adder+=1;
}
}
全部资料如下:
下载链接看文章开题