手里断断续续攒了一大堆LCD,有普通单色的,也有彩色的。彩色以ST7789/ST7735为主。在买TFT显示屏的饿时候,经常会看到有ILI9341驱动的,价格上比ST7789的高一些,什么原因不知道。出于好奇,想看看驱动处理上有什么不同,就下手买了一块。为了安全起见,从卖方提供的网址下载了例程。例程有51单片机用的,也有AT单片机用的,不过单片机的型号不是我手里有的。觉着型号不一致,驱动原理、方式应该没什么区别。
实际到手了以后,无论用哪种型号的单片机,使用例程就没有成功过,当时就蒙圈了。以为是显示屏坏掉了,已经准备退货了。想想到那么大个厂家,不可能提供坏的显示屏出货,就抱着最后一个希望,打开万能的Arduino,找例程库救场。之前测试的时候,已经把Ardafruit的TFT驱动库搞乱了,就没想着再用它来测试。就尝试着找其它大佬写的,自带驱动,不需要的第三方的库支持的。找了好几个,最后终于找到一个名为“Bonezegei_ILI9341”的例程。
用这个例程终于正常点亮了TFT显示屏,证明显示屏没问题。但显示的字符是反的,就像镜子里反射出来的结果。于是查找它对应的程序,找到Bonezegei_ILI9341.cpp文件打开看,在初始化处理中
void Bonezegei_ILI9341::begin() { setFontParam(verdanaB_12ptBitmaps, verdanaB_12ptDescriptors); vspi = new SPIClass(VSPI); vspi->begin(); vspi->setFrequency(ILI9341_SPISPEED); vspi->setDataMode(SPI_MODE0); vspi->setBitOrder(MSBFIRST); pinMode(_dc, OUTPUT); pinMode(_cs, OUTPUT); pinMode(_rst, OUTPUT); digitalWrite(_cs, HIGH); digitalWrite(_dc, HIGH); digitalWrite(_rst, HIGH); digitalWrite(_rst, LOW); delay(200); digitalWrite(_rst, HIGH); delay(2); sendCommand(0x11); delay(2); sendCommand(0x3a); delay(2); sendCommand(0x06); delay(2); sendCommand(0x29); delay(2); sendCommand(0x3A); sendData(0x66); delay(2); //16 bit= 0x55 18bit = 0x66 setRotation(1); clear(0); }
这一条指令是导致字符镜像显示的原因,改为setRotation(0);后显示变为正常。另外,注意看这个初始化指令,很简短。以往使用ST7789驱动的TFT显示屏时,初始化时会设置很多东西,像下面这样:
//************* Start Initial Sequence ********** WriteComm(0x3A); WriteData(0x55); WriteComm(0xF6); WriteData(0x01); WriteData(0x33); WriteComm(0xB5); WriteData(0x04); WriteData(0x04); WriteData(0x0A); WriteData(0x14); WriteComm(0x35); WriteData(0x00); WriteComm(0xCF); WriteData(0x00); WriteData(0xEA); WriteData(0XF0); WriteComm(0xED); WriteData(0x64); WriteData(0x03); WriteData(0X12); WriteData(0X81); WriteComm(0xE8); WriteData(0x85); WriteData(0x00); WriteData(0x78); WriteComm(0xCB); WriteData(0x39); WriteData(0x2C); WriteData(0x00); WriteData(0x33); WriteData(0x06); WriteComm(0xF7); WriteData(0x20); WriteComm(0xEA); WriteData(0x00); WriteData(0x00); WriteComm(0xC0); //Power control WriteData(0x21); //VRH[5:0] WriteComm(0xC1); //Power control WriteData(0x10); //BT[3:0] WriteComm(0xC5); //VCM control WriteData(0x4F); WriteData(0x38); WriteComm(0xC7); WriteData(0x98); WriteComm(0x36); // Memory Access Control WriteData(0x08); WriteComm(0xB1); WriteData(0x00); WriteData(0x13); WriteComm(0xB6); // Display Function Control WriteData(0x0A); WriteData(0xA2); WriteComm(0xF2); // 3Gamma Function Disable WriteData(0x02); WriteComm(0xE0); //Set Gamma WriteData(0x0F); WriteData(0x27); WriteData(0x24); WriteData(0x0C); WriteData(0x10); WriteData(0x08); WriteData(0x55); WriteData(0X87); WriteData(0x45); WriteData(0x08); WriteData(0x14); WriteData(0x07); WriteData(0x13); WriteData(0x08); WriteData(0x00); WriteComm(0XE1); //Set Gamma WriteData(0x00); WriteData(0x0F); WriteData(0x12); WriteData(0x05); WriteData(0x11); WriteData(0x06); WriteData(0x25); WriteData(0x34); WriteData(0x37); WriteData(0x01); WriteData(0x08); WriteData(0x07); WriteData(0x2B); WriteData(0x34); WriteData(0x0F); WriteComm(0x11); //Exit Sleep Delay(120); WriteComm(0x29); //Display on
现在看来,没必要。后面准备按照Bonezegei的处理方式,把驱动程序搞到51单片机和ARM32单片机中试试。
这次经历给我的教训是:不能完全相信卖家提供的程序。搞不好卖家也是从网上哪个地方弄来的,未经实际测试验证。