How to use 2.8 inch LCD driver on Mini Stm32 V3.0 using STM32CubeIDE

Posted

in

by

To use the 2.8-inch LCD.

I first checked the hardware schematic to find out all the pins attached to the LCD.

The LCD has a driver ic on its flex cable.
when I read the device code from the IC. The IC is ILI9325

You can check this post here for that

Mini STM32 V3.0

After checking the schematic diagram of both the development board and the LCD. It is time to create a project in STM32 Cube IDE.

After creating the project this is what the pin arrangment looks like in the integrated cubemx of stm32cube ide.

Download the LCD Library from below

  1. Download and extract the zip file.
  2. Inside you will find a folder named “LCD28”
  3. Copy that folder and place it into the driver folder of your stm32cubeide project.
  4. Insert the following header files into your main.c file
/* USER CODE BEGIN Includes */
#include "stm32f103xb.h"
#include "stdio.h"
#include "stdlib.h"
#include "../../Drivers/LCD28/ili932x.h"

/* USER CODE END Includes */
  1. Add the following code to initialize the LCD
/* USER CODE BEGIN 2 */
  

	HAL_GPIO_WritePin(LCD_BL_EN_GPIO_Port, LCD_BL_EN_Pin, GPIO_PIN_SET);
	LCD_Init();
	LCD_Clear(BLACK);

  /* USER CODE END 2 */
  1. Here are the list of functions you can use to make graphic on the 2.8 inch display
void LCD_Clear(uint16_t Color);
void LCD_Delay(uint32_t nCount);
void LCD_DrawPoint(uint16_t x,uint16_t y);
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void Draw_Circle(uint8_t x0,uint16_t y0,uint8_t r);
void LCD_Fill(uint8_t xsta,uint16_t ysta,uint8_t xend,uint16_t yend,uint16_t color);
uint16_t WriteOneASCII(uint8_t *pucMsk,
                              uint16_t x0,
                              uint16_t y0,
                              uint16_t color);
uint16_t WriteOneHzChar(uint8_t *pucMsk,
                               uint16_t x0,
                               uint16_t y0,
                               uint16_t color);
void WriteString(uint16_t x0, uint16_t y0,uint8_t *pcStr, uint16_t color);

Demo Program

/* USER CODE BEGIN WHILE */

	HAL_GPIO_WritePin(LCD_BL_EN_GPIO_Port, LCD_BL_EN_Pin, GPIO_PIN_SET);
	HAL_Delay(1000);
	LCD_Init();
	LCD_Clear(BLACK);

	uint8_t *textPtr;

	// Example usage of the provided LCD functions
	LCD_Clear(0xFFFF); // Clear the LCD screen with white color

	// Draw a blue line from (10, 10) to (100, 50)
	LCD_DrawLine(10, 10, 100, 50);

	// Draw a filled rectangle from (120, 50) to (180, 150) with red color
	LCD_Fill(120, 50, 180, 150, 0xF800);

	// Draw a green circle with center at (200, 200) and radius 20
	Draw_Circle(200, 200, 20);

	// Write a string at (50, 250) with black color

	textPtr = ((uint8_t *)"Hello www.EXASUB.com");
	WriteString(50,(250),textPtr,RED);



	// Color array in the desired order
	uint16_t colors[] = {BLACK, NAVY, DGREEN, DCYAN, MAROON, PURPLE, OLIVE, LGRAY,
			DGRAY, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE};
	uint8_t numColors = sizeof(colors) / sizeof(colors[0]);

	// Index variable for cycling through colors
	uint8_t colorIndex = 0;
	while (1)
	{
		/* USER CODE END WHILE */
		textPtr = ((uint8_t *)"Hello www.EXASUB.com");
		WriteString(50,(250),textPtr,colors[colorIndex]);
		// Increment the color index and wrap around if necessary
		colorIndex = (colorIndex + 1) % numColors;
		textPtr = ((uint8_t *)"ScIeNcE TeCh EnG MaTh ");
		WriteString(10,(270),textPtr,colors[colorIndex]);

		HAL_Delay(250);


		/* USER CODE BEGIN 3 */
	}
	/* USER CODE END 3 */

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *