STM32 使用GPIO 8080接口方式驱动ST7789V 驱动代码实现
时间: 2023-10-31 08:24:15 浏览: 454
stm32+spi+7789v 驱动例程.rar
5星 · 资源好评率100%
以下是一个使用STM32的GPIO口通过8080接口方式驱动ST7789V的简单示例代码:
```c
#include "stm32f10x.h"
#include "delay.h"
#define LCD_DATA_PORT GPIOA
#define LCD_CTRL_PORT GPIOB
#define LCD_CS_PIN GPIO_Pin_12
#define LCD_RS_PIN GPIO_Pin_13
#define LCD_WR_PIN GPIO_Pin_14
#define LCD_RD_PIN GPIO_Pin_15
#define LCD_RST_PIN GPIO_Pin_3
void LCD_WriteCommand(uint8_t cmd)
{
LCD_DATA_PORT->ODR = cmd;
LCD_CTRL_PORT->BRR = LCD_RS_PIN;
LCD_CTRL_PORT->BRR = LCD_WR_PIN;
LCD_CTRL_PORT->BSRR = LCD_WR_PIN;
LCD_CTRL_PORT->BSRR = LCD_RS_PIN;
}
void LCD_WriteData(uint8_t data)
{
LCD_DATA_PORT->ODR = data;
LCD_CTRL_PORT->BSRR = LCD_RS_PIN;
LCD_CTRL_PORT->BRR = LCD_WR_PIN;
LCD_CTRL_PORT->BSRR = LCD_WR_PIN;
}
void LCD_Init(void)
{
// 初始化GPIO口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LCD_DATA_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_CS_PIN | LCD_RS_PIN | LCD_WR_PIN | LCD_RD_PIN | LCD_RST_PIN;
GPIO_Init(LCD_CTRL_PORT, &GPIO_InitStructure);
// 复位LCD
GPIO_SetBits(LCD_CTRL_PORT, LCD_RST_PIN);
delay_ms(5);
GPIO_ResetBits(LCD_CTRL_PORT, LCD_RST_PIN);
delay_ms(10);
GPIO_SetBits(LCD_CTRL_PORT, LCD_RST_PIN);
delay_ms(120);
// 初始化ST7789V
LCD_WriteCommand(0x11); // Sleep out
delay_ms(120);
LCD_WriteCommand(0x36); // Memory data access control
LCD_WriteData(0x00);
LCD_WriteCommand(0x3A); // Interface pixel format
LCD_WriteData(0x05);
LCD_WriteCommand(0xB2); // Porch control
LCD_WriteData(0x0C);
LCD_WriteData(0x0C);
LCD_WriteData(0x00);
LCD_WriteData(0x33);
LCD_WriteData(0x33);
LCD_WriteCommand(0xB7); // Gate control
LCD_WriteData(0x35);
LCD_WriteCommand(0xBB); // VCOMS setting
LCD_WriteData(0x19);
LCD_WriteCommand(0xC0); // LCM control
LCD_WriteData(0x2C);
LCD_WriteCommand(0xC2); // VDV and VRH command enable
LCD_WriteData(0x01);
LCD_WriteData(0xFF);
LCD_WriteCommand(0xC3); // VRH set
LCD_WriteData(0x11);
LCD_WriteCommand(0xC4); // VDV set
LCD_WriteData(0x20);
LCD_WriteCommand(0xC6); // Frame rate control
LCD_WriteData(0x0F);
LCD_WriteCommand(0xD0); // Power control
LCD_WriteData(0xA4);
LCD_WriteData(0xA1);
LCD_WriteCommand(0xE0); // Positive gamma correction
LCD_WriteData(0xD0);
LCD_WriteData(0x08);
LCD_WriteData(0x11);
LCD_WriteData(0x08);
LCD_WriteData(0x0C);
LCD_WriteData(0x15);
LCD_WriteData(0x39);
LCD_WriteData(0x33);
LCD_WriteData(0x50);
LCD_WriteData(0x36);
LCD_WriteData(0x13);
LCD_WriteData(0x14);
LCD_WriteData(0x29);
LCD_WriteData(0x2D);
LCD_WriteCommand(0xE1); // Negative gamma correction
LCD_WriteData(0xD0);
LCD_WriteData(0x08);
LCD_WriteData(0x10);
LCD_WriteData(0x08);
LCD_WriteData(0x06);
LCD_WriteData(0x06);
LCD_WriteData(0x39);
LCD_WriteData(0x44);
LCD_WriteData(0x51);
LCD_WriteData(0x0B);
LCD_WriteData(0x16);
LCD_WriteData(0x14);
LCD_WriteData(0x2F);
LCD_WriteData(0x31);
LCD_WriteCommand(0x29); // Display on
}
int main(void)
{
LCD_Init();
while (1)
{
// 显示内容
}
}
```
以上代码只是一个简单的示例,具体的实现方式和细节需要根据具体的硬件和软件环境进行调整和修改,建议您参考ST7789V的数据手册和STM32的硬件文档,以及相关的开发工具和示例代码。
阅读全文