找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1672|回复: 0
收起左侧

STM32CubeMX及TRUESTIDIO代码,TFTLDC显示

[复制链接]
ID:490251 发表于 2019-12-29 10:18 | 显示全部楼层 |阅读模式
简单TFTLCD日期时间汉字显示

单片机源程序如下:
  1. /* USER CODE END Header */

  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "gpio.h"
  5. #include "fsmc.h"

  6. /* Private includes ----------------------------------------------------------*/
  7. /* USER CODE BEGIN Includes */
  8. #include        "tftlcd.h"
  9. /* USER CODE END Includes */

  10. /* Private typedef -----------------------------------------------------------*/
  11. /* USER CODE BEGIN PTD */

  12. /* USER CODE END PTD */

  13. /* Private define ------------------------------------------------------------*/
  14. /* USER CODE BEGIN PD */

  15. /* USER CODE END PD */

  16. /* Private macro -------------------------------------------------------------*/
  17. /* USER CODE BEGIN PM */

  18. /* USER CODE END PM */

  19. /* Private variables ---------------------------------------------------------*/

  20. /* USER CODE BEGIN PV */

  21. /* USER CODE END PV */

  22. /* Private function prototypes -----------------------------------------------*/
  23. void SystemClock_Config(void);
  24. /* USER CODE BEGIN PFP */

  25. /* USER CODE END PFP */

  26. /* Private user code ---------------------------------------------------------*/
  27. /* USER CODE BEGIN 0 */

  28. /* USER CODE END 0 */

  29. /**
  30.   * @brief  The application entry point.
  31.   * @retval int
  32.   */
  33. int main(void)
  34. {
  35.   /* USER CODE BEGIN 1 */

  36.   /* USER CODE END 1 */
  37.   

  38.   /* MCU Configuration--------------------------------------------------------*/

  39.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  40.   HAL_Init();

  41.   /* USER CODE BEGIN Init */

  42.   /* USER CODE END Init */

  43.   /* Configure the system clock */
  44.   SystemClock_Config();

  45.   /* USER CODE BEGIN SysInit */

  46.   /* USER CODE END SysInit */

  47.   /* Initialize all configured peripherals */
  48.   MX_GPIO_Init();
  49.   MX_FSMC_Init();
  50.   /* USER CODE BEGIN 2 */
  51.   TFTLCD_Init();        //TFT LCD软件初始化,必须调用

  52.   LCD_Clear(lcdColor_BLACK);        //以黑色清屏
  53.   lcdBACK_COLOR=lcdColor_BLACK;        //背景色
  54.   lcdFRONT_COLOR=lcdColor_RED;        //前景色
  55.   LCD_setFontSize(16);                //字体大小
  56.   LCD_ShowString(10,0,(uint8_t *)"Hello World");

  57.   LCD_setFontSize(24);
  58.   LCD_ShowString(10,LCD_CurPosY+20,(uint8_t *)"Hello ");
  59.   LCD_ShowString(LCD_CurPosX+10,LCD_CurPosY,(uint8_t *)"UPC");

  60.   lcdFRONT_COLOR=lcdColor_GREEN;
  61.   LCD_ShowUint(10, 70, 2019);
  62.   LCD_ShowFontHZ(58, 70, "年");
  63.   LCD_DrawRectangle(0, 65, 100, 105);

  64. #ifdef        USE_HZ_LIB
  65.   lcdFRONT_COLOR=lcdColor_YELLOW;
  66.   LCD_ShowHZ16(10, 140, "中");
  67.   LCD_ShowHZ16(30, 140, "国");
  68.   LCD_ShowHZ16(50, 140, "石");
  69.   LCD_ShowHZ16(70, 140, "油");
  70.   LCD_ShowHZ16(90, 140, "大");
  71.   LCD_ShowHZ16(110, 140, "学");
  72. #endif


  73.   /* USER CODE END 2 */

  74.   /* Infinite loop */
  75.   /* USER CODE BEGIN WHILE */

  76.   while (1)
  77.   {
  78.     /* USER CODE END WHILE */

  79.     /* USER CODE BEGIN 3 */
  80.   }
  81.   /* USER CODE END 3 */
  82. }

  83. /**
  84.   * @brief System Clock Configuration
  85.   * @retval None
  86.   */
  87. void SystemClock_Config(void)
  88. {
  89.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  90.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  91.   /** Configure the main internal regulator output voltage
  92.   */
  93.   __HAL_RCC_PWR_CLK_ENABLE();
  94.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  95.   /** Initializes the CPU, AHB and APB busses clocks
  96.   */
  97.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  98.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  99.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  100.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  101.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  102.   RCC_OscInitStruct.PLL.PLLM = 8;
  103.   RCC_OscInitStruct.PLL.PLLN = 168;
  104.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  105.   RCC_OscInitStruct.PLL.PLLQ = 4;
  106.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  107.   {
  108.     Error_Handler();
  109.   }
  110.   /** Initializes the CPU, AHB and APB busses clocks
  111.   */
  112.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  113.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  114.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  115.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  116.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  117.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  118.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  119.   {
  120.     Error_Handler();
  121.   }
  122. }

  123. /* USER CODE BEGIN 4 */

  124. /* USER CODE END 4 */

  125. /**
  126.   * @brief  This function is executed in case of error occurrence.
  127.   * @retval None
  128.   */
  129. void Error_Handler(void)
  130. {
  131.   /* USER CODE BEGIN Error_Handler_Debug */
  132.   /* User can add his own implementation to report the HAL error return state */

  133.   /* USER CODE END Error_Handler_Debug */
  134. }

  135. #ifdef  USE_FULL_ASSERT
  136. /**
  137.   * @brief  Reports the name of the source file and the source line number
  138.   *         where the assert_param error has occurred.
  139.   * @param  file: pointer to the source file name
  140.   * @param  line: assert_param error line source number
  141.   * @retval None
  142.   */
  143. void assert_failed(uint8_t *file, uint32_t line)
  144. {
  145.   /* USER CODE BEGIN 6 */
  146.   /* User can add his own implementation to report the file name and line number,
  147.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  148.   /* USER CODE END 6 */
  149. }
  150. #endif /* USE_FULL_ASSERT */

  151. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
Demo8_1TFTLCD.7z (1.05 MB, 下载次数: 10)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表