1. 叙述
许久未使用的TFT显示屏,这些天突然想使用它来竖屏显示,在查阅数据手册后设置成功,加上还有一些颜色显示问题,一并记录。首先看数据手册的寄存器功能位描述
数据手册
再看一下不同设置方法的理论显示效果
显示分析
由于一开始的色块刷新函数适用于的初始化时(36h)寄存器位置写入的值为(1100_0000),也就是上图的第四个,注意上图的三位数据和(MV MX MY)与实际寄存器顺序不一样
X-Y 坐标交换: 与DDRAM中的正常数据显示模式相比,就是X和Y的数据对调了
X-Mirror: 与DDRAM中正常的模式相比,为X轴对称
Y-Mirror: 与与DDRAM中正常的模式相比,为Y轴对称
至于为啥采用第四种竖屏 显示,而不是正常模式,由于模块正常模式是反着的,不好看。
若是需要改为横屏 显示,而且还能够使用原来的刷屏函数,那就要向寄存器中写入(0110_0000)
三种显示效果如下所示,由于屏幕亮度太高,文字显示不出来。2是正常显示,1是第四种显示,3是横屏显示
至于颜色错乱问题,如红色显示成了蓝色,是由于(36h)寄存器的RGB位被置1了,所以RGB数据被显示成了BGR。
2.代码
初始化的代如下所示,其实就只改了一行。
void Lcd_Init()
{
LCD_GPIO_Init();
Lcd_Reset();
Lcd_WriteIndex(0x11);//Sleep exit
Lcd_DelayMs (120);
//ST7735R Frame Rate
Lcd_WriteIndex(0xB1);
Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB2);
Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB3);
Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D);
Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB4); //Column inversion
Lcd_WriteData(0x07);
//ST7735R Power Sequence
Lcd_WriteIndex(0xC0);
Lcd_WriteData(0xA2); Lcd_WriteData(0x02); Lcd_WriteData(0x84);
Lcd_WriteIndex(0xC1); Lcd_WriteData(0xC5);
Lcd_WriteIndex(0xC2);
Lcd_WriteData(0x0A); Lcd_WriteData(0x00);
Lcd_WriteIndex(0xC3);
Lcd_WriteData(0x8A); Lcd_WriteData(0x2A);
Lcd_WriteIndex(0xC4);
Lcd_WriteData(0x8A); Lcd_WriteData(0xEE);
Lcd_WriteIndex(0xC5); //VCOM
Lcd_WriteData(0x0E);
//屏幕横竖问题未解决 已解决 写入0x60
Lcd_WriteIndex(0x36); //MX, MY, RGB mode
//Lcd_WriteData(0xC0); //竖屏
Lcd_WriteData(0x60); //横屏
//ST7735R Gamma Sequence
Lcd_WriteIndex(0xe0);
Lcd_WriteData(0x0f); Lcd_WriteData(0x1a);
Lcd_WriteData(0x0f); Lcd_WriteData(0x18);
Lcd_WriteData(0x2f); Lcd_WriteData(0x28);
Lcd_WriteData(0x20); Lcd_WriteData(0x22);
Lcd_WriteData(0x1f); Lcd_WriteData(0x1b);
Lcd_WriteData(0x23); Lcd_WriteData(0x37); Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
Lcd_WriteData(0x02); Lcd_WriteData(0x10);
Lcd_WriteIndex(0xe1);
Lcd_WriteData(0x0f); Lcd_WriteData(0x1b);
Lcd_WriteData(0x0f); Lcd_WriteData(0x17);
Lcd_WriteData(0x33); Lcd_WriteData(0x2c);
Lcd_WriteData(0x29); Lcd_WriteData(0x2e);
Lcd_WriteData(0x30); Lcd_WriteData(0x30);
Lcd_WriteData(0x39); Lcd_WriteData(0x3f);
Lcd_WriteData(0x00); Lcd_WriteData(0x07);
Lcd_WriteData(0x03); Lcd_WriteData(0x10);
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);Lcd_WriteData(0x00);
Lcd_WriteData(0x00);Lcd_WriteData(0x7f);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);Lcd_WriteData(0x00);
Lcd_WriteData(0x00);Lcd_WriteData(0x9f);
Lcd_WriteIndex(0xF0); //Enable test command
Lcd_WriteData(0x01);
Lcd_WriteIndex(0xF6); //Disable ram power save mode
Lcd_WriteData(0x00);
Lcd_WriteIndex(0x3A); //65k mode
Lcd_WriteData(0x05);
Lcd_WriteIndex(0x29);//Display on
}
//对应的设置显示区代码
void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end)
{
#ifdef USE_DMA
//修改后,为使用DMA 加速SPI2传输数据(刷屏)
Lcd_WriteIndex(0x2A);
Lcd_WriteData16(x_start);
Lcd_WriteData16(x_end);
Lcd_WriteIndex(0x2B);
Lcd_WriteData16(y_start);
Lcd_WriteData16(x_end); //采用DMA搬运时需要使用x_end,很奇怪
Lcd_WriteIndex(0x2C);
#else
//正常显示
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(x_start);
Lcd_WriteData(0x00);
Lcd_WriteData(x_end);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(y_start);
Lcd_WriteData(0x00);
Lcd_WriteData(y_end);
Lcd_WriteIndex(0x2c);
#endif
}
3.总结
本次主要是在使用littvgl 开源GUI显示图片时发现图片显示颜色出现了问题,开始以为是GUI移植过程出了问题,后来在直接操作屏幕显示发现颜色也不对,便找到了相关的数据手册细看了(36h)这一寄存器的说明,最后定位到了初始化的问题上。本人不才,必有疏漏,望指正。
注意!!!
下载资源 UCOSIII+LittleVGL+DMA刷新屏幕 的朋友,会出现颜色显示不对的问题,需要将原来初始化代码中的 Lcd_WriteData(0x68); //横屏 改为 Lcd_WriteData(0x68)
自己上传的资源不允许修改和评论,这也是**操作,抱歉了。
版权声明:本文为CSDN博主「黑不溜秋吓死你」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42965223/article/details/119853548
暂无评论