当前位置:   article > 正文

单片机设计_天气预报(STM32 TFT ESP8266)_stm32天气提醒

stm32天气提醒

想要更多项目私wo!!!


一、电路设计

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

二、运行结果


三、部分代码

  1. int main(void)
  2. {
  3. /* USER CODE BEGIN 1 */
  4. uint8_t cnt = 0;
  5. temp = 1;
  6. int humidity = 0;
  7. int value = 0;
  8. /* USER CODE END 1 */
  9. /* MCU Configuration--------------------------------------------------------*/
  10. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  11. HAL_Init();
  12. /* USER CODE BEGIN Init */
  13. /* USER CODE END Init */
  14. /* Configure the system clock */
  15. SystemClock_Config();
  16. /* USER CODE BEGIN SysInit */
  17. /* USER CODE END SysInit */
  18. /* Initialize all configured peripherals */
  19. MX_GPIO_Init();
  20. MX_USART1_UART_Init();
  21. MX_USART3_UART_Init();
  22. MX_RTC_Init();
  23. /* USER CODE BEGIN 2 */
  24. Lcd_Init(); //³õʼ»¯TFT
  25. LCD_Clear(WHITE); //ÇåÆÁ
  26. picture();
  27. HAL_UART_Receive_IT(&huart1, (uint8_t *)&aRxBuffer_rx1, 1);
  28. HAL_UART_Receive_IT(&huart3, (uint8_t *)&aRxBuffer_rx3, 1); //¿ªÆô´®¿ÚÖжÏ
  29. esp8266_config();
  30. LCD_Clear(WHITE); //ÇåÆÁ
  31. Han();
  32. /* USER CODE END 2 */
  33. /* Infinite loop */
  34. /* USER CODE BEGIN WHILE */
  35. while (1)
  36. {
  37. /* USER CODE END WHILE */
  38. /* USER CODE BEGIN 3 */
  39. for(int a=0;a<11;a++)
  40. {
  41. showimage4(gImage_1[a]); //ÏÔʾ¶¯Ì¬
  42. RTC_display();
  43. if(a == 10)a=0;
  44. char *p;
  45. p = strstr(Data_buff,"text_day"); //²éÕÒÌìÆø
  46. sscanf(p+11,"%[^\"]",weather);
  47. // LCD_ShowString(40,80,(uint8_t*)weather);
  48. p = strstr(Data_buff,"high"); //²éÕÒÆøÎÂ
  49. temperature[0]=atoi(p+7);
  50. p = strstr(Data_buff,"low");
  51. temperature[1]=atoi(p+6);
  52. // LCD_ShowxNum2(45,40,temperature[1],2,24,0);
  53. LCD_ShowxNum2(160,207,temperature[0],2,24,0);
  54. //ζÈ
  55. value = (temperature[1]+temperature[0])/2;
  56. LCD_ShowxNum2(52,160,value,2,24,0);
  57. //ʪ¶È
  58. p = strstr(Data_buff,"humidity");
  59. humidity=atoi(p+11);
  60. LCD_ShowxNum2(132,160,humidity,2,24,0);
  61. LCD_ShowNew(161,160,'%',24,0);
  62. //ÏÔʾ¶ÔÓ¦ÌìÆøUI Èç¹û·¢ÏÖδÏÔʾÌìÆøͼ±ê£¬Ô­ÒòΪ֪ÐÄÌìÆøµÄUIÅж¨×Ö·û´®´óСд²»Ò»Ñù£¬Í¨¹ý´®¿Ú¸ÄһϴóСд¾Í¿ÉÒÔÁË
  63. if((strstr(weather,"Overcast")) || (strstr(weather,"Mostly Cloudy")) || (strstr(weather,"Partly Cloudy")) || strstr(weather,"Cloudy")) //¶àÔÆ
  64. {
  65. Overcast();
  66. }
  67. if((strstr(weather,"Sunny")) || (strstr(weather,"Clear")) || (strstr(weather,"Fair"))) //ÇçÌì
  68. {
  69. Sunny();
  70. }
  71. if((strstr(weather,"Shower"))) //ÕóÓê
  72. {
  73. Shower();
  74. }
  75. if((strstr(weather,"Thundershower")) || (strstr(weather,"Thundershower with Hail"))) //À×Óê
  76. {
  77. Thundershower();
  78. }
  79. if((strstr(weather,"Light rain")) || (strstr(weather,"Moderate Rain"))) //ÓêÌì
  80. {
  81. smallrain();
  82. }
  83. if((strstr(weather,"Heavy Rain")) || (strstr(weather,"Storm")) || (strstr(weather,"Heavy Storm")) || (strstr(weather,"Severe Storm"))) //±©Óê
  84. {
  85. Bigrain();
  86. }
  87. 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"))) //Ñ©Ìì
  88. {
  89. snow();
  90. }
  91. }
  92. // cnt++;
  93. // if(cnt > 50)
  94. // {
  95. // SendATCmd(get, 2000);
  96. // cnt = 0;
  97. // }
  98. }
  99. /* USER CODE END 3 */
  100. }
  101. /**
  102. * @brief System Clock Configuration
  103. * @retval None
  104. */
  105. void SystemClock_Config(void)
  106. {
  107. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  108. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  109. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  110. /** Initializes the RCC Oscillators according to the specified parameters
  111. * in the RCC_OscInitTypeDef structure.
  112. */
  113. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  114. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  115. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  116. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  117. RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  118. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  119. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  120. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  121. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  122. {
  123. Error_Handler();
  124. }
  125. /** Initializes the CPU, AHB and APB buses clocks
  126. */
  127. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  128. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  129. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  130. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  131. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  132. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  133. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  134. {
  135. Error_Handler();
  136. }
  137. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  138. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  139. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  140. {
  141. Error_Handler();
  142. }
  143. }

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

闽ICP备14008679号