📄 lcd_test.lst
字号:
C51 COMPILER V8.02 LCD_TEST 08/21/2009 16:03:38 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD_TEST
OBJECT MODULE PLACED IN lcd_test.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd_test.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "C8051F020.h"
2
3
4 #define uint unsigned int
5 #define uchar unsigned char
6 #define x1 0x80
7 #define x2 0x88
8 #define y 0x80
9 #define comm 0
10 #define dat 1
11 /*
12 sbit cs = P3^0;
13 sbit std = P3^1;
14 sbit sclk = P3^2;
15 */
16
17
18 sbit cs = P0^0;
19 sbit std = P0^1;
20 sbit sclk = P0^2;
21 sbit rst=P3^5;
22
23
24 uchar code tab5[]={0x02,0x01,0x05,0x01,0x05,0x01,0x05,0x03,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
25 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x80,0x40,0x00,0x20,0x00,0x40,0x00
26 };
27
28 void delay (uint us) //延时
29 {
30 1 while(us--);
31 1 }
32
33 void delay1 (uint ms)
34 {
35 1 uint i,j;
36 1 for(i=0;i<ms;i++)
37 1 for(j=0;j<15;j++)
38 1 delay(1);
39 1 }
40
41 void wr_lcd(uchar dat_comm,uchar content)//定义读、写数据和操作方式
42 {
43 1 uchar a,i,j;
44 1 delay(600);
45 1 a=content;
46 1 cs=1;
47 1 sclk=0;
48 1 std=1;
49 1 for(i=0;i<5;i++)
50 1 {
51 2 sclk=1;
52 2 sclk=0;
53 2 }
54 1 std=0;
55 1 sclk=1;
C51 COMPILER V8.02 LCD_TEST 08/21/2009 16:03:38 PAGE 2
56 1 sclk=0;
57 1 if(dat_comm)
58 1 std=1; //data
59 1 else
60 1 std=0; //command
61 1 sclk=1;
62 1 sclk=0;
63 1 std=0;
64 1 sclk=1;
65 1 sclk=0;
66 1 for(j=0;j<2;j++)
67 1 {
68 2 for(i=0;i<4;i++)
69 2 {
70 3 a=a<<1;
71 3 std=CY;
72 3 sclk=1;
73 3 sclk=0;
74 3 }
75 2 std=0;
76 2 for(i=0;i<4;i++)
77 2 {
78 3 sclk=1;
79 3 sclk=0;
80 3 }
81 2 }
82 1 }
83
84
85 void Init_Clock(void)//配置系统时钟
86 {
87 1 int n = 0;
88 1 OSCXCN = 0x67;
89 1 for (n = 0; n < 255; n++) ;
90 1 while ( (OSCXCN & 0x80) == 0 );
91 1 OSCICN = 0x0C;
92 1
93 1 }
94
95 void Init_lcd(void)//液晶初始化
96 {
97 1 rst=1;
98 1 // psb=0;
99 1 wr_lcd(comm,0x30); //30---基本指令动作
100 1 wr_lcd(comm,0x01); //清屏,地址指针指向00H
101 1 delay (100);
102 1 wr_lcd(comm,0x06); //光标的移动方向
103 1 wr_lcd(comm,0x0b); //开显示,关游标
104 1 }
105
106
107 void Init_Port(void)//端口配置
108 {
109 1 //交叉开关配置
110 1 XBR0 = 0x00;
111 1 XBR1 = 0x00;
112 1 XBR2 = 0x40;
113 1
114 1 P0MDOUT = 0xff;
115 1
116 1 }
117
C51 COMPILER V8.02 LCD_TEST 08/21/2009 16:03:38 PAGE 3
118
119 /*-----------------------------------------------*/
120 //当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl.
121 void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
122 {
123 1 uchar i,j;
124 1 for(j=0;j<yl;j++)
125 1 {
126 2 for(i=0;i<xl;i++)
127 2 {
128 3 wr_lcd (comm,0x34);
129 3 wr_lcd (comm,y0+j);
130 3 wr_lcd (comm,x0+i);
131 3 wr_lcd (comm,0x30);
132 3 wr_lcd (dat,data1);
133 3 wr_lcd (dat,data2);
134 3 }
135 2 }
136 1 wr_lcd (comm,0x36);
137 1 }
138
139
140
141 void clrram (void)
142 {
143 1 wr_lcd (comm,0x30);
144 1 wr_lcd (comm,0x01);
145 1 delay (180);
146 1 }
147
148
149 /*--------------显示点阵----------------*/
150 void lat_disp (uchar data1,uchar data2)
151 {
152 1 uchar i,j,k,x;
153 1 x=x1;
154 1 for(k=0;k<2;k++)
155 1 {
156 2 for(j=0;j<16;j++)
157 2 {
158 3 for(i=0;i<8;i++)
159 3 {
160 4 wr_lcd (comm,0x34);
161 4 wr_lcd (comm,0x80+j*2);
162 4 wr_lcd (comm,0x80+i);
163 4 wr_lcd (comm,0x30);
164 4 wr_lcd (dat,data1);
165 4 wr_lcd (dat,data1);
166 4 }
167 3 for(i=0;i<8;i++)
168 3 {
169 4 wr_lcd (comm,0x34);
170 4 wr_lcd (comm,0x80+j*2+1);
171 4 wr_lcd (comm,x+i);
172 4 wr_lcd (comm,0x30);
173 4 wr_lcd (dat,data2);
174 4 wr_lcd (dat,data2);
175 4 }
176 3 }
177 2 x=x2;
178 2 }
179 1 wr_lcd (comm,0x36);
C51 COMPILER V8.02 LCD_TEST 08/21/2009 16:03:38 PAGE 4
180 1 }
181
182 /*-------------下半屏显示图形--------------*/
183 void img_disp1 (uchar code *img)
184 {
185 1 uchar i,j;
186 1 for(j=0;j<32;j++)
187 1 {
188 2 for(i=0;i<8;i++)
189 2 {
190 3 wr_lcd (comm,0x34);
191 3 wr_lcd (comm,y+j);
192 3 wr_lcd (comm,x2+i);
193 3 wr_lcd (comm,0x30);
194 3 wr_lcd (dat,img[j*16+i*2]);
195 3 wr_lcd (dat,img[j*16+i*2+1]);
196 3 }
197 2 }
198 1 wr_lcd (comm,0x36);
199 1 }
200
201
202
203 void main(void)
204 {
205 1 WDTCN = 0xDE; // 关闭 WDT
206 1 WDTCN = 0xAD;
207 1 Init_Clock();
208 1 Init_Port();
209 1 Init_lcd();
210 1
211 1 while(1)
212 1 {
213 2 //clrram();
214 2 //wr_lcd(comm,0x34);
215 2 //wr_lcd(comm,0x80+31);
216 2 //wr_lcd(comm,0x80+10);
217 2 wr_lcd(comm,0x30);
218 2 wr_lcd(comm,0x80);
219 2 wr_lcd(comm,0x89);
220 2 wr_lcd(dat,0x18);
221 2 wr_lcd(dat,0x18);
222 2 // wr_lcd(comm,0x36);
223 2 //con_disp(0xff,0xff,0x80,0x80,1,1);
224 2 //
225 2 //lat_disp(0xff,0xff);
226 2 //img_disp1(tab5);
227 2 delay1(1000);
228 2 }
229 1
230 1
231 1 }
232
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 613 ----
CONSTANT SIZE = 32 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 14
IDATA SIZE = ---- ----
C51 COMPILER V8.02 LCD_TEST 08/21/2009 16:03:38 PAGE 5
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 + -