今天调试的时候发现,个别的液晶显示屏,程序烧进去之后,刚上电显示的字是反的,复位键之后,显示正常了,而且每次上电都有这个问题,后来发现原因在液晶的初始化程序里:
原来有问题的程序
void init_s95417(void)
{
LCD_CS_H;
delay(5);
LCD_RST_L;
delay(5);
LCD_RST_H;
//LCD_RD_H;
LCD_CS_L;
delay(50);//可以适当调整延时,保障稳定显示
//write_cmd_data(0x0000,0x0001); //开启内部晶振
write_cmd_data(0x0001,0x0100); //源扫描设置SS=0, 输出的移动方向是从S1到S720
//(源扫描设置SS=1, 输出的移动方向是从S720到S1)
//SM=0,逐行扫描(SM=1,隔行扫描)
write_cmd_data(0x0002,0x0700); //B/C=1、EOR=1:行倒置(B/C=0:帧/场倒置)
write_cmd_data(0x0003,0x1098); //AM=1,地址在水平方向自动加1 //1030
//I/D[1:0] = 10:水平垂直方向均增加
//ORG=1
//BGR=1:采用BGR格式
//TRI=0、DFM=*:8位机、两次数据传送
write_cmd_data(0x0004,0x0000); //比例缩放设置:不缩放
//显示控制
write_cmd_data(0x0008,0x0207); //设置后边沿和前沿
write_cmd_data(0x0009,0x0000);//设置非显示区时间间隔ISC[3:0]
write_cmd_data(0x000A,0x0000); //帧标记功能
write_cmd_data(0x000C,0x0000);//RGB显示接口控制1
write_cmd_data(0x000D,0x0000);//帧标记位置
write_cmd_data(0x000F,0x0000);//RGB显示接口控制2
//电源配置
write_cmd_data(0x0010,0x0000);
write_cmd_data(0x0011,0x0007);
write_cmd_data(0x0012,0x0000);
write_cmd_data(0x0013,0x0000);
//vgh
write_cmd_data(0x0010,0x1290);
write_cmd_data(0x0011,0x0227);
//delay(100);
//vregiout
write_cmd_data(0x0012,0x001d); //0x001b
//delay(100);
//vom amplitude
write_cmd_data(0x0013,0x1500);
//delay(100);
//vom H
write_cmd_data(0x0029,0x0018);
write_cmd_data(0x002B,0x000D);
//伽马校正
write_cmd_data(0x0030,0x0004);
write_cmd_data(0x0031,0x0307);
write_cmd_data(0x0032,0x0002);//0006
write_cmd_data(0x0035,0x0206);
write_cmd_data(0x0036,0x0408);
write_cmd_data(0x0037,0x0507);
write_cmd_data(0x0038,0x0204);//0200
write_cmd_data(0x0039,0x0707);
write_cmd_data(0x003C,0x0405);//0504
write_cmd_data(0x003D,0x0F02);
//窗口设置
write_cmd_data(0x0050,0x0000);//水平起始位置
write_cmd_data(0x0051,0x013F);//水平终止位置 //
write_cmd_data(0x0052,0x0000);//垂直起始位置
write_cmd_data(0x0053,0x013F);//垂直终止位置
write_cmd_data(0x0060,0xA700);//门扫描设置,GS=1:从G320扫描到G1,320线
write_cmd_data(0x0061,0x0001);
write_cmd_data(0x006A,0x0000);
//
write_cmd_data(0x0080,0x0000);
write_cmd_data(0x0081,0x0000);
write_cmd_data(0x0082,0x0000);
write_cmd_data(0x0083,0x0000);
write_cmd_data(0x0084,0x0000);
write_cmd_data(0x0085,0x0000);
//
write_cmd_data(0x0090,0x0010);
write_cmd_data(0x0092,0x0600);
write_cmd_data(0x0093,0x0003);
write_cmd_data(0x0095,0x0110);
write_cmd_data(0x0097,0x0000);
write_cmd_data(0x0098,0x0000);
write_cmd_data(0x0007,0x0133);
//write_cmd_data(0x0022);
LCD_CS_H;
}
后来改过的程序
void init_s95417(void)
{
LCD_CS_H;
delay(5);
LCD_RST_L;
delay(50);
LCD_RST_H;
//LCD_RD_H;
LCD_CS_L;
delay(50);//可以适当调整延时,保障稳定显示
//write_cmd_data(0x0000,0x0001); //开启内部晶振
write_cmd_data(0x0001,0x0100); //源扫描设置SS=0, 输出的移动方向是从S1到S720
//(源扫描设置SS=1, 输出的移动方向是从S720到S1)
//SM=0,逐行扫描(SM=1,隔行扫描)
write_cmd_data(0x0002,0x0700); //B/C=1、EOR=1:行倒置(B/C=0:帧/场倒置)
write_cmd_data(0x0003,0x1098); //AM=1,地址在水平方向自动加1 //1030
//I/D[1:0] = 10:水平垂直方向均增加
//ORG=1
//BGR=1:采用BGR格式
//TRI=0、DFM=*:8位机、两次数据传送
write_cmd_data(0x0004,0x0000); //比例缩放设置:不缩放
//显示控制
write_cmd_data(0x0008,0x0207); //设置后边沿和前沿
write_cmd_data(0x0009,0x0000);//设置非显示区时间间隔ISC[3:0]
write_cmd_data(0x000A,0x0000); //帧标记功能
write_cmd_data(0x000C,0x0000);//RGB显示接口控制1
write_cmd_data(0x000D,0x0000);//帧标记位置
write_cmd_data(0x000F,0x0000);//RGB显示接口控制2
//电源配置
write_cmd_data(0x0010,0x0000);
write_cmd_data(0x0011,0x0007);
write_cmd_data(0x0012,0x0000);
write_cmd_data(0x0013,0x0000);
//vgh
write_cmd_data(0x0010,0x1290);
write_cmd_data(0x0011,0x0227);
//delay(100);
//vregiout
write_cmd_data(0x0012,0x001d); //0x001b
//delay(100);
//vom amplitude
write_cmd_data(0x0013,0x1500);
//delay(100);
//vom H
write_cmd_data(0x0029,0x0018);
write_cmd_data(0x002B,0x000D);
//伽马校正
write_cmd_data(0x0030,0x0004);
write_cmd_data(0x0031,0x0307);
write_cmd_data(0x0032,0x0002);//0006
write_cmd_data(0x0035,0x0206);
write_cmd_data(0x0036,0x0408);
write_cmd_data(0x0037,0x0507);
write_cmd_data(0x0038,0x0204);//0200
write_cmd_data(0x0039,0x0707);
write_cmd_data(0x003C,0x0405);//0504
write_cmd_data(0x003D,0x0F02);
//窗口设置
write_cmd_data(0x0050,0x0000);//水平起始位置
write_cmd_data(0x0051,0x013F);//水平终止位置 //
write_cmd_data(0x0052,0x0000);//垂直起始位置
write_cmd_data(0x0053,0x013F);//垂直终止位置
write_cmd_data(0x0060,0xA700);//门扫描设置,GS=1:从G320扫描到G1,320线
write_cmd_data(0x0061,0x0001);
write_cmd_data(0x006A,0x0000);
//
write_cmd_data(0x0080,0x0000);
write_cmd_data(0x0081,0x0000);
write_cmd_data(0x0082,0x0000);
write_cmd_data(0x0083,0x0000);
write_cmd_data(0x0084,0x0000);
write_cmd_data(0x0085,0x0000);
//
write_cmd_data(0x0090,0x0010);
write_cmd_data(0x0092,0x0600);
write_cmd_data(0x0093,0x0003);
write_cmd_data(0x0095,0x0110);
write_cmd_data(0x0097,0x0000);
write_cmd_data(0x0098,0x0000);
write_cmd_data(0x0007,0x0133);
//write_cmd_data(0x0022);
LCD_CS_H;
}
其实就是把开头的1个delay延时时间改长了,因为液晶显示屏可能质量不同,质量差一点的,当单片机上电后,它还没有准备好,结果显示就出现问题了,时间改长之后,让它初始化的更稳定些。
但一天之后发现有的液晶出现花屏,即有的字或字母显示不清楚,还有就是上电之后液晶顶部大概8个单位宽的横条出现黑色,也就是没有任何颜色。后来发现还是这个延迟稍长了一点。
经过几次实验之后,得出了3个档,分别是5,20,50,绝大部分是在20就可以的,如果不行,根据不同情况进行调整。