-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLCD_SPI_LPC1700.c
1051 lines (891 loc) · 38 KB
/
GLCD_SPI_LPC1700.c
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
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
379
380
381
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* GLCD_SPI_LPC1700.c: LPC1700 low level Graphic LCD (240x320 pixels) driven */
/* with SPI functions */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2010 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
#include <lpc17xx.h>
#include "GLCD.h"
#include "Font_6x8_h.h"
#include "Font_16x24_h.h"
#include "movement/movement.h"
extern char ClockLetters;
extern int index_color_snake,index_color_game, colors[];
/*********************** Hardware specific configuration **********************/
#define HORIZONTAL 1
/* 8bit to 16bit LCD Interface
PINS:
- EN = P0.19
- LE = P0.20
- DIR = P0.21
- CS = P0.22
- RS = P0.23
- WR = P0.24
- RD = P0.25
- DB[0.7] = P2.0...P2.7
- DB[8.15]= P2.0...P2.7 */
#define PIN_EN (1 << 19)
#define PIN_LE (1 << 20)
#define PIN_DIR (1 << 21)
#define PIN_CS (1 << 22)
#define PIN_RS (1 << 23)
#define PIN_WR (1 << 24)
#define PIN_RD (1 << 25)
/* SPI_SR - bit definitions */
#define TFE 0x01
#define RNE 0x04
#define BSY 0x10
/*------------------------- Speed dependant settings -------------------------*/
/* If processor works on high frequency delay has to be increased, it can be
increased by factor 2^N by this constant */
#define DELAY_2N 18
/*---------------------- Graphic LCD size definitions ------------------------*/
#define WIDTH 320 /* Screen Width (in pixels) */
#define HEIGHT 240 /* Screen Hight (in pixels) */
#define BPP 16 /* Bits per pixel */
#define BYPP ((BPP+7)/8) /* Bytes per pixel */
/*--------------- Graphic LCD interface hardware definitions -----------------*/
/* Pin EN setting to 0 or 1 */
#define LCD_EN(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_EN) : (LPC_GPIO0->FIOCLR = PIN_EN));
/* Pin LE setting to 0 or 1 */
#define LCD_LE(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_LE) : (LPC_GPIO0->FIOCLR = PIN_LE));
/* Pin DIR setting to 0 or 1 */
#define LCD_DIR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_DIR) : (LPC_GPIO0->FIOCLR = PIN_DIR));
/* Pin CS setting to 0 or 1 */
#define LCD_CS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_CS) : (LPC_GPIO0->FIOCLR = PIN_CS));
/* Pin RS setting to 0 or 1 */
#define LCD_RS(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RS) : (LPC_GPIO0->FIOCLR = PIN_RS));
/* Pin WR setting to 0 or 1 */
#define LCD_WR(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_WR) : (LPC_GPIO0->FIOCLR = PIN_WR));
/* Pin RD setting to 0 or 1 */
#define LCD_RD(x) ((x) ? (LPC_GPIO0->FIOSET = PIN_RD) : (LPC_GPIO0->FIOCLR = PIN_RD));
/*---------------------------- Global variables ------------------------------*/
/******************************************************************************/
static volatile unsigned short TextColor = Black, BackColor = White;
static unsigned short driverCode;
/************************ Local auxiliary functions ***************************/
/*******************************************************************************
* Delay in while loop cycles *
* Parameter: cnt: number of while cycles to delay *
* Return: *
*******************************************************************************/
static void delay (int cnt) {
cnt <<= DELAY_2N;
while (cnt--);
}
__asm void wait()
{
nop
BX lr
}
void wait_delay(int count)
{
while(count--);
}
/*******************************************************************************
* Send 1 byte over serial communication *
* Parameter: byte: byte to be sent *
* Return: *
*******************************************************************************/
static __inline unsigned char lcd_send (unsigned short byte) {
LPC_GPIO2->FIODIR |= 0x000000ff; //P2.0...P2.7 Output
LCD_DIR(1) //Interface A->B
LCD_EN(0) //Enable 2A->2B
LPC_GPIO2->FIOPIN = byte; //Write D0..D7
LCD_LE(1)
LCD_LE(0) //latch D0..D7
LPC_GPIO2->FIOPIN = byte >> 8; //Write D8..D15
return(1);
}
/*******************************************************************************
* read 1 byte over serial communication *
* Parameter: byte: byte to be sent *
* Return: *
*******************************************************************************/
static __inline unsigned short lcd_read (void) {
unsigned short id;
LPC_GPIO2->FIODIR &= 0xffffff00; //P2.0...P2.7 Input
LCD_DIR(0) //Interface B->A
LCD_EN(0) //Enable 2B->2A
wait_delay(80); //delay some times
id = LPC_GPIO2->FIOPIN & 0x00ff; //Read D8..D15
LCD_EN(1) //Enable 1B->1A
wait_delay(80); //delay some times
id = (id << 8) | (LPC_GPIO2->FIOPIN & 0x00ff); //Read D0..D7
LCD_DIR(1)
return(id);
}
/*******************************************************************************
* Write a command the LCD controller *
* Parameter: cmd: command to be written *
* Return: *
*******************************************************************************/
static __inline void wr_cmd (unsigned char cmd) {
LCD_RS(0)
LCD_RD(1)
lcd_send(cmd);
LCD_WR(0)
wait();
LCD_WR(1)
}
/*******************************************************************************
* Write data to the LCD controller *
* Parameter: dat: data to be written *
* Return: *
*******************************************************************************/
static __inline void wr_dat (unsigned short dat) {
LCD_RS(1)
LCD_RD(1)
lcd_send(dat);
LCD_WR(0)
wait();
LCD_WR(1)
}
/*******************************************************************************
* Start of data writing to the LCD controller *
* Parameter: *
* Return: *
*******************************************************************************/
static __inline void wr_dat_start (void) {
LCD_RS(1)
}
/*******************************************************************************
* Stop of data writing to the LCD controller *
* Parameter: *
* Return: *
*******************************************************************************/
static __inline void wr_dat_stop (void) {
LCD_CS(1)
}
/*******************************************************************************
* Data writing to the LCD controller *
* Parameter: dat: data to be written *
* Return: *
*******************************************************************************/
static __inline void wr_dat_only (unsigned short dat) {
lcd_send(dat);
LCD_WR(0)
wait();
LCD_WR(1)
}
/*******************************************************************************
* Read data from the LCD controller *
* Parameter: *
* Return: read data *
*******************************************************************************/
static __inline unsigned short rd_dat (void) {
unsigned short val = 0;
LCD_RS(1)
LCD_WR(1)
LCD_RD(0)
val = lcd_read();
LCD_RD(1)
return val;
}
/*******************************************************************************
* Write a value to the to LCD register *
* Parameter: reg: register to be written *
* val: value to write to the register *
*******************************************************************************/
static __inline void wr_reg (unsigned char reg, unsigned short val) {
LCD_CS(0)
wr_cmd(reg);
wr_dat(val);
LCD_CS(1)
}
/*******************************************************************************
* Read from the LCD register *
* Parameter: reg: register to be read *
* Return: value read from the register *
*******************************************************************************/
static unsigned short rd_reg (unsigned char reg) {
unsigned short val = 0;
LCD_CS(0)
wr_cmd(reg);
val = rd_dat();
LCD_CS(1)
return (val);
}
/************************ Exported functions **********************************/
/*******************************************************************************
* Initialize the Graphic LCD controller *
* Parameter: *
* Return: *
*******************************************************************************/
void GLCD_Init (void) {
/* Configure the LCD Control pins */
LPC_GPIO0->FIODIR |= 0x03f80000;
LPC_GPIO0->FIOSET = 0x03f80000;
delay(5); /* Delay 50 ms */
driverCode = rd_reg(0x00);
if(driverCode == 0x4531) //2.8" TFT LCD Module,DriverIC is LGDP4531
{
wr_reg(0x00,0x0001);
wr_reg(0x10,0x0628);
wr_reg(0x12,0x0006);
wr_reg(0x13,0x0A32);
wr_reg(0x11,0x0040);
wr_reg(0x15,0x0050);
wr_reg(0x12,0x0016);
delay(15);
wr_reg(0x10,0x5660);
delay(15);
wr_reg(0x13,0x2A4E);
wr_reg(0x01,0x0100);
wr_reg(0x02,0x0300);
wr_reg(0x03,0x1030);
wr_reg(0x08,0x0202);
wr_reg(0x0A,0x0000);
wr_reg(0x30,0x0000);
wr_reg(0x31,0x0402);
wr_reg(0x32,0x0106);
wr_reg(0x33,0x0700);
wr_reg(0x34,0x0104);
wr_reg(0x35,0x0301);
wr_reg(0x36,0x0707);
wr_reg(0x37,0x0305);
wr_reg(0x38,0x0208);
wr_reg(0x39,0x0F0B);
delay(15);
wr_reg(0x41,0x0002);
wr_reg(0x60,0x2700);
wr_reg(0x61,0x0001);
wr_reg(0x90,0x0119);
wr_reg(0x92,0x010A);
wr_reg(0x93,0x0004);
wr_reg(0xA0,0x0100);
delay(15);
wr_reg(0xA0,0x0000);
delay(20);
}
else if(driverCode == 0x9325) //2.8" TFT LCD Module,DriverIC is ILI9325
{
wr_reg(0x00e7,0x0010);
wr_reg(0x0000,0x0001); //start internal osc
wr_reg(0x0001,0x0100);
wr_reg(0x0002,0x0700); //power on sequence
wr_reg(0x0003,(1<<12)|(1<<5)|(1<<4) ); //65K
wr_reg(0x0004,0x0000);
wr_reg(0x0008,0x0207);
wr_reg(0x0009,0x0000);
wr_reg(0x000a,0x0000); //display setting
wr_reg(0x000c,0x0001); //display setting
wr_reg(0x000d,0x0000); //0f3c
wr_reg(0x000f,0x0000);
//Power On sequence //
wr_reg(0x0010,0x0000);
wr_reg(0x0011,0x0007);
wr_reg(0x0012,0x0000);
wr_reg(0x0013,0x0000);
delay(15);
wr_reg(0x0010,0x1590);
wr_reg(0x0011,0x0227);
delay(15);
wr_reg(0x0012,0x009c);
delay(15);
wr_reg(0x0013,0x1900);
wr_reg(0x0029,0x0023);
wr_reg(0x002b,0x000e);
delay(15);
wr_reg(0x0020,0x0000);
wr_reg(0x0021,0x0000);
///////////////////////////////////////////////////////
delay(15);
wr_reg(0x0030,0x0007);
wr_reg(0x0031,0x0707);
wr_reg(0x0032,0x0006);
wr_reg(0x0035,0x0704);
wr_reg(0x0036,0x1f04);
wr_reg(0x0037,0x0004);
wr_reg(0x0038,0x0000);
wr_reg(0x0039,0x0706);
wr_reg(0x003c,0x0701);
wr_reg(0x003d,0x000f);
delay(15);
wr_reg(0x0050,0x0000);
wr_reg(0x0051,0x00ef);
wr_reg(0x0052,0x0000);
wr_reg(0x0053,0x013f);
wr_reg(0x0060,0xa700);
wr_reg(0x0061,0x0001);
wr_reg(0x006a,0x0000);
wr_reg(0x0080,0x0000);
wr_reg(0x0081,0x0000);
wr_reg(0x0082,0x0000);
wr_reg(0x0083,0x0000);
wr_reg(0x0084,0x0000);
wr_reg(0x0085,0x0000);
wr_reg(0x0090,0x0010);
wr_reg(0x0092,0x0000);
wr_reg(0x0093,0x0003);
wr_reg(0x0095,0x0110);
wr_reg(0x0097,0x0000);
wr_reg(0x0098,0x0000);
//display on sequence
wr_reg(0x0007,0x0133);
wr_reg(0x0020,0x0000);
wr_reg(0x0021,0x0000);
}
else if(driverCode == 0x9320) //3.2" TFT LCD Module,DriverIC is ILI9320
{
/* Start Initial Sequence --------------------------------------------------*/
wr_reg(0xE5, 0x8000); /* Set the internal vcore voltage */
wr_reg(0x00, 0x0001); /* Start internal OSC */
wr_reg(0x01, 0x0100); /* Set SS and SM bit */
wr_reg(0x02, 0x0700); /* Set 1 line inversion */
wr_reg(0x03, 0x1030); /* Set GRAM write direction and BGR=1 */
wr_reg(0x04, 0x0000); /* Resize register */
wr_reg(0x08, 0x0202); /* 2 lines each, back and front porch */
wr_reg(0x09, 0x0000); /* Set non-disp area refresh cyc ISC */
wr_reg(0x0A, 0x0000); /* FMARK function */
wr_reg(0x0C, 0x0000); /* RGB interface setting */
wr_reg(0x0D, 0x0000); /* Frame marker Position */
wr_reg(0x0F, 0x0000); /* RGB interface polarity */
/* Power On sequence -------------------------------------------------------*/
wr_reg(0x10, 0x0000); /* Reset Power Control 1 */
wr_reg(0x11, 0x0000); /* Reset Power Control 2 */
wr_reg(0x12, 0x0000); /* Reset Power Control 3 */
wr_reg(0x13, 0x0000); /* Reset Power Control 4 */
delay(20); /* Discharge cap power voltage (200ms)*/
wr_reg(0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
wr_reg(0x11, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
delay(5); /* Delay 50 ms */
wr_reg(0x12, 0x0139); /* VREG1OUT voltage */
delay(5); /* Delay 50 ms */
wr_reg(0x13, 0x1D00); /* VDV[4:0] for VCOM amplitude */
wr_reg(0x29, 0x0013); /* VCM[4:0] for VCOMH */
delay(5); /* Delay 50 ms */
wr_reg(0x20, 0x0000); /* GRAM horizontal Address */
wr_reg(0x21, 0x0000); /* GRAM Vertical Address */
/* Adjust the Gamma Curve --------------------------------------------------*/
wr_reg(0x30, 0x0006);
wr_reg(0x31, 0x0101);
wr_reg(0x32, 0x0003);
wr_reg(0x35, 0x0106);
wr_reg(0x36, 0x0B02);
wr_reg(0x37, 0x0302);
wr_reg(0x38, 0x0707);
wr_reg(0x39, 0x0007);
wr_reg(0x3C, 0x0600);
wr_reg(0x3D, 0x020B);
/* Set GRAM area -----------------------------------------------------------*/
wr_reg(0x50, 0x0000); /* Horizontal GRAM Start Address */
wr_reg(0x51, (HEIGHT-1)); /* Horizontal GRAM End Address */
wr_reg(0x52, 0x0000); /* Vertical GRAM Start Address */
wr_reg(0x53, (WIDTH-1)); /* Vertical GRAM End Address */
wr_reg(0x60, 0x2700); /* Gate Scan Line */
wr_reg(0x61, 0x0001); /* NDL,VLE, REV */
wr_reg(0x6A, 0x0000); /* Set scrolling line */
/* Partial Display Control -------------------------------------------------*/
wr_reg(0x80, 0x0000);
wr_reg(0x81, 0x0000);
wr_reg(0x82, 0x0000);
wr_reg(0x83, 0x0000);
wr_reg(0x84, 0x0000);
wr_reg(0x85, 0x0000);
/* Panel Control -----------------------------------------------------------*/
wr_reg(0x90, 0x0010);
wr_reg(0x92, 0x0000);
wr_reg(0x93, 0x0003);
wr_reg(0x95, 0x0110);
wr_reg(0x97, 0x0000);
wr_reg(0x98, 0x0000);
}
/* Set GRAM write direction and BGR = 1
I/D=10 (Horizontal : increment, Vertical : increment)
AM=1 (address is updated in vertical writing direction) */
wr_reg(0x03, 0x1038);
wr_reg(0x07, 0x0173); /* 262K color and display ON */
if(driverCode == 0x8989) //3.2" TFT LCD Module,DriverIC is SSD1289
{
wr_reg(0x0000,0x0001); delay(5); //打开晶振
wr_reg(0x0003,0xA8A4); delay(5); //0xA8A4
wr_reg(0x000C,0x0000); delay(5);
wr_reg(0x000D,0x080C); delay(5);
wr_reg(0x000E,0x2B00); delay(5);
wr_reg(0x001E,0x00B0); delay(5);
wr_reg(0x0001,0x2b3F); delay(5); //驱动输出控制320*240 0x6B3F 293f 2b3f 6b3f
wr_reg(0x0002,0x0600); delay(5);
wr_reg(0x0010,0x0000); delay(5);
wr_reg(0x0011,0x6078); delay(5); //0x4030 //定义数据格式 16位色 横屏 0x6058 6078
wr_reg(0x0005,0x0000); delay(5);
wr_reg(0x0006,0x0000); delay(5);
wr_reg(0x0016,0xEF1C); delay(5);
wr_reg(0x0017,0x0003); delay(5);
wr_reg(0x0007,0x0233); delay(5); //0x0233
wr_reg(0x000B,0x0000); delay(5);
wr_reg(0x000F,0x0000); delay(5); //扫描开始地址
wr_reg(0x0041,0x0000); delay(5);
wr_reg(0x0042,0x0000); delay(5);
wr_reg(0x0048,0x0000); delay(5);
wr_reg(0x0049,0x013F); delay(5);
wr_reg(0x004A,0x0000); delay(5);
wr_reg(0x004B,0x0000); delay(5);
wr_reg(0x0044,0xEF00); delay(5);
wr_reg(0x0045,0x0000); delay(5);
wr_reg(0x0046,0x013F); delay(5);
wr_reg(0x0030,0x0707); delay(5);
wr_reg(0x0031,0x0204); delay(5);
wr_reg(0x0032,0x0204); delay(5);
wr_reg(0x0033,0x0502); delay(5);
wr_reg(0x0034,0x0507); delay(5);
wr_reg(0x0035,0x0204); delay(5);
wr_reg(0x0036,0x0204); delay(5);
wr_reg(0x0037,0x0502); delay(5);
wr_reg(0x003A,0x0302); delay(5);
wr_reg(0x003B,0x0302); delay(5);
wr_reg(0x0023,0x0000); delay(5);
wr_reg(0x0024,0x0000); delay(5);
wr_reg(0x0025,0x8000); delay(5);
wr_reg(0x004f,0); //行首址0
wr_reg(0x004e,0); //列首址0
}
}
/*******************************************************************************
* Set draw window region *
* Parameter: x: horizontal position *
* y: vertical position *
* w: window width in pixel *
* h: window height in pixels *
* Return: *
*******************************************************************************/
void GLCD_SetWindow (unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
if(driverCode==0x8989)
{
wr_reg(0x44, x); /* Horizontal GRAM Start Address */
wr_reg(0x44, 0 |((x+w-1)<<8)); /* Horizontal GRAM End Address (-1) */
wr_reg(0x45, y); /* Vertical GRAM Start Address */
wr_reg(0x46, y+h-1); /* Vertical GRAM End Address (-1) */
/* Set pos */
wr_reg(0x4e, x);
wr_reg(0x4f, y);
}
else
{
wr_reg(0x50, x); /* Horizontal GRAM Start Address */
wr_reg(0x51, x+w-1); /* Horizontal GRAM End Address (-1) */
wr_reg(0x52, y); /* Vertical GRAM Start Address */
wr_reg(0x53, y+h-1); /* Vertical GRAM End Address (-1) */
/* Set pos */
wr_reg(0x20, x);
wr_reg(0x21, y);
}
}
/*******************************************************************************
* Set draw window region to whole screen *
* Parameter: *
* Return: *
*******************************************************************************/
void GLCD_WindowMax (void) {
#if (HORIZONTAL == 1)
GLCD_SetWindow (0, 0, HEIGHT, WIDTH);
#else
GLCD_SetWindow (0, 0, WIDTH, HEIGHT);
#endif
}
/*******************************************************************************
* Draw a pixel in foreground color *
* Parameter: x: horizontal position *
* y: vertical position *
* Return: *
*******************************************************************************/
void GLCD_PutPixel (unsigned int x, unsigned int y) {
if(driverCode==0x8989)
{
#if (HORIZONTAL == 1)
wr_reg(0x4e, y);
wr_reg(0x4f, WIDTH-1-x);
#else
wr_reg(0x4e, x);
wr_reg(0x4f, y);
#endif
}
else
{
#if (HORIZONTAL == 1)
wr_reg(0x20, y);
wr_reg(0x21, WIDTH-1-x);
#else
wr_reg(0x20, x);
wr_reg(0x21, y);
#endif
}
LCD_CS(0)
wr_cmd(0x22);
wr_dat(TextColor);
LCD_CS(1)
}
/*******************************************************************************
* Set foreground color *
* Parameter: color: foreground color *
* Return: *
*******************************************************************************/
void GLCD_SetTextColor (unsigned short color) {
TextColor = color;
}
/*******************************************************************************
* Set background color *
* Parameter: color: background color *
* Return: *
*******************************************************************************/
void GLCD_SetBackColor (unsigned short color) {
BackColor = color;
}
/*******************************************************************************
* Clear display *
* Parameter: color: display clearing color *
* Return: *
*******************************************************************************/
void GLCD_Clear (unsigned short color) {
unsigned int i;
GLCD_WindowMax();
if(driverCode==0x8989)
{
wr_reg(0x4e, 0);
wr_reg(0x4f, 0);
}
else
{
wr_reg(0x20, 0);
wr_reg(0x21, 0);
}
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for(i = 0; i < (WIDTH*HEIGHT); i++)
wr_dat_only(color);
wr_dat_stop();
}
/*******************************************************************************
* Draw character on given position *
* Parameter: x: horizontal position *
* y: vertical position *
* cw: character width in pixel *
* ch: character height in pixels *
* c: pointer to character bitmap *
* Return: *
*******************************************************************************/
void GLCD_DrawChar_U8 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned char *c) {
int idx = 0, i, j;
#if (HORIZONTAL == 1)
x = WIDTH-x-cw;
GLCD_SetWindow(y, x, ch, cw);
#else
GLCD_SetWindow(x, y, cw, ch);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (j = 0; j < ch; j++) {
#if (HORIZONTAL == 1)
for (i = cw-1; i >= 0; i--) {
#else
for (i = 0; i <= cw-1; i++) {
#endif
if((c[idx] & (1 << i)) == 0x00) {
wr_dat_only(BackColor);
} else {
wr_dat_only(TextColor);
}
}
c++;
}
wr_dat_stop();
}
/*******************************************************************************
* Draw character on given position *
* Parameter: x: horizontal position *
* y: vertical position *
* cw: character width in pixel *
* ch: character height in pixels *
* c: pointer to character bitmap *
* Return: *
*******************************************************************************/
void GLCD_DrawChar_U16 (unsigned int x, unsigned int y, unsigned int cw, unsigned int ch, unsigned short *c) {
int idx = 0, i, j;
#if (HORIZONTAL == 1)
x = WIDTH-x-cw;
GLCD_SetWindow(y, x, ch, cw);
#else
GLCD_SetWindow(x, y, cw, ch);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (j = 0; j < ch; j++) {
#if (HORIZONTAL == 1)
for (i = cw-1; i >= 0; i--) {
#else
for (i = 0; i <= cw-1; i++) {
#endif
if((c[idx] & (1 << i)) == 0x00) {
wr_dat_only(BackColor);
} else {
wr_dat_only(TextColor);
}
}
c++;
}
wr_dat_stop();
}
/*******************************************************************************
* Disply character on given line *
* Parameter: ln: line number *
* col: column number *
* fi: font index (0 = 6x8, 1 = 16x24) *
* c: ascii character *
* Return: *
*******************************************************************************/
void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char fi, unsigned char c) {
c -= 32;
switch (fi) {
case 0: /* Font 6 x 8 */
GLCD_DrawChar_U8 (col * 6, ln * 8, 6, 8, (unsigned char *)&Font_6x8_h [c * 8]);
break;
case 1: /* Font 16 x 24 */
GLCD_DrawChar_U16(col * 16, ln * 24, 16, 24, (unsigned short *)&Font_16x24_h[c * 24]);
break;
}
}
/*******************************************************************************
* Disply string on given line *
* Parameter: ln: line number *
* col: column number *
* fi: font index (0 = 6x8, 1 = 16x24) *
* s: pointer to string *
* Return: *
*******************************************************************************/
void GLCD_DisplayString (unsigned int ln, unsigned int col, unsigned char fi, unsigned char *s) {
GLCD_WindowMax();
while (*s) {
GLCD_DisplayChar(ln, col++, fi, *s++);
}
}
void GLCD_DisplayStringTime (unsigned int ln, unsigned int col, unsigned char fi, unsigned char *s, int step) {
GLCD_WindowMax();
while (*s) {
GLCD_DisplayChar(ln, col++, fi, *s++);
delay_ms(step);
}
}
/*******************************************************************************
* Clear given line *
* Parameter: ln: line number *
* fi: font index (0 = 6x8, 1 = 16x24) *
* Return: *
*******************************************************************************/
void GLCD_ClearLn (unsigned int ln, unsigned char fi) {
unsigned char i;
unsigned char buf[60];
GLCD_WindowMax();
switch (fi) {
case 0: /* Font 6 x 8 */
for (i = 0; i < (WIDTH+5)/6; i++)
buf[i] = ' ';
buf[i+1] = 0;
break;
case 1: /* Font 16 x 24 */
for (i = 0; i < (WIDTH+15)/16; i++)
buf[i] = ' ';
buf[i+1] = 0;
break;
}
GLCD_DisplayString (ln, 0, fi, buf);
}
/*******************************************************************************
* Draw bargraph *
* Parameter: x: horizontal position *
* y: vertical position *
* w: maximum width of bargraph (in pixels) *
* val: value of active bargraph (in 1/1024) *
* Return: *
*******************************************************************************/
void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
int i,j;
val = (val * w) >> 10; /* Scale value */
#if (HORIZONTAL == 1)
x = WIDTH-x-w;
GLCD_SetWindow(y, x, h, w);
#else
GLCD_SetWindow(x, y, w, h);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (i = 0; i < h; i++) {
#if (HORIZONTAL == 1)
for (j = w-1; j >= 0; j--) {
#else
for (j = 0; j <= w-1; j++) {
#endif
if(j >= val) {
wr_dat_only(BackColor);
} else {
wr_dat_only(TextColor);
}
}
}
wr_dat_stop();
}
void GLCD_SetBar (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
int i,j;
val = (val * w) >> 10; /* Scale value */
#if (HORIZONTAL == 1)
x = WIDTH-x-w;
GLCD_SetWindow(y, x, h, w);
#else
GLCD_SetWindow(x, y, w, h);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (i = 0; i < h; i++) {
#if (HORIZONTAL == 1)
for (j = w-1; j >= 0; j--) {
#else
for (j = 0; j <= w-1; j++) {
#endif
if(j >= val) {
wr_dat_only(BackColor);
} else {
wr_dat_only(colors[index_color_snake]);
}
}
}
wr_dat_stop();
}
void GLCD_SetClr (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
int i,j;
val = (val * w) >> 10; /* Scale value */
#if (HORIZONTAL == 1)
x = WIDTH-x-w;
GLCD_SetWindow(y, x, h, w);
#else
GLCD_SetWindow(x, y, w, h);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (i = 0; i < h; i++) {
#if (HORIZONTAL == 1)
for (j = w-1; j >= 0; j--) {
#else
for (j = 0; j <= w-1; j++) {
#endif
if(j >= val) {
wr_dat_only(BackColor);
} else {
wr_dat_only(White);
}
}
}
wr_dat_stop();
}
/*******************************************************************************
* Display graphical bitmap image at position x horizontally and y vertically *
* (This function is optimized for 16 bits per pixel format, it has to be *
* adapted for any other bits per pixel format) *
* Parameter: x: horizontal position *
* y: vertical position *
* w: width of bitmap *
* h: height of bitmap *
* bitmap: address at which the bitmap data resides *
* Return: *
*******************************************************************************/
void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) {
unsigned int i, j;
unsigned short *bitmap_ptr = (unsigned short *)bitmap;
#if (HORIZONTAL == 1)
x = WIDTH-x-w;
GLCD_SetWindow(y, x, h, w);
#else
GLCD_SetWindow(x, y, w, h);
#endif
LCD_CS(0)
wr_cmd(0x22);
wr_dat_start();
for (j = 0; j < h; j++) {
#if (HORIZONTAL == 1)
for (i = 0; i < w; i++) {
wr_dat_only(*bitmap_ptr++);
}
#else
bitmap_ptr += w-1;
for (i = 0; i < w; i++) {
wr_dat_only(*bitmap_ptr--);
}
bitmap_ptr += w+1;
#endif
}
wr_dat_stop();
}
/*******************************************************************************
* Display graphical bmp file image at position x horizontally and y vertically *
* (This function is optimized for 16 bits per pixel format, it has to be *
* adapted for any other bits per pixel format) *
* Parameter: x: horizontal position *
* y: vertical position *
* w: width of bitmap *
* h: height of bitmap *
* bmp: address at which the bmp data resides *
* Return: *
*******************************************************************************/
void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) {
unsigned int i, j;
unsigned short *bitmap_ptr = (unsigned short *)bmp;
#if (HORIZONTAL == 1)
x = WIDTH-x-w;
GLCD_SetWindow(y, x, h, w);
#else
GLCD_SetWindow(x, y, w, h);
#endif
LCD_CS(0)