项目用到LCD显示信息,使用的屏幕是微雪电子的1.69寸IPS彩色LCD显示屏,分辨率是240×280分辨率,采用SPI接口驱动。驱动芯片是ST7789V2,模块使用到6个控制管脚:
LCD_DINLCD_CLKLCD_CSLCD_DCLCD_RSTLCD_BL
SPI 通信 MOSI 引脚 |
SPI 通信 CLK引脚 |
LCD 的片选引脚,低电平有效 |
LCD 的数据/命令引脚,低电平表示命令,高电平表示数据 |
LCD 的复位引脚,低电平有效 |
LCD 的背光引脚 |
根据开发板的原理图,选择合适的管脚:
使用STM32CubeMX配置SPI驱动过程如下:
背光管脚配置PWM输出,PA2定时器3通道1:
内部时钟,分频系数99,计数值999,则PWM频率为:100MHz/(99+1)/(999+1)=1KHz,
输出占空比百分值为:Pulse值/(999+1)
测试代码:
#include "image.h" #include "LCD_Test.h" #include "LCD_1in69.h" #include "Touch_Driver.h" #include "DEV_Config.h" Touch_1IN69_XY XY; UBYTE flag = 0,flgh = 0; UWORD x,y,l = 0; void LCD_1in69_test() { printf("LCD_1IN28_test Demo\r\n"); DEV_Module_Init(); printf("LCD_1IN28_ Init and Clear...\r\n"); LCD_1IN69_SetBackLight(1000); LCD_1IN69_Init(VERTICAL); LCD_1IN69_Clear(WHITE); XY.mode = 0; //if(Touch_1IN69_init(XY.mode) == true) // printf("OK!\r\n"); // else // printf("NO!\r\n"); printf("Paint_NewImage\r\n"); Paint_NewImage(LCD_1IN69_WIDTH, LCD_1IN69_HEIGHT, 0, WHITE); printf("Set Clear and Display Funtion\r\n"); Paint_SetClearFuntion(LCD_1IN69_Clear); Paint_SetDisplayFuntion(LCD_1IN69_DrawPoint); printf("Paint_Clear\r\n"); Paint_Clear(BLACK); Paint_Clear(RED); Paint_Clear(GREEN); Paint_Clear(BLUE); Paint_Clear(BLACK); Paint_DrawString_EN(0, 90, "stm32wba55cg", &Font24, BLACK, RED); Paint_DrawString_EN(0, 120, "eepw bbs", &Font20, BLACK, GREEN); while(1); Paint_ClearWindows(10,90,230,137,WHITE); Paint_DrawString_EN(105, 100, "Up", &Font24, 0X647C, WHITE); /*while(XY.Gesture != UP) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); }*/ Paint_ClearWindows(105,100,160,155,WHITE); Paint_DrawString_EN(85, 100, "Down", &Font24, 0X647C, WHITE); /*while(XY.Gesture != Down) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); }*/ Paint_ClearWindows(85, 100,160,155,WHITE); Paint_DrawString_EN(85, 100, "Left", &Font24, 0X647C, WHITE); /*while(XY.Gesture != LEFT) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); }*/ Paint_ClearWindows(85, 100,160,155,WHITE); Paint_DrawString_EN(80, 100, "Right", &Font24, 0X647C, WHITE); /*while(XY.Gesture != RIGHT) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); }*/ Paint_ClearWindows(80, 100,165,160,WHITE); Paint_DrawString_EN(47, 100, "Long Press", &Font20, 0X647C, WHITE); /*while(XY.Gesture != LONG_PRESS) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); }*/ Paint_ClearWindows(47, 100,200,155,WHITE); Paint_DrawString_EN(35, 100, "Double Click", &Font20, 0X647C, WHITE); while(XY.Gesture != DOUBLE_CLICK) { if (flag == TOUCH_IRQ) { XY.Gesture = I2C_Read_Byte(0x01); flag = TOUCH_DRAW; } DEV_Delay_ms(10); } XY.mode = 1; //Touch_1IN69_init(XY.mode); Paint_ClearWindows(10,90,230,137,WHITE); Paint_DrawPoint(120, 140, BLACK, DOT_PIXEL_2X2, DOT_FILL_AROUND); while (1) { if (flag == TOUCH_IRQ) { Paint_DrawPoint(XY.x_point, XY.y_point, XY.color, DOT_PIXEL_2X2, DOT_FILL_AROUND); } } } void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { //if(GPIO_Pin & TP_INT_Pin) { if(XY.mode == 1) { flag = TOUCH_IRQ; //XY = Touch_1IN69_Get_Point(); } //else { flag = TOUCH_IRQ; } } }
效果:
工程源码分享: