1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
27
28
31
32
37
38
41
42
45
46
49
50
53
54
57
58
61
62
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
87
88
91
92
95
96
99
100
105
106
107
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
242
246
247
252
256
257
262
267
268
274
279
280
287
288
289
290
291
292
293
294
295
296
297
298
299
304
305
306
307
308
309
310
311
312
313
319
326
327
332
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
414
415
416
417
418
419
420
421
422
423
424
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
488
489
492
493
496
497
/* ... */
#include "ili9325.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
LCD_DrvTypeDef ili9325_drv =
{
ili9325_Init,
ili9325_ReadID,
ili9325_DisplayOn,
ili9325_DisplayOff,
ili9325_SetCursor,
ili9325_WritePixel,
ili9325_ReadPixel,
ili9325_SetDisplayWindow,
ili9325_DrawHLine,
ili9325_DrawVLine,
ili9325_GetLcdPixelWidth,
ili9325_GetLcdPixelHeight,
ili9325_DrawBitmap,
ili9325_DrawRGBImage,
...};
static uint16_t ArrayRGB[320] = {0};
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
void ili9325_Init(void)
{
LCD_IO_Init();
Initialize ILI9325 low level bus layer
ili9325_WriteReg(LCD_REG_0, 0x0001);
ili9325_WriteReg(LCD_REG_1, 0x0100);
ili9325_WriteReg(LCD_REG_2, 0x0700);
ili9325_WriteReg(LCD_REG_3, 0x1018);
ili9325_WriteReg(LCD_REG_4, 0x0000);
ili9325_WriteReg(LCD_REG_8, 0x0202);
ili9325_WriteReg(LCD_REG_9, 0x0000);
ili9325_WriteReg(LCD_REG_10, 0x0000);
ili9325_WriteReg(LCD_REG_12, 0x0000);
ili9325_WriteReg(LCD_REG_13, 0x0000);
ili9325_WriteReg(LCD_REG_15, 0x0000);
Start Initial Sequence
ili9325_WriteReg(LCD_REG_16, 0x0000);
ili9325_WriteReg(LCD_REG_17, 0x0000);
ili9325_WriteReg(LCD_REG_18, 0x0000);
ili9325_WriteReg(LCD_REG_19, 0x0000);
ili9325_WriteReg(LCD_REG_16, 0x17B0);
ili9325_WriteReg(LCD_REG_17, 0x0137);
ili9325_WriteReg(LCD_REG_18, 0x0139);
ili9325_WriteReg(LCD_REG_19, 0x1d00);
ili9325_WriteReg(LCD_REG_41, 0x0013);
ili9325_WriteReg(LCD_REG_32, 0x0000);
ili9325_WriteReg(LCD_REG_33, 0x0000);
Power On sequence
ili9325_WriteReg(LCD_REG_48, 0x0007);
ili9325_WriteReg(LCD_REG_49, 0x0302);
ili9325_WriteReg(LCD_REG_50, 0x0105);
ili9325_WriteReg(LCD_REG_53, 0x0206);
ili9325_WriteReg(LCD_REG_54, 0x0808);
ili9325_WriteReg(LCD_REG_55, 0x0206);
ili9325_WriteReg(LCD_REG_56, 0x0504);
ili9325_WriteReg(LCD_REG_57, 0x0007);
ili9325_WriteReg(LCD_REG_60, 0x0105);
ili9325_WriteReg(LCD_REG_61, 0x0808);
Adjust the Gamma Curve (ILI9325)
ili9325_WriteReg(LCD_REG_80, 0x0000);
ili9325_WriteReg(LCD_REG_81, 0x00EF);
ili9325_WriteReg(LCD_REG_82, 0x0000);
ili9325_WriteReg(LCD_REG_83, 0x013F);
ili9325_WriteReg(LCD_REG_96, 0xA700);
ili9325_WriteReg(LCD_REG_97, 0x0001);
ili9325_WriteReg(LCD_REG_106, 0x0000);
Set GRAM area
ili9325_WriteReg(LCD_REG_128, 0x0000);
ili9325_WriteReg(LCD_REG_129, 0x0000);
ili9325_WriteReg(LCD_REG_130, 0x0000);
ili9325_WriteReg(LCD_REG_131, 0x0000);
ili9325_WriteReg(LCD_REG_132, 0x0000);
ili9325_WriteReg(LCD_REG_133, 0x0000);
Partial Display Control
ili9325_WriteReg(LCD_REG_144, 0x0010);
ili9325_WriteReg(LCD_REG_146, 0x0000);
ili9325_WriteReg(LCD_REG_147, 0x0003);
ili9325_WriteReg(LCD_REG_149, 0x0110);
ili9325_WriteReg(LCD_REG_151, 0x0000);
ili9325_WriteReg(LCD_REG_152, 0x0000);
ili9325_WriteReg(LCD_REG_3, 0x1018);
ili9325_WriteReg(LCD_REG_7, 0x0173);
ili9325_SetCursor(0, 0);
LCD_IO_WriteReg(LCD_REG_34);
}{ ... }
/* ... */
void ili9325_DisplayOn(void)
{
ili9325_WriteReg(LCD_REG_16, 0x0000);
ili9325_WriteReg(LCD_REG_17, 0x0000);
ili9325_WriteReg(LCD_REG_18, 0x0000);
ili9325_WriteReg(LCD_REG_19, 0x0000);
ili9325_WriteReg(LCD_REG_16, 0x17B0);
ili9325_WriteReg(LCD_REG_17, 0x0137);
ili9325_WriteReg(LCD_REG_18, 0x0139);
ili9325_WriteReg(LCD_REG_19, 0x1d00);
ili9325_WriteReg(LCD_REG_41, 0x0013);
ili9325_WriteReg(LCD_REG_7, 0x0173);
}{ ... }
/* ... */
void ili9325_DisplayOff(void)
{
ili9325_WriteReg(LCD_REG_16, 0x0000);
ili9325_WriteReg(LCD_REG_17, 0x0000);
ili9325_WriteReg(LCD_REG_18, 0x0000);
ili9325_WriteReg(LCD_REG_19, 0x0000);
ili9325_WriteReg(LCD_REG_41, 0x0000);
ili9325_WriteReg(LCD_REG_7, 0x0);
}{ ... }
/* ... */
uint16_t ili9325_GetLcdPixelWidth(void)
{
return (uint16_t)320;
}{ ... }
/* ... */
uint16_t ili9325_GetLcdPixelHeight(void)
{
return (uint16_t)240;
}{ ... }
/* ... */
uint16_t ili9325_ReadID(void)
{
LCD_IO_Init();
return (ili9325_ReadReg(0x00));
}{ ... }
/* ... */
void ili9325_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
ili9325_WriteReg(LCD_REG_32, Ypos);
ili9325_WriteReg(LCD_REG_33, (ILI9325_LCD_PIXEL_WIDTH - 1 - Xpos));
}{ ... }
/* ... */
void ili9325_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
{
ili9325_SetCursor(Xpos, Ypos);
LCD_IO_WriteReg(LCD_REG_34);
LCD_IO_WriteMultipleData((uint8_t*)&RGBCode, 2);
}{ ... }
/* ... */
uint16_t ili9325_ReadPixel(uint16_t Xpos, uint16_t Ypos)
{
ili9325_SetCursor(Xpos, Ypos);
return (LCD_IO_ReadData(LCD_REG_34));
}{ ... }
/* ... */
void ili9325_WriteReg(uint8_t LCDReg, uint16_t LCDRegValue)
{
LCD_IO_WriteReg(LCDReg);
LCD_IO_WriteMultipleData((uint8_t*)&LCDRegValue, 2);
}{ ... }
/* ... */
uint16_t ili9325_ReadReg(uint8_t LCDReg)
{
return (LCD_IO_ReadData(LCDReg));
}{ ... }
/* ... */
void ili9325_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
ili9325_WriteReg(LCD_REG_80, (Ypos));
ili9325_WriteReg(LCD_REG_81, (Ypos + Height - 1));
ili9325_WriteReg(LCD_REG_82, ILI9325_LCD_PIXEL_WIDTH - Xpos - Width);
ili9325_WriteReg(LCD_REG_83, ILI9325_LCD_PIXEL_WIDTH - Xpos - 1);
}{ ... }
/* ... */
void ili9325_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
ili9325_SetCursor(Xpos, Ypos);
LCD_IO_WriteReg(LCD_REG_34);
for(counter = 0; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}for (counter = 0; counter < Length; counter++) { ... }
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
}{ ... }
/* ... */
void ili9325_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
{
uint16_t counter = 0;
ili9325_WriteReg(LCD_REG_3, 0x1010);
ili9325_SetCursor(Xpos, Ypos);
LCD_IO_WriteReg(LCD_REG_34);
for(counter = 0; counter < Length; counter++)
{
ArrayRGB[counter] = RGBCode;
}for (counter = 0; counter < Length; counter++) { ... }
LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
ili9325_WriteReg(LCD_REG_3, 0x1018);
}{ ... }
/* ... */
void ili9325_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
{
uint32_t index = 0, size = 0;
size = *(volatile uint16_t *) (pbmp + 2);
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
index = *(volatile uint16_t *) (pbmp + 10);
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
size = (size - index)/2;
pbmp += index;
ili9325_WriteReg(LCD_REG_3, 0x1008);
ili9325_SetCursor(Xpos, Ypos);
LCD_IO_WriteReg(LCD_REG_34);
LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*2);
ili9325_WriteReg(LCD_REG_3, 0x1018);
}{ ... }
/* ... */
void ili9325_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
{
uint32_t size = 0;
size = (Xsize * Ysize);
ili9325_SetCursor(Xpos, Ypos);
LCD_IO_WriteReg(LCD_REG_34);
LCD_IO_WriteMultipleData((uint8_t*)pdata, size*2);
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */