This post was last edited by dirty on 2024-2-5 00:32
After a period of understanding and familiarity, this article implements the LCD display function.
1. Hardware Understanding
The development board has an onboard LCD display with a resolution of 172(H)RGB x320(V), a driver IC ST7789V3, and MCU driving control via the SPI interface. The hardware principle of the development board is as follows
Figure 1: LCD schematic connection
LCD screen pin MCU PIN Function
LCD_CS PE1 Chip select signal, low level is effective
LCD_DC PE2 Display data/command pin. Write command when low level, write data when high level
LCD_SDA PB14 data pin, ==MOSI
LCD_SCL PE0 clock pin, == SCK
LCD_RES PB15 Reset pin, low level reset
BLK PB9 Backlight pin, high level turns on the backlight
2. Code Preparation
1. Define the screen resolution and choose the horizontal or vertical screen mode. Here we use the horizontal screen mode.
#define USE_HORIZONTAL 3//2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#if USE_HORIZONTAL==0||USE_HORIZONTAL==1
#define LCD_W 172
#define LCD_H 320
#else
#define LCD_W 320
#define LCD_H 172
#endif
2. SPI driver writing, can be IO simulation or hardware SPI, the former display refresh is slower, or the latter using DMA will be faster. Here we share ST7789V3 driver RGB screen initialization, the configuration is valid.
void LCD_Init(void)
{
LCD_GPIO_Init();//初始化GPIO
LCD_RES_Clr();//复位
FL_DelayMs(30);
LCD_RES_Set();
FL_DelayMs(100);
LCD_BLK_Set();//打开背光
FL_DelayMs(100);
LCD_WR_REG(0x11);
// FL_DelayMs(120);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x13);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xD6);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xF0);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x05);
LCD_WR_DATA8(0x29);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x3E);
LCD_WR_DATA8(0x38);
LCD_WR_DATA8(0x12);
LCD_WR_DATA8(0x12);
LCD_WR_DATA8(0x28);
LCD_WR_DATA8(0x30);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xF0);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x0A);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x07);
LCD_WR_DATA8(0x28);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x3E);
LCD_WR_DATA8(0x36);
LCD_WR_DATA8(0x14);
LCD_WR_DATA8(0x14);
LCD_WR_DATA8(0x29);
LCD_WR_DATA8(0x32);
LCD_WR_REG(0x11);
FL_DelayMs(120);
LCD_WR_REG(0x29);
}
3. UI interface design
Using the font extraction tool and image extraction tool, I designed the Fudan micro-official website logo, QQ avatar, Chinese characters, etc., supplemented by color matching, layout, etc.
void lcd_show(void)
{
LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
// LCD_Fill(0,0,LCD_W,LCD_H,RED);
// LCD_Fill(0,0,LCD_W,LCD_H,GREEN);
// LCD_Fill(0,0,LCD_W,LCD_H,BLUE);
// LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
LCD_ShowPicture(50,10,120,50,gImage_image_fdw);
LCD_ShowChinese(180,19,"复旦微",BLUE,WHITE,32,0);
LCD_ShowChinese(80,60,"车规系列",BLUE,WHITE,32,0);
LCD_ShowString(220,60,"MCU",RED,WHITE,32,0);
LCD_ShowString(80,100,"FM33FT056A",RED,WHITE,32,0);
LCD_ShowPicture(140,130,40,40,gImage_1);
}
3. Test results
The display effect after compiling and burning is as follows
The overall display effect is good, and the function of driving the LCD screen is realized. If you want to make some rich interface displays later, you can use LVGL, which also lays a good foundation.