ILI9341 TFT LCD驱动器初始化配置详解

这里我重新按照官方英文手册配置了LCD寄存器,并加了详细中文说明,供参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* 函数功能: 初始化LCD寄存器
* 输入参数: 无
* 返 回 值: 无
* 说 明:需要配置哪些寄存器,需要设置什么值与液晶厂家生产环境密切相关,
* 所以这些参数由厂家提供,不同厂家可能不同。也可以根据ILI9341芯片
* 手册内容参考修改。
*/
static void ILI9341_REG_Config ( void )
{

/* Power control B (CFh) */
/* 功耗控制B */
DEBUG_DELAY();
LCD_WRITE_CMD(0xCF);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x81);
LCD_WRITE_DATA(0x30);

/* Power on sequence control (EDh) */
/* 电源时序控制 */
DEBUG_DELAY();
LCD_WRITE_CMD(0xED);
LCD_WRITE_DATA(0x64);
LCD_WRITE_DATA(0x03);
LCD_WRITE_DATA(0x12);
LCD_WRITE_DATA(0x81);

/* Driver timing control A (E8h) */
/* 驱动时序控制A */
DEBUG_DELAY();
LCD_WRITE_CMD(0xE8);
LCD_WRITE_DATA(0x85);
LCD_WRITE_DATA(0x10);
LCD_WRITE_DATA(0x78);

/* Power control A (CBh) */
/* 功耗控制A */
DEBUG_DELAY();
LCD_WRITE_CMD(0xCB);
LCD_WRITE_DATA(0x39);
LCD_WRITE_DATA(0x2C);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x34);
LCD_WRITE_DATA(0x02);

/* Pump ratio control (F7h) */
/* 泵比控制 */
DEBUG_DELAY();
LCD_WRITE_CMD(0xF7);
LCD_WRITE_DATA(0x20);

/* Driver timing control B(EAh) */
/* 驱动时序控制B */
DEBUG_DELAY();
LCD_WRITE_CMD(0xEA);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x00);

/* Frame Rate Control (In Normal Mode/Full Colors) (B1h) */
/* 帧速率控制(正常模式/全色模式) */
DEBUG_DELAY();
LCD_WRITE_CMD(0xB1);
LCD_WRITE_DATA(0x00);
//此处RTNA[4:0]=11100,对应帧频率是68HZ,使用的是正常模式,内部时钟分频
LCD_WRITE_DATA(0x1B);

/* Display Function Control (B6h) */
/*显示功能设置控制*/
//按理有四个参数,为什么参考的例程只写了两个参数,其它是默认吗
DEBUG_DELAY();
LCD_WRITE_CMD(0xB6);
LCD_WRITE_DATA(0x0A);
LCD_WRITE_DATA(0xA2);

/* Power Control 1 (C0h) */
/*功耗控制1*/
DEBUG_DELAY();
LCD_WRITE_CMD(0xC0);
//VRH[5:0]:设置GVDD电平,作为VCOM电平和灰度电压的基准电压,当前设置GVDD为5.5V
LCD_WRITE_DATA(0x35);

/* Power Control 2 (C1h) */
/*功耗控制2*/
DEBUG_DELAY();
//设置最佳的工作电压的升压因子,为了降低功耗,设置一个较小的因子
LCD_WRITE_CMD(0xC1);
//应该是0x01,不应该是0x11,此处貌似参考的野火的例程写的有问题
LCD_WRITE_DATA(0x01);

/* VCOM Control 1(C5h) */
/*VCOM控制1*/
LCD_WRITE_CMD(0xC5);
LCD_WRITE_DATA(0x45);
LCD_WRITE_DATA(0x45);

/* VCOM Control 2(C7h) */
/*VCOM控制2*/
LCD_WRITE_CMD(0xC7);
LCD_WRITE_DATA(0xA2);

/* Enable 3G (F2h) */
/*使能3G*/
LCD_WRITE_CMD(0xF2);
//0x01为使能伽马控制,不知道野火的代码为什么0x00不启用,不启用的话后面的设置不是无效了吗
LCD_WRITE_DATA(0x01);

/* Gamma Set (26h) */
/*伽马设置*/
LCD_WRITE_CMD(0x26);
//按理没有参数,不知道官方为什么要写入数据,况且既然已经不启用伽马控制了,写什么伽马设置
//GC[7:0]01是伽马曲线1(G2.2)
LCD_WRITE_DATA(0x01);
DEBUG_DELAY();

/* Positive Gamma Correction(E0h) */
/*正极伽马校正*/
LCD_WRITE_CMD(0xE0); //Set Gamma
LCD_WRITE_DATA(0x0F);
LCD_WRITE_DATA(0x26);
LCD_WRITE_DATA(0x24);
LCD_WRITE_DATA(0x0B);
LCD_WRITE_DATA(0x0E);
LCD_WRITE_DATA(0x09);
LCD_WRITE_DATA(0x54);
LCD_WRITE_DATA(0xA8);
LCD_WRITE_DATA(0x46);
LCD_WRITE_DATA(0x0C);
LCD_WRITE_DATA(0x17);
LCD_WRITE_DATA(0x09);
LCD_WRITE_DATA(0x0F);
LCD_WRITE_DATA(0x07);
LCD_WRITE_DATA(0x00);

/* Negative Gamma Correction (E1h) */
/*负极伽马校正*/
LCD_WRITE_CMD(0XE1); //Set Gamma
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x19);
LCD_WRITE_DATA(0x1B);
LCD_WRITE_DATA(0x04);
LCD_WRITE_DATA(0x10);
LCD_WRITE_DATA(0x07);
LCD_WRITE_DATA(0x2A);
LCD_WRITE_DATA(0x47);
LCD_WRITE_DATA(0x39);
LCD_WRITE_DATA(0x03);
LCD_WRITE_DATA(0x06);
LCD_WRITE_DATA(0x06);
LCD_WRITE_DATA(0x30);
LCD_WRITE_DATA(0x38);
LCD_WRITE_DATA(0x0F);

/* memory access control set(36h) */
/*存储器访问控制*/
DEBUG_DELAY();
LCD_WRITE_CMD(0x36);
//野火官方默认为0xC8会导致整个屏幕的文字反转
//其它默认即可,关键是其中的BGR参数,默认是BGR模式,需要当心(难怪我之前的颜色不太正常)
LCD_WRITE_DATA(0x08);
DEBUG_DELAY();

/* column address control set (2Ah)*/
/*列地址设置*/
LCD_WRITE_CMD(0x2A);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0xEF);

/* page address control set(2Bh) */
/*行地址设置*/
DEBUG_DELAY();
LCD_WRITE_CMD(0x2B);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x00);
LCD_WRITE_DATA(0x01);
LCD_WRITE_DATA(0x3F);

/* Pixel Format Set (3Ah) */
/*像素格式设置*/
DEBUG_DELAY();
LCD_WRITE_CMD(0x3a);
//设定16BPP
LCD_WRITE_DATA(0x55);

/* Sleep Out (11h) */
/*退出睡眠模式*/
//一个小疑问,为什么要退出睡眠模式呢,难道插电默认就是睡眠状态吗,还是只是为了保险起见,才这么写的呢?
//实际测试结果,注释掉这句确实无法点亮屏幕
LCD_WRITE_CMD(0x11);
//退出睡眠模式后,需要等待120ms
Lcd_Delay(0xAFFf<<2);
DEBUG_DELAY();

/* Display ON (29h) */
/*开显示*/
//28h是关显示,29h是开显示
LCD_WRITE_CMD(0x29);
//初始化完成以后,提速
if(lcd_id==0X9341)//如果是9341IC,则设置WR时序为最快
{
//重新配置写时序控制寄存器的时序
//地址建立时间(ADDSET)清零
FSMC_Bank1E->BWTR[0]&=~(0XF<<0);
//数据保存时间清零
FSMC_Bank1E->BWTR[0]&=~(0XF<<8);
//地址建立时间(ADDSET)为4个HCLK =21ns
FSMC_Bank1E->BWTR[0]|=4<<0;
//数据保存时间(DATAST)为5.2ns*4个HCLK=21ns
FSMC_Bank1E->BWTR[0]|=4<<8;
}
}