实现温湿度监测和控制抽水机在土壤湿度低于一定门限值是自动浇水
单片机源程序如下:
- #include "stm32f10x.h"
- #include "bsp_SysTick.h"
- #include "bsp_usart1.h"
- #include "bsp_adc.h"
- #include "GPIO_map.h"
- #include "bsp_dht11.h"
- #include "bsp_eeprom.h"
- #include "bsp_relay.h"
- #include "touch.h"
- #include "lcd.h"
- #include "sys.h"
- #include "caculator.h"
- #include "bsp_Timbase.h"
- #include "bsp_key.h"
- extern __IO uint16_t ADC_ConvertedValue;
- extern DHT11_Data_TypeDef DHT11_Data;
- extern unsigned int Task_Delay[NumOfTask];
- extern void KEY_Scan(void);
- extern void KEY_Init(void);
- u16 Temp,Hum,Soil_hum;
- u16 Soil_hum = 100;
- u16 Hum_limit = 98;
- void Load_Drow_Dialog(void)
- {
- LCD_Clear(WHITE);//清屏
- POINT_COLOR=BLUE;//设置字体为蓝色
- LCD_ShowString(216,0,"RST");//显示清屏区域
- POINT_COLOR=RED;//设置画笔蓝色
- }
- int main(void)
- {
- /* 配置SysTick 为10us中断一次 */
- // int v = 0;
- Relay_Init();
- KEY_Init();
- SystemInit();
- SysTick_Init();
- NVIC_Configuration();
- ADC1_Init();
- USART1_Config();
- DHT11_GPIO_Config();
- // FLASH_Unlock();
- // EE_INIT();
- // EE_READ_ACC_OFFSET();
- LCD_Init();
- // CA_Init();
- GUI_Init();
- Delay_ms(100);
- // Touch_Init();
- Delay_ms(1500);
- //Load_Drow_Dialog();
- TIM2_Configuration();
- TIM2_NVIC_Configuration();
-
- while(1)
- {
-
- if(Soil_hum < Hum_limit)
- {
- GPIO_SetBits(GPIOC,GPIO_Pin_11);
- }
- else GPIO_ResetBits(GPIOC,GPIO_Pin_11);
- if( Read_DHT11(&DHT11_Data)==SUCCESS ) //温度采集并显示
- {
- Temp = DHT11_Data.temp_int;
- LCD_Show2Num(95,60,Temp,2,16,0);
- Hum = DHT11_Data.humi_int;
- LCD_Show2Num(95,100,Hum,2,16,0);
- }
- // Soil_hum = (ADC_ConvertedValue*100)/4096;
- // LCD_Show2Num(115,90,Soil_hum,2,16,0);
- // LCD_Show2Num(115,130,Hum_limit,2,16,0);
- // CA_ScreenInput();
- Soil_hum = (ADC_ConvertedValue*100)/4096;
- LCD_Show2Num(145,140,Soil_hum,2,16,0);
- KEY_Scan();
- LCD_Show2Num(145,180,Hum_limit,2,16,0);
- // if(Task_Delay[1]==TASK_ENABLE) //键盘任务
- // {
- // LCD_Show2Num(115,130,Hum_limit,2,16,0);
- // CA_ScreenInput();
- // Task_Delay[1]=20; //此值每1ms会减1,减到0才可以重新进来这里,所以执行的周期是20ms
- // }
- }
- }
- /*********************************************END OF FILE**********************/
复制代码
所有资料51hei提供下载:
家庭花卉养殖系统 - 按键.rar
(363 KB, 下载次数: 57)
|