1 | void LcdInit(void)
|
2 | {
|
3 | unsigned char ucDelay = 0,ucStartTime;
|
4 | unsigned int uiDelay = 0, uiStartTime;
|
5 | DATADIR |= 0xFF;
|
6 | CONTROLDIR |= ((1 << CDPIN) | (1 << CSPIN) |
|
7 | (1 << RDPIN) | (1 << WRPIN) | (1 <<RSTPIN));
|
8 | RSTHIGH;
|
9 | WRLOW;
|
10 | RDLOW;
|
11 | CSLOW;
|
12 | EPSONDATA;
|
13 |
|
14 | ucDelay = 0;
|
15 | ucStartTime = TimerGet1SecTick();
|
16 | while (ucDelay < 3) // wait 3 sec
|
17 | ucDelay = TimerGet1SecDiff(ucStartTime);
|
18 |
|
19 | EpsonSendCmd(0x40); // SystemSet
|
20 |
|
21 | uiDelay = 0;
|
22 | uiStartTime = TimerGet1MSecTick();
|
23 | while (uiDelay < 40) // wait 200 msec
|
24 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
25 |
|
26 | EpsonSendData1(0x30);
|
27 | EpsonSendData1(0x05); // char width in px -1 (here 6)
|
28 | EpsonSendData1(0x07); // char height -1 (here 8)
|
29 | EpsonSendData1(0x34); // number of chars per row
|
30 | EpsonSendData1(0x87); // width
|
31 | EpsonSendData1(0xEF); // height 240 lines
|
32 | EpsonSendData1(0x35); // horizontal adress range register
|
33 | EpsonSendData1(0x00);
|
34 |
|
35 | ucDelay = 0;
|
36 | ucStartTime = TimerGet1SecTick();
|
37 | while (ucDelay < 3) // wait 3 sec
|
38 | ucDelay = TimerGet1SecDiff(ucStartTime);
|
39 |
|
40 | EpsonSendCmd(0x40); // SystemSet
|
41 |
|
42 | uiDelay = 0;
|
43 | uiStartTime = TimerGet1MSecTick();
|
44 | while (uiDelay < 40) // wait 200 msec
|
45 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
46 |
|
47 | EpsonSendData1(0x30);
|
48 | EpsonSendData1(0x05); // char width in px -1 (here 6)
|
49 | EpsonSendData1(0x07); // char height -1 (here 8)
|
50 | EpsonSendData1(0x34); // number of chars per row
|
51 | EpsonSendData1(0x87); // width
|
52 | EpsonSendData1(0xEF); // height 240 lines
|
53 | EpsonSendData1(0x35); // horizontal adress range register
|
54 | EpsonSendData1(0x00);
|
55 |
|
56 | uiDelay = 0;
|
57 | uiStartTime = TimerGet1MSecTick();
|
58 | while (uiDelay < 0xFF) // wait 200 msec
|
59 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
60 |
|
61 | EpsonSendCmd(0x44); // SCROLL
|
62 | EpsonSendData2((unsigned int)(DISP1HOME)); // layer 1 home adress
|
63 | EpsonSendData1(0xFE); // 240 Lines
|
64 | EpsonSendData2((unsigned int)(DISP2HOME)); // layer 2 home adress
|
65 | EpsonSendData1(0xFE); // 240 Lines
|
66 | EpsonSendData2((unsigned int)(DISP3HOME)); // layer 3 home adress
|
67 | EpsonSendData2((unsigned int)0x0000); // Dont care
|
68 |
|
69 | EpsonSendCmd(0x58); // DISPON/OFF
|
70 | EpsonSendData1(0x14); // no flash no cursor
|
71 |
|
72 | EpsonSendCmd(0x4C); // Cursor direction right
|
73 |
|
74 | EpsonSendCmd(0x5B); // OVLAY
|
75 | EpsonSendData1(0x01); // ORMODE
|
76 |
|
77 | EpsonSendCmd(0x5A); // HDOTSCR
|
78 | EpsonSendData1(0x00);
|
79 |
|
80 | LcdClearLayer(1);
|
81 |
|
82 | uiDelay = 0;
|
83 | uiStartTime = TimerGet1MSecTick();
|
84 | while (uiDelay < 200) // wait 20 msec
|
85 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
86 |
|
87 | LcdClearLayer(2);
|
88 |
|
89 | uiDelay = 0;
|
90 | uiStartTime = TimerGet1MSecTick();
|
91 | while (uiDelay < 200) // wait 20 msec
|
92 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
93 |
|
94 | LcdClearLayer(3);
|
95 |
|
96 | uiDelay = 0;
|
97 | uiStartTime = TimerGet1MSecTick();
|
98 | while (uiDelay < 200) // wait 20 msec
|
99 | uiDelay = TimerGet1MSecDiff(uiStartTime);
|
100 |
|
101 | EpsonSendCmd(0x59); // DISPON/OFF
|
102 | EpsonSendData1(0x14); // no flash no cursor
|
103 | return;
|
104 | }
|
105 |
|
106 | void slope(unsigned char cnt)
|
107 | {
|
108 | unsigned char i;
|
109 | for (i=0; i < cnt; i++)
|
110 | asm volatile("nop");
|
111 | }
|
112 |
|
113 | void EpsonSendCmd(unsigned char cmd)
|
114 | {
|
115 | EPSONCMD;
|
116 | WRHIGH;
|
117 | CSHIGH;
|
118 | RDHIGH;
|
119 | DATAPORT = cmd;
|
120 | slope(20);
|
121 | CSLOW;
|
122 | slope(20);
|
123 | WRLOW;
|
124 | slope(20);
|
125 | WRHIGH;
|
126 | slope(20);
|
127 | CSHIGH;
|
128 | }
|
129 |
|
130 |
|
131 | void EpsonSendData1(unsigned char cmd)
|
132 | {
|
133 | EPSONDATA;
|
134 | WRHIGH;
|
135 | CSHIGH;
|
136 | RDHIGH;
|
137 | DATAPORT = cmd;
|
138 | slope(20);
|
139 | CSLOW;
|
140 | slope(20);
|
141 | WRLOW;
|
142 | slope(20);
|
143 | WRHIGH;
|
144 | slope(20);
|
145 | CSHIGH;
|
146 | EPSONCMD;
|
147 | }
|