stm32f103c8t6湿度报警代码
时间: 2023-08-24 11:06:07 浏览: 39
以下是一个基于STM32F103C8T6的湿度报警代码:
```c
#include "stm32f10x.h"
#include "dht11.h"
#define LED_PORT GPIOC
#define LED_PIN GPIO_Pin_13
#define HUMIDITY_THRESHOLD 70 // 设定湿度阈值
void delay(uint32_t nCount) {
uint32_t i;
for(i = 0; i < nCount; i++) {
}
}
int main(void) {
GPIO_InitTypeDef GPIO_InitStructure;
uint8_t humidity, temperature;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* Configure LED pin */
GPIO_InitStructure.GPIO_Pin = LED_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LED_PORT, &GPIO_InitStructure);
/* Initialize DHT11 sensor */
DHT11_Init();
while(1) {
humidity = temperature = 0;
/* Read humidity and temperature */
DHT11_Read(&humidity, &temperature);
if(humidity >= HUMIDITY_THRESHOLD) {
/* Turn on LED */
GPIO_SetBits(LED_PORT, LED_PIN);
} else {
/* Turn off LED */
GPIO_ResetBits(LED_PORT, LED_PIN);
}
/* Wait for 5 seconds */
delay(7200000);
}
}
```
希望对您有帮助!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)