【专题STM32F03】 使用 STM32Cube\Repository\STM32Cube_FW_F1_V1.8.5 中例程由ST7735硬SPI串口屏修改驱动ST7789V硬SPI串口LCD屏
1)修改Project
\STM32Cube_FW_F1_V1.8.5\Projects\STM32F103RB-Nucleo\Demonstrations\Adafruit_LCD_1_8_SD_Joystick
2)接线 (见 stm32f1xx_nucleo.h)
LCD_LED_PIN 接高电平
LCD_CS_PIN 接PB6
LCD_DC_PIN 接PA9
LCD_SPI_CLK 接SPI1 ,PA5
LCD_SPI_SDA 接SPI1 ,PA7
3)修改代码
st7735.h
/** * @brief ST7735 Size */ //#define ST7735_LCD_PIXEL_WIDTH ((uint16_t)128) //#define ST7735_LCD_PIXEL_HEIGHT ((uint16_t)160) #define ST7735_LCD_PIXEL_WIDTH ((uint16_t)240) #define ST7735_LCD_PIXEL_HEIGHT ((uint16_t)320)
st7735.c
void st7735_Init(void) { uint8_t data = 0; /* Initialize ST7735 low level bus layer -----------------------------------*/ LCD_IO_Init(); /* Out of sleep mode, 0 args, no delay */ st7735_WriteReg(0x11, 0x00);//LCD_Write_Cmd(0x11); LCD_Delay(10); st7735_WriteReg(0x36, 0x00);//LCD_Write_Cmd(0x36); //LCD_Write_Data(0x00); //横屏 如果设置不对,会出现两种色块分屏 //LCD_Write_Data (0xa0); //横屏 st7735_WriteReg(0x3a, 0x05);//LCD_Write_Cmd(0x3a); //LCD_Write_Data (0x05); //像素点的数据格式设置为 RGB:565 //与屏的型号有关 st7735_WriteReg(0x20, 0x00);//LCD_Write_Cmd(0x20); // 颜色值需按位取反 /* porch 设置 */ //st7735_WriteReg(0x2b, 0x00);//LCD_Write_Cmd(0xb2); st7735_WriteReg(0x2b, 0x0c);//LCD_Write_Data (0x0c); st7735_WriteReg(0x2b, 0x0c);//LCD_Write_Data (0x0c); st7735_WriteReg(0x2b, 0x00);//LCD_Write_Data (0x00); st7735_WriteReg(0x2b, 0x33);//LCD_Write_Data (0x33); st7735_WriteReg(0x2b, 0x33);//LCD_Write_Data (0x33); /* VGH设置 */ st7735_WriteReg(0xb7, 0x35);//LCD_Write_Cmd(0xb7); //LCD_Write_Data (0x35); /* VCOM 设置 */ st7735_WriteReg(0xbb, 0x35);//LCD_Write_Cmd(0xbb); //LCD_Write_Data (0x35); /* LCM 设置 */ st7735_WriteReg(0xc0, 0x2c);//LCD_Write_Cmd(0xc0); //LCD_Write_Data (0x2c); /* VDV and VRH 设置 */ st7735_WriteReg(0xc2, 0x01);//LCD_Write_Cmd(0xc2); //LCD_Write_Data (0x01); /* VRH 设置 */ st7735_WriteReg(0xc3, 0x0b);//LCD_Write_Cmd(0xc3); //LCD_Write_Data (0x0b); /* VDV 设置 */ st7735_WriteReg(0xc4, 0x20);//LCD_Write_Cmd(0xc4); //LCD_Write_Data (0x20); /* 普通模式下显存速率设置 60Mhz */ st7735_WriteReg(0xc6, 0x1e);//LCD_Write_Cmd(0xc6); //LCD_Write_Data (0x1e); /* 电源控制 */ st7735_WriteReg(0xd0, 0xa4);//LCD_Write_Cmd(0xd0); //LCD_Write_Data (0xa4); st7735_WriteReg(0xd0, 0xa1);//LCD_Write_Data (0xa1); /* 正电压设置 */ //st7735_WriteReg(0xe0, 0x00);//LCD_Write_Cmd(0xE0); //Set Gamma st7735_WriteReg(0xe0, 0xd0);//LCD_Write_Data (0xd0); st7735_WriteReg(0xe0, 0x00);//LCD_Write_Data (0x00); st7735_WriteReg(0xe0, 0x02);//LCD_Write_Data (0x02); st7735_WriteReg(0xe0, 0x07);//LCD_Write_Data (0x07); st7735_WriteReg(0xe0, 0x0b);//LCD_Write_Data (0x0b); st7735_WriteReg(0xe0, 0x1a);//LCD_Write_Data (0x1a); st7735_WriteReg(0xe0, 0x31);//LCD_Write_Data (0x31); st7735_WriteReg(0xe0, 0x54);//LCD_Write_Data (0x54); st7735_WriteReg(0xe0, 0x40);//LCD_Write_Data (0x40); st7735_WriteReg(0xe0, 0x29);//LCD_Write_Data (0x29); st7735_WriteReg(0xe0, 0x12);//LCD_Write_Data (0x12); st7735_WriteReg(0xe0, 0x12);//LCD_Write_Data (0x12); st7735_WriteReg(0xe0, 0x12);//LCD_Write_Data (0x12); st7735_WriteReg(0xe0, 0x17);//LCD_Write_Data (0x17); /* 负电压设置 */ //st7735_WriteReg(0xe1, 0x00);//LCD_Write_Cmd(0XE1); //Set Gamma st7735_WriteReg(0xe1, 0xd0);//LCD_Write_Data (0xd0); st7735_WriteReg(0xe1, 0x00);//LCD_Write_Data (0x00); st7735_WriteReg(0xe1, 0x02);//LCD_Write_Data (0x02); st7735_WriteReg(0xe1, 0x07);//LCD_Write_Data (0x07); st7735_WriteReg(0xe1, 0x05);//LCD_Write_Data (0x05); st7735_WriteReg(0xe1, 0x25);//LCD_Write_Data (0x25); st7735_WriteReg(0xe1, 0x2d);//LCD_Write_Data (0x2d); st7735_WriteReg(0xe1, 0x44);//LCD_Write_Data (0x44); st7735_WriteReg(0xe1, 0x45);//LCD_Write_Data (0x45); st7735_WriteReg(0xe1, 0x1c);//LCD_Write_Data (0x1c); st7735_WriteReg(0xe1, 0x18);//LCD_Write_Data (0x18); st7735_WriteReg(0xe1, 0x16);//LCD_Write_Data (0x16); st7735_WriteReg(0xe1, 0x1c);//LCD_Write_Data (0x1c); st7735_WriteReg(0xe1, 0x1d);//LCD_Write_Data (0x1d); /* 显示开 */ st7735_WriteReg(0x29, 0x00);//LCD_Write_Cmd(0x29); }
LCD相关的源代码依赖关系解析: LCD +STM32F103RB-Nucleo+Demonstrations+Adafruit_LCD_1_8_SD_Joystick