本設(shè)計(jì):
基于Labview的空氣質(zhì)量監(jiān)測(cè)系統(tǒng)設(shè)計(jì)_STM32F103C8T6(程序+原理圖+PCB)
原理圖:Altium Designer
程序編譯器:keil 5
編程語(yǔ)言:C語(yǔ)言
編號(hào)C0028
C0028 網(wǎng)盤鏈接
本設(shè)計(jì)通過(guò)下位機(jī)和上位機(jī)結(jié)合來(lái)實(shí)現(xiàn)系統(tǒng)監(jiān)測(cè)的各項(xiàng)功能。上位機(jī)軟件使用Labview虛擬儀器進(jìn)行設(shè)計(jì),下位機(jī)采用STM32F103C8T6單片機(jī)控制。下位機(jī)主要有溫濕度傳感器、光照傳感器、顯示器、無(wú)線傳輸模塊等組成。溫濕度傳感器可以采集室內(nèi)溫濕度,然后反饋給單片機(jī),單片機(jī)處理后在顯示器上顯示相關(guān)參數(shù)。同時(shí),光照傳感器的工作原理與溫濕度模塊相同。
1.上位機(jī)實(shí)現(xiàn)功能
通信波特率設(shè)置為115200,上位機(jī)通過(guò)USB無(wú)線串口轉(zhuǎn)NRF24L01模塊來(lái)接受下位機(jī)傳來(lái)的環(huán)境參數(shù)信息,實(shí)時(shí)顯示當(dāng)前溫濕度和光照強(qiáng)度,當(dāng)環(huán)境參數(shù)大于設(shè)定閾值時(shí),上位機(jī)顯示界面中的報(bào)警指示燈亮起,同時(shí)下位機(jī)的蜂鳴器報(bào)警模塊會(huì)響起,啟動(dòng)降溫模塊。當(dāng)環(huán)境參數(shù)回歸正常時(shí),報(bào)警自動(dòng)取消,降溫模塊停止工作。
2.下位機(jī)實(shí)現(xiàn)功能
單片機(jī)STM32F103C8T6通過(guò)DHT11溫濕度傳感器和光敏二極管分別采集當(dāng)前環(huán)境中的溫濕度和光強(qiáng)信息,通過(guò)OLED屏進(jìn)行實(shí)時(shí)顯示,并且將采集到的環(huán)境數(shù)據(jù)通過(guò)NRF24L01無(wú)線通信模塊實(shí)時(shí)發(fā)送至上位機(jī)端。當(dāng)環(huán)境參數(shù)大于設(shè)定閾值時(shí),蜂鳴器模塊進(jìn)行報(bào)警,霧化器模塊進(jìn)行降溫處理。當(dāng)環(huán)境參數(shù)回歸正常時(shí),報(bào)警自動(dòng)取消,霧化器模塊停止工作。
原理圖(提供源文件):
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端口時(shí)鐘
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); //根據(jù)設(shè)定參數(shù)初始化
}
void key_init()
{
// +//PC13
// -//PC15
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //使能PC端口時(shí)鐘
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15;//端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//設(shè)置成上拉輸入
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度為50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); //根據(jù)設(shè)定參數(shù)初始化
}
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;//發(fā)送的總字節(jié)數(shù)
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(); //延時(shí)函數(shù)初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級(jí)分組為組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
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},//"環(huán)",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},//"監(jiān)",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},//"測(cè)",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},//"統(tǒng)",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},//"強(qiáng)",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;
}
}
全部資料如下:
下載鏈接看文章開題