毕设仿真分享 单片机天气预报(STM32 TFT ESP8266)

本文详细描述了一个基于STM32F103ZET6和ESP8266的项目,涉及电路配置、初始化过程、使用TFT-LCD显示实时天气数据和操作系统的系统时钟配置。代码展示了主函数中对传感器数据的处理和UI界面的动态更新。
摘要由CSDN通过智能技术生成

一、电路设计

此电路由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();
      }
    }


项目获取:

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

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值