- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- /** @addtogroup STM32L5xx_HAL_Examples
- * @{
- */
- /** @addtogroup BSP
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- #define LCD_FEATURES_NUM 3
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- static uint8_t LCD_Feature;
- /* Private function prototypes -----------------------------------------------*/
- static void LCD_SetHint(void);
- static void LCD_Show_Feature(uint8_t feature);
- /* Private functions ---------------------------------------------------------*/
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] LCD demo
- * @param None
- * @retval None
- */
- void LCD_demo(void)
- {
- LCD_SetHint();
- LCD_Feature = 0;
- LCD_Show_Feature (LCD_Feature);
-
- }
- /**
- * @brief Display LCD demo hint
- * @param None
- * @retval None
- */
- static void LCD_SetHint(void)
- {
- /* Clear the LCD */
- UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
- /* Set LCD Demo description */
- UTIL_LCD_FillRect(0, 0, 240, 80, UTIL_LCD_COLOR_BLUE);
- UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
- UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_BLUE);
- UTIL_LCD_SetFont(&Font24);
- UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"LCD", CENTER_MODE);
- UTIL_LCD_SetFont(&Font12);
- UTIL_LCD_DisplayStringAt(0, 30, (uint8_t *)"This example shows the different", CENTER_MODE);
- UTIL_LCD_DisplayStringAt(0, 45, (uint8_t *)"LCD Features, use User push-button", CENTER_MODE);
- UTIL_LCD_DisplayStringAt(0, 60, (uint8_t *)"to display next page", CENTER_MODE);
- UTIL_LCD_DrawRect(10, 90, 220, 140, UTIL_LCD_COLOR_BLUE);
- UTIL_LCD_DrawRect(11, 91, 218, 138, UTIL_LCD_COLOR_BLUE);
- }
- /**
- * @brief Show LCD Features
- * @param feature : feature index
- * @retval None
- */
- static void LCD_Show_Feature(uint8_t feature)
- {
- Point Points[] = {{20, 150}, {50, 150}, {50, 200}};
- Point Points2[] = {{60, 150}, {90, 150}, {90, 200}};
- UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
- UTIL_LCD_FillRect(12, 92, 216, 136, UTIL_LCD_COLOR_WHITE);
- UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLACK);
- switch (feature)
- {
- case 0:
- /* Text Feature */
- UTIL_LCD_DisplayStringAt(14, 100, (uint8_t *)"Left aligned Text", LEFT_MODE);
- UTIL_LCD_DisplayStringAt(0, 115, (uint8_t *)"Center aligned Text", CENTER_MODE);
- UTIL_LCD_DisplayStringAt(14, 130, (uint8_t *)"Right aligned Text", RIGHT_MODE);
- UTIL_LCD_SetFont(&Font24);
- UTIL_LCD_DisplayStringAt(14, 150, (uint8_t *)"Font24", LEFT_MODE);
- UTIL_LCD_SetFont(&Font20);
- UTIL_LCD_DisplayStringAt(14, 180, (uint8_t *)"Font20", LEFT_MODE);
- UTIL_LCD_SetFont(&Font16);
- UTIL_LCD_DisplayStringAt(14, 210, (uint8_t *)"Font16", LEFT_MODE);
- break;
- case 1:
- /* Draw misc. Shapes */
- UTIL_LCD_DrawRect(20, 100, 30 , 40, UTIL_LCD_COLOR_BLACK);
- UTIL_LCD_FillRect(60, 100, 30 , 40, UTIL_LCD_COLOR_BLACK);
- UTIL_LCD_DrawCircle(130, 120, 20, UTIL_LCD_COLOR_GRAY);
- UTIL_LCD_FillCircle(195, 120, 20, UTIL_LCD_COLOR_GRAY);
- UTIL_LCD_DrawPolygon(Points, 3, UTIL_LCD_COLOR_GREEN);
- UTIL_LCD_FillPolygon(Points2, 3, UTIL_LCD_COLOR_GREEN);
- UTIL_LCD_DrawEllipse(130, 170, 30, 20, UTIL_LCD_COLOR_RED);
- UTIL_LCD_FillEllipse(195, 170, 30, 20, UTIL_LCD_COLOR_RED);
- UTIL_LCD_DrawHLine(20, 210, 30, UTIL_LCD_COLOR_BLACK);
- UTIL_LCD_DrawLine (100, 220, 220, 190, UTIL_LCD_COLOR_BLACK);
- UTIL_LCD_DrawLine (100, 190, 220, 220, UTIL_LCD_COLOR_BLACK);
- break;
- case 2:
- break;
- default :
- break;
- }
- }
7、添加头文件到工程中:
8、在main.c中添加初始化等代码:
- if (LcdInitialized != SET)
- {
- LCD_UTILS_Drv_t lcdDrv;
- /* Initialize the LCD */
- if (BSP_LCD_Init(0, LCD_ORIENTATION_PORTRAIT) != BSP_ERROR_NONE)
- {
- Error_Handler();
- }
- /* Set UTIL_LCD functions */
- lcdDrv.DrawBitmap = BSP_LCD_DrawBitmap;
- lcdDrv.FillRGBRect = BSP_LCD_FillRGBRect;
- lcdDrv.DrawHLine = BSP_LCD_DrawHLine;
- lcdDrv.DrawVLine = BSP_LCD_DrawVLine;
- lcdDrv.FillRect = BSP_LCD_FillRect;
- lcdDrv.GetPixel = BSP_LCD_ReadPixel;
- lcdDrv.SetPixel = BSP_LCD_WritePixel;
- lcdDrv.GetXSize = BSP_LCD_GetXSize;
- lcdDrv.GetYSize = BSP_LCD_GetYSize;
- lcdDrv.SetLayer = BSP_LCD_SetActiveLayer;
- lcdDrv.GetFormat = BSP_LCD_GetFormat;
- UTIL_LCD_SetFuncDriver(&lcdDrv);
- /* Clear the LCD */
- UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
- /* Set the display on */
- if (BSP_LCD_DisplayOn(0) != BSP_ERROR_NONE)
- {
- Error_Handler();
- }
- LcdInitialized = SET;
- }
-
- Display_DemoDescription();
实现效果: