温湿度获取通过433通信发出去
单片机源程序如下:
- /////////////////////////////////////////////////////////////////////////////////////////////
- /* Development project : Smart Home System */
- /* Version number : V1.0 */
- /* Development board model: STM32F103ZET6 */
- /* Author : Dobe_Li */
- /////////////////////////////////////////////////////////////////////////////////////////////
- #include "public.h"
- #include "stmflash.h"
- #include "oled.h"
- #include "sht30_1.h"
- #include "led.h"
- #include "timer.h"
- #define FLASH_SAVE_ADDR 0X08070000 //设置FLASH 保存地址(必须为偶数,且其值要大于本代码所占用FLASH的大小+0X08000000)
- sht30_data sht30_2_data;
- uint8_t warning[9];
- uint8_t W[8]="warning";
- int main(void)
- {
- uint8_t temp[3];
- uint8_t T[5]="Temp:";
- uint8_t H[5]="Huim:";
-
- SystemInit();//系统时钟初始化
- Usart1_Init();//串口1初始化
- OLED_Init();//OLED屏初始化
- Hc12_init(); //433通信模块初始化
- Sht30_Init();//温湿度传感器初始化
- LED_Init();
- TIM3_Int_Init(8999,7199);
- warning[0]='S';
- warning[1]='Z';
- warning[2]='N';
- warning[3]='W';
- STMFLASH_Read(FLASH_SAVE_ADDR,(u16*)temp,2);
- warning[4]=temp[0];
- warning[5]=temp[1];
- warning[7]='D';
- while(1)
- {
- sht30_2_data=Get_sht30_data();
- OLED_Clear();
- OLED_ShowString(20,3,T);
- OLED_ShowNum(65,3,sht30_2_data.temperature,4,16);
- OLED_ShowChar(100,3,'C');
- OLED_ShowString(20,5,H);
- OLED_ShowNum(65,5,sht30_2_data.humidity,4,16);
- OLED_ShowChar(100,5,'%');
- if(sht30_2_data.temperature>=40)
- {
- warning[6]='3';
- OLED_ShowString(20,2,W);
- Usart3_sendstring(warning);
- }
- if(sht30_2_data.temperature<=0)
- {
- warning[6]='0';
- OLED_ShowString(20,2,W);
- Usart3_sendstring(warning);
- }
- if(sht30_2_data.humidity<=20)
- {
- warning[6]='4';
- OLED_ShowString(20,2,W);
- Usart3_sendstring(warning);
- }
- if(sht30_2_data.humidity>=70)
- {
- warning[6]='7';
- OLED_ShowString(20,2,W);
- Usart3_sendstring(warning);
- }
- USART3_DataProcess(); //对指令处理并给主机发送数据
- }
- }
复制代码
所有资料51hei提供下载:
HT.rar
(87.38 KB, 下载次数: 111)
|