当前位置:   article > 正文

毕设 单片机天气预报(STM32 TFT ESP8266)_单片机温湿度数据 天气预测

单片机温湿度数据 天气预测

一、电路设计

此电路由STM32F103ZET6最小系统板、7针1.3寸TFT-LCD(240×240)显示屏和ESP8266WiFi模块组成。

二、运行结果

三、部分代码



    int main(void)
    {
      /* USER CODE BEGIN 1 */
    	uint8_t cnt = 0;
    	temp = 1;
    	int humidity = 0;
    	int value = 0;
      /* USER CODE END 1 */
    
      /* MCU Configuration--------------------------------------------------------*/
    
      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();
    
      /* USER CODE BEGIN Init */
    
      /* USER CODE END Init */
    
      /* Configure the system clock */
      SystemClock_Config();
    
      /* USER CODE BEGIN SysInit */
    
      /* USER CODE END SysInit */
    
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_USART1_UART_Init();
      MX_USART3_UART_Init();
      MX_RTC_Init();
      /* USER CODE BEGIN 2 */
    	Lcd_Init();			//³õʼ»¯TFT	
    	LCD_Clear(WHITE); //ÇåÆÁ
    	
    	picture();
    	
    	HAL_UART_Receive_IT(&huart1;, (uint8_t *)&aRxBuffer;_rx1, 1);			
    	HAL_UART_Receive_IT(&huart3;, (uint8_t *)&aRxBuffer;_rx3, 1);		//¿ªÆô´®¿ÚÖжÏ
    	esp8266_config();
    	LCD_Clear(WHITE); //ÇåÆÁ
    	Han();
      /* USER CODE END 2 */
    
      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
      while (1)
      {
        /* USER CODE END WHILE */
    
        /* USER CODE BEGIN 3 */


    		for(int a=0;a<11;a++)
    		{
    			showimage4(gImage_1[a]);		//ÏÔʾ¶¯Ì¬
    			RTC_display();
    			if(a == 10)a=0;


    			char *p;
    			p =	strstr(Data_buff,"text_day");				//²éÕÒÌìÆø			
    			sscanf(p+11,"%[^\"]",weather);	
    //			LCD_ShowString(40,80,(uint8_t*)weather);			
    			p = strstr(Data_buff,"high");								//²éÕÒÆøÎÂ
    			temperature[0]=atoi(p+7);
    			p = strstr(Data_buff,"low");
    			temperature[1]=atoi(p+6);
    //			LCD_ShowxNum2(45,40,temperature[1],2,24,0);
    			LCD_ShowxNum2(160,207,temperature[0],2,24,0);
    
    			//ζÈ
    			value = (temperature[1]+temperature[0])/2;
    			LCD_ShowxNum2(52,160,value,2,24,0); 			
    
    			//ʪ¶È
    			p = strstr(Data_buff,"humidity");
    			humidity=atoi(p+11);
    			LCD_ShowxNum2(132,160,humidity,2,24,0);
    			LCD_ShowNew(161,160,'%',24,0);
    			
    			//ÏÔʾ¶ÔÓ¦ÌìÆøUI   Èç¹û·¢ÏÖδÏÔʾÌìÆøͼ±ê£¬Ô­ÒòΪ֪ÐÄÌìÆøµÄUIÅж¨×Ö·û´®´óСд²»Ò»Ñù£¬Í¨¹ý´®¿Ú¸ÄһϴóСд¾Í¿ÉÒÔÁË
    			if((strstr(weather,"Overcast")) || (strstr(weather,"Mostly Cloudy")) || (strstr(weather,"Partly Cloudy")) || strstr(weather,"Cloudy"))	//¶àÔÆ
    			{
    				Overcast();
    			}
    			if((strstr(weather,"Sunny")) || (strstr(weather,"Clear")) || (strstr(weather,"Fair")))			//ÇçÌì
    			{
    				Sunny();
    			}
    			if((strstr(weather,"Shower")))				//ÕóÓê
    			{
    				Shower();
    			}
    			if((strstr(weather,"Thundershower")) || (strstr(weather,"Thundershower with Hail")))		//À×Óê
    			{
    				Thundershower();
    			}
    			if((strstr(weather,"Light rain")) || (strstr(weather,"Moderate Rain")))			//ÓêÌì
    			{
    				smallrain();
    			}
    			if((strstr(weather,"Heavy Rain")) || (strstr(weather,"Storm")) || (strstr(weather,"Heavy Storm")) || (strstr(weather,"Severe Storm")))		//±©Óê
    			{
    				Bigrain();
    			}
    			if((strstr(weather,"Ice Rain")) || (strstr(weather,"Sleet")) || (strstr(weather,"Snow Flurry")) || (strstr(weather,"Light Snow")) || (strstr(weather,"Moderate Snow")) || (strstr(weather,"Heavy Snow")) || (strstr(weather,"Snowstorm")))		//Ñ©Ìì
    			{
    				snow();
    			}			
    			
    		}
    
    //		cnt++;
    //		if(cnt > 50)
    //		{
    //			SendATCmd(get, 2000);
    //			cnt = 0;
    //		}
    		
      }
      /* USER CODE END 3 */
    }
    
    /**
      * @brief System Clock Configuration
      * @retval None
      */
    void SystemClock_Config(void)
    {
      RCC_OscInitTypeDef RCC_OscInitStruct = {0};
      RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
      RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
    
      /** Initializes the RCC Oscillators according to the specified parameters
      * in the RCC_OscInitTypeDef structure.
      */
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
      RCC_OscInitStruct.HSEState = RCC_HSE_ON;
      RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.LSIState = RCC_LSI_ON;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
      RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
      if (HAL_RCC_OscConfig(&RCC;_OscInitStruct) != HAL_OK)
      {
        Error_Handler();
      }
      /** Initializes the CPU, AHB and APB buses clocks
      */
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    
      if (HAL_RCC_ClockConfig(&RCC;_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
      {
        Error_Handler();
      }
      PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
      PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
      if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit;) != HAL_OK)
      {
        Error_Handler();
      }
    }


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172

项目获取:

https://gitee.com/feifei1122/simulation-project

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/708700
推荐阅读
相关标签
  

闽ICP备14008679号