📄 lcd12864.lst
字号:
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD12864
OBJECT MODULE PLACED IN LCD12864.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD12864.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /***************************************************************************
2
3 12864液晶模块(ST7920控制器) Keil C51 并行口驱动程序
4
5 s_yqzhan@stu.edu.cn
6 OFourME@163.com 2007-9-29
7
8 /**************************************************************************/
9
10 #include"LCD12864.h"
11 // #define NOP
12
13 /* 通过define NOP 决定是否在程序中插入nop指令
14 ** 因为LCD可能对电平保持时间有一定的要求 */
15
16
17 /*////////////////////////////////////////////////////////////////////////*/
18
19 #ifdef NOP
#include<intrins.h>
#endif
22
23 /*////////////////////////////////////////////////////////////////////////*/
24 /* 初始化12864液晶模块 */
25
26 void init_LCD(void)
27 {
28 1 RST = 0;
29 1 delay(10);
30 1 RST = 1;
31 1 #ifdef NOP
_nop_();
#endif
34 1 PSB = 1;/*H:8位或4位并口方式,L:串口方式*/
35 1 send_i(ext8);
36 1 send_i(bas8);
37 1 send_i(clr);
38 1 send_i(cursor_1);
39 1 send_i(texton);
40 1 }
41
42 /*////////////////////////////////////////////////////////////////////////*/
43 /* 等待,直到12864液晶模块处于就绪状态 */
44
45 void chk_busy(void)
46 {
47 1 BF = 1; /*DI=L.RW=H,读出忙标志(BF)及地址记数器(AC)的状态*/
48 1 DI = 0; /*BF标志提供内部工作情况.BF=1表示模块在进行内部操作,*/
49 1 RW = 1; /*此时模块不接受外部指令和数据.BF=0时,模块为准备状态,*/
50 1 E = 1; /*随时可接受外部指令和数据.*/
51 1 while(BF);
52 1 E = 0;
53 1 }
54
55 /*////////////////////////////////////////////////////////////////////////*/
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 2
56 /* 向12864液晶模块传输指令 */
57
58 void send_i(cmd12864 instrution)
59 {
60 1 chk_busy();
61 1 DI = 0;
62 1 RW = 0;
63 1 DB = instrution;
64 1 E = 1;
65 1 #ifdef NOP
_nop_();
_nop_();
#endif
69 1 E = 0;
70 1 }
71
72 /*////////////////////////////////////////////////////////////////////////*/
73 /* 向12864液晶模块传输数据 */
74
75 void send_d(int8u dt)
76 {
77 1 chk_busy();
78 1 DI = 1; /* 数据(1)/指令(0) */
79 1 RW = 0; /* 读(1)/写(0) */
80 1 DB = dt;/* P0口,作为数据总线 */
81 1 E = 1;/* 使能-写(H->L)/读(H) */
82 1 #ifdef NOP
_nop_();
_nop_();
#endif
86 1 E = 0;
87 1 }
88
89 /*////////////////////////////////////////////////////////////////////////*/
90 /* 从12864液晶模块读取数据 */
91
92 int8u read_d()
93 {
94 1 int8u dt;
95 1
96 1 chk_busy();
97 1 DI = 1;
98 1 RW = 1;
99 1 E = 1;
100 1 #ifdef NOP
_nop_();
#endif
103 1 dt = DB;
104 1 E = 0;
105 1 return dt;
106 1 }
107 /*////////////////////////////////////////////////////////////////////////*/
108 /* 从12864液晶模块读取指令、状态 */
109
110 int8u read_i()
111 {
112 1 int8u dt;
113 1
114 1 chk_busy();
115 1 DI = 0;
116 1 RW = 1;
117 1 E = 1;
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 3
118 1 #ifdef NOP
_nop_();
#endif
121 1 dt = DB;
122 1 E = 0;
123 1 return dt;
124 1 }
125
126 /*////////////////////////////////////////////////////////////////////////*/
127 /* 设置文本输出位置;x取值范围:0~7;y取值范围:0~3 */
128
129 void gotoxy(int8u x, int8u y)
130 {
131 1 switch(y)
132 1 {
133 2 case 0: send_i(0x80+x);break;
134 2 case 1: send_i(0x90+x);break;
135 2 case 2: send_i(0x88+x);break;
136 2 case 3: send_i(0x98+x);break;
137 2 }
138 1 }
139
140 /*////////////////////////////////////////////////////////////////////////*/
141 /* 设置图形模式输出位置;x取值范围(byte):0~7,单位为16位/2个字节,共128位;
142 y取值范围(bit):0~63
143 */
144
145 void setxy(int8u x, int8u y)
146 {
147 1 send_i(ext8);
148 1 if( y & 0xe0 ) /* y>=32 */
149 1 {
150 2 send_i(gdbas+y-32);
151 2 send_i(page1+x);
152 2 }
153 1 else
154 1 {
155 2 send_i(gdbas+y);
156 2 send_i(page0+x);
157 2 }
158 1 send_i(bas8);
159 1 }
160
161 /*////////////////////////////////////////////////////////////////////////*/
162 /* 屏幕闪烁 */
163
164 void flash()
165 {
166 1 send_i(textoff); /* 关闭显示 */
167 1 delay(250);
168 1 send_i(texton); /* 开显示,关光标,不闪烁 */
169 1 delay(250);
170 1 send_i(textoff);
171 1 delay(250);
172 1 send_i(texton);
173 1 delay(250);
174 1 send_i(textoff);
175 1 delay(250);
176 1 send_i(texton);
177 1 }
178
179 /*////////////////////////////////////////////////////////////////////////*/
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 4
180 /* 清屏 */
181
182 void clrddram()
183 {
184 1 send_i(clr);
185 1 send_i(ext8);
186 1 send_i(bas8);
187 1 }
188
189 /*////////////////////////////////////////////////////////////////////////*/
190 /* 连续向LCD发送string指向的num个数据 */
191
192 void LCD_puts(TAB* string, int8u num)
193 {
194 1 while(num--)
195 1 {
196 2 send_d(*string++);//向12864液晶模块传输数据
197 2 }
198 1 }
199
200 /*////////////////////////////////////////////////////////////////////////*/
201 /* 全屏显示图形子程序 */
202
203 void pho_disp(BMP12864* tab)
204 {
205 1 int8u i, j, k, lcd_x, lcd_y;
206 1
207 1 lcd_x = 0x80;
208 1 for(i=0 ; i<2; i++)
209 1 {
210 2 for(j=0, lcd_y=0x80; j<32; j++, lcd_y++)
211 2 {
212 3 send_i(ext8);
213 3 send_i(lcd_y);
214 3 send_i(lcd_x);
215 3 send_i(bas8);
216 3 for(k=16; k; k--)
217 3 send_d(*(tab++));
218 3 }
219 2 lcd_x = 0x88;
220 2 }
221 1 send_i(grapon);
222 1 send_i(bas8);
223 1 }
224
225 /*////////////////////////////////////////////////////////////////////////*/
226 /* 显示点阵子程序,以lcd_data填充图形显示空间(GDRAM) */
227
228 void lat_disp(int8u lcd_data)
229 {
230 1 int8u i, j, k;
231 1 int8u lcd_x, lcd_y;
232 1
233 1 lcd_x=0x80;
234 1 i=2;
235 1 do
236 1 { j=32; lcd_y=0x80;
237 2 do
238 2 { send_i(ext8);
239 3 send_i(lcd_y);
240 3 send_i(lcd_x);
241 3 send_i(bas8);
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 5
242 3 k=16;
243 3 do
244 3 { send_d(lcd_data);
245 4 }while(k--);
246 3 lcd_y++;
247 3 }while(--j);
248 2 lcd_x = 0x88;
249 2 }while(--i);
250 1
251 1 send_i(grapon);
252 1 send_i(bas8);
253 1 }
254
255 /*////////////////////////////////////////////////////////////////////////*/
256 /* 造字功能,最多自定义4的字,word的范围为0~3 */
257
258 void setcgram(int8u word, BMP1616* map)
259 {
260 1 int i;
261 1
262 1 send_i(cgbas+16*word);
263 1 for(i=0; i<32; i++)
264 1 send_d( *map++ );
265 1
266 1 }
267
268 /*////////////////////////////////////////////////////////////////////////*/
269
270 void clrgdram()
271 {
272 1 lat_disp(0);
273 1 }
274
275 /*//////////////////////////////////////////////////////////////////////////
276 原型:void putpixel(int8u x, int8u y, int8u mode);
277
278 功能:在屏幕的指定位置上画点
279
280 说明:(x,y)为屏幕上点的坐标,mode值含义如下:
281 mode=0:清除(x,y)处的点
282 1:在(x,y)处画点
283 2:将(x,y)处的点的状态取反
284 //////////////////////////////////////////////////////////////////////////*/
285 /* 本程序可能是错误的,因为read_d()读取的GDRAM的内容并不完全,
286 这可能是因为本人的12864液晶模块故障,或是因为其并无此功能。
287 */
288
289 void putpixel(int8u x, int8u y, int8u mode)
290 {
291 1 int8u i;
292 1 union
293 1 { int16u D;
294 1 struct
295 1 { int8u c1;
296 1 int8u c2;
297 1 }C;
298 1 }t;
299 1
300 1 int16u code an[] = {
301 1 0x7fff, 0xbfff, 0xdfff, 0xefff, 0xf7ff, 0xfbff, 0xfdff, 0xfeff,
302 1 0xff7f, 0xffbf, 0xffdf, 0xffef, 0xfff7, 0xfffb, 0xfffd, 0xfffe };
303 1 int16u code or[] = {
C51 COMPILER V8.02 LCD12864 01/07/2009 11:33:16 PAGE 6
304 1 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
305 1 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001 };
306 1 int16u code * const xo = or;
307 1
308 1 setxy(x/16,y);
309 1 read_d();
310 1 t.C.c1 = read_d();
311 1 t.C.c2 = read_d();
312 1
313 1 i = x & 0x0f;
314 1 switch(mode)
315 1 {
316 2 case 0: t.D &= an[i]; break;
317 2 case 1: t.D |= or[i]; break;
318 2 default:t.D ^= xo[i];
319 2 }
320 1 setxy(x/16,y);
321 1 send_d(t.C.c1);
322 1 send_d(t.C.c2);
323 1 }
324
325 /*////////////////////////////////////////////////////////////////////////*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 606 ----
CONSTANT SIZE = 64 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 6
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -