基于STM32F103C8T6最小開發板設計的戶外環境監測系統(運用了DHT11模塊,GY-30數字光照模塊,低電平觸發蜂鳴器,OLED顯示)
實踐成果展示:
7.jpg (101.24 KB, 下載次數: 41)
下載附件
2021-8-1 17:36 上傳
6.png (85.33 KB, 下載次數: 53)
下載附件
2021-8-1 17:35 上傳
單片機源程序如下:
- #include "stm32f10x.h"
- #include "usart.h"
- #include "delay.h"
- #include "DTH117.h"
- #include "sys.h"
- #include "bh1750.h"
- #include "oled.h"
- #include "bmp.h"
- #include "Beep.h"
- #include <stdarg.h>
- #include <string.h>
- #include <stdio.h>
- /*
- *讀取溫濕度傳感器DHT11的值,并用串口打印出來
- */
- void clock_init(void);
- u8 temp = 0,humi = 0,Light=0;
- /**************************************************************************
- 函數名:int main(void)
- 參數說明:無
- 返回值:無
- 函數作用:主函數
- ***************************************************************************/
- int main(void)
- {
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- delay_init();
- DHT11_Init();
- clock_init();
- bh1750_Init();
- OLED_Init();
- Beep_Init();
- OLED_Clear();
- Usart1_Init(115200); //初始化串口
- Usart2_Init(115200);
- //UsartPrintf(USART_DEBUG,"HardWare init OK\r\n");
-
-
-
-
- while(1)
- {
- //if (timeCount % 40==0){
- bh1750_ReadOneTime();
- bh1750_ReadContinuous1();
- DHT11_Read_Data(&temp,&humi);
- Light=getValue();
-
- UsartPrintf(USART_DEBUG,"\r\n 溫度:%d,濕度:%d,光照:%d",temp,humi,Light);
- OLED_Clear();
- OLED_ShowCHinese(0,0,0);
- OLED_ShowCHinese(15,0,1);
- OLED_ShowCHinese(30,0,2);
- OLED_ShowCHinese(45,0,3);
- OLED_ShowCHinese(60,0,4);
- OLED_ShowCHinese(75,0,5);
- OLED_ShowCHinese(90,0,6);
- OLED_ShowCHinese(105,0,7);
- OLED_ShowCHinese(0,2,8);
- OLED_ShowCHinese(17,2,9);
- OLED_Show(temp,humi,Light);//屏幕顯示成果
- delay_ms(50);//建議不要低于這個數值
- Beep_Warn(temp,humi);
- //}
- delay_ms(10);
- }
-
- }
- // }
-
- /**************************************************************************
- 函數名:void clock_init(void)
- 參數說明:無
- 返回值:無
- 函數作用:開啟高速外部時鐘,
- ADCCLK設置為12MHZ, SYSCLK設置為72Mhz,PCLK1設置為36MHZ,PKLC2設置為72mhz
- ***************************************************************************/
- void clock_init(void)
- {
- RCC->CR = 0x1010000;
- RCC->CFGR = 0x1DC402;
- }
復制代碼
Keil代碼下載:
代碼.7z
(208.34 KB, 下載次數: 154)
2021-8-1 17:53 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|