st7789v2 240*320 怎么初始化为常黑 rgb565
时间: 2023-07-24 17:40:33 浏览: 118
以下是ST7789V2液晶显示屏初始化为常黑RGB565模式的代码示例,供您参考:
```
// 引脚定义
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
// 初始化函数
void tft_init() {
// 硬件初始化
pinMode(TFT_CS, OUTPUT);
pinMode(TFT_DC, OUTPUT);
pinMode(TFT_RST, OUTPUT);
digitalWrite(TFT_CS, HIGH);
digitalWrite(TFT_DC, HIGH);
digitalWrite(TFT_RST, HIGH);
// 软件初始化
tft_reset(); // 复位ST7789V2液晶显示屏
// ST7789V2液晶显示屏初始化代码
tft_write_command(0x36); // Memory data access control
tft_write_data(0x40); // Y-Mirror & X-Mirror, Reverse RGB
tft_write_command(0x3A); // Interface pixel format
tft_write_data(0x55); // 16-bit / pixel RGB565
tft_write_command(0xB2); // Porch control
tft_write_data(0x0C);
tft_write_data(0x0C);
tft_write_data(0x00);
tft_write_data(0x33);
tft_write_data(0x33);
tft_write_command(0xB7); // Gate control
tft_write_data(0x35);
tft_write_command(0xBB); // VCOMS setting
tft_write_data(0x19);
tft_write_command(0xC0); // LCMCTRL
tft_write_data(0x2C);
tft_write_command(0xC2); // VDV and VRH command enable
tft_write_data(0x01);
tft_write_command(0xC3); // VRH set
tft_write_data(0x12);
tft_write_command(0xC4); // VDV set
tft_write_data(0x20);
tft_write_command(0xC6); // Frame rate control
tft_write_data(0x0F);
tft_write_command(0xD0); // Power control 1
tft_write_data(0xA4);
tft_write_data(0xA1);
tft_write_command(0xE0); // PVGAMCTRL
tft_write_data(0xD0);
tft_write_data(0x00);
tft_write_data(0x05);
tft_write_data(0x0E);
tft_write_data(0x15);
tft_write_data(0x0D);
tft_write_data(0x37);
tft_write_data(0x43);
tft_write_data(0x47);
tft_write_data(0x09);
tft_write_data(0x15);
tft_write_data(0x12);
tft_write_data(0x16);
tft_write_data(0x19);
tft_write_command(0xE1); // NVGAMCTRL
tft_write_data(0xD0);
tft_write_data(0x00);
tft_write_data(0x05);
tft_write_data(0x0D);
tft_write_data(0x0C);
tft_write_data(0x06);
tft_write_data(0x2D);
tft_write_data(0x44);
tft_write_data(0x40);
tft_write_data(0x0E);
tft_write_data(0x1C);
tft_write_data(0x18);
tft_write_data(0x16);
tft_write_data(0x19);
tft_write_command(0x2A); // Column address set
tft_write_data(0x00);
tft_write_data(0x00);
tft_write_data(0x01);
tft_write_data(0x3F);
tft_write_command(0x2B); // Row address set
tft_write_data(0x00);
tft_write_data(0x00);
tft_write_data(0x01);
tft_write_data(0xE0);
tft_write_command(0x29); // Display on
}
// 发送命令
void tft_write_command(uint8_t cmd) {
digitalWrite(TFT_DC, LOW);
digitalWrite(TFT_CS, LOW);
SPI.transfer(cmd);
digitalWrite(TFT_CS, HIGH);
}
// 发送数据
void tft_write_data(uint8_t data) {
digitalWrite(TFT_DC, HIGH);
digitalWrite(TFT_CS, LOW);
SPI.transfer(data);
digitalWrite(TFT_CS, HIGH);
}
// 复位
void tft_reset() {
digitalWrite(TFT_RST, LOW);
delay(50);
digitalWrite(TFT_RST, HIGH);
delay(50);
}
```
需要注意的是,不同的液晶显示屏驱动程序的设置方法可能会有所不同,具体操作需要参考液晶显示屏驱动程序的说明文档。同时,如果您不熟悉相关的硬件和软件知识,建议寻求专业人士的帮助。
阅读全文