📄 lcd.lst
字号:
C51 COMPILER V8.02 LCD 05/16/2009 13:41:49 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN LCD.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <C8051F020.h>
2
3 #define uint unsigned int
4 #define uchar unsigned char
5 #define x1 0x80
6 #define x2 0x88
7 #define y 0x80
8 #define comm 0
9 #define dat 1
10
11 sbit cs = P0^0; //串行口使能,高电平有效(作RS时,1为数据,0为指令)
12 sbit std = P0^1; //串口数据(作R/W时,1为读,0为写)
13 sbit sclk = P0^2; //串口时钟,高电平有效
14 sbit psb = P0^3; //H=并口; L=串口;
15 sbit rst = P0^4; //复位,低电平有效
16
17 void wr_lcd (uchar dat_comm,uchar content);
18 void delay (uint us);
19 Read_Data();
20
21 uchar code tab6[]={
22 /*-- 调入了一幅图像:这是您新建的图像 --*/
23 /*-- 宽度x高度=128x64 --*/
24 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
25 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
26 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
27 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
28 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
29 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
30 0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
31 0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
37 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39 0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
42 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
43 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
44 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
45 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
46 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
47 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
48 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
49 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
50 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
51 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
52 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
53 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
54 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
55 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
C51 COMPILER V8.02 LCD 05/16/2009 13:41:49 PAGE 2
56 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
57 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
59 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
60 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
61 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
63 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
64 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
65 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
66 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
67 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
68 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
70 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
71 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
72 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
73 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
74 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
75 0x00,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x40,0x00,0x00,
76 0x00,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x60,0x00,0x00,
77 0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,
78 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
85 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
86 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
87 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
88 };
89
90 /*---------------系统初始化------------*/
91 void SysInitial()
92 {
93 1 uint i;
94 1 EA=0;
95 1 WDTCN=0xDE; //关闭看门狗
96 1 WDTCN=0xAD;
97 1 EA=1;
98 1 OSCXCN = 0x67; // 先选择外捕振荡器,频率为11.0592MHZ ,晶体振荡器方式1.6MHz<f≤3.2M
-Hz
99 1 for (i=0; i < 256; i++) ; // 再延时(>1ms),
100 1 while (!(OSCXCN & 0x80)) ; // 等待外部晶振稳定
101 1 OSCICN = 0x88; // 选择外部晶振,允许时钟丢失检测
102 1 XBR0=0x00; //使能交叉开关
103 1 XBR1=0x00;
104 1 XBR2=0x42;
105 1 P3MDOUT=0xff;
106 1 P0MDOUT=0xff;
107 1 P2MDOUT=0xff;
108 1 P74OUT=0xff; //P4-P7脚设为推挽 作为输出用
109 1 }
110
111
112 /*------------------LCD初始化-----------------*/
113 void init_lcd (void)
114 {
115 1 rst=0; //复位
116 1 delay(100);
C51 COMPILER V8.02 LCD 05/16/2009 13:41:49 PAGE 3
117 1 rst=1; //复位无效
118 1 psb=0; //H:并行 L:串行
119 1 wr_lcd (comm,0x30); //30---基本指令动作
120 1 wr_lcd (comm,0x01); //清屏,地址指针指向00H
121 1 delay (100); //清屏需较长时间
122 1 wr_lcd (comm,0x06); //光标右移,整体不移动
123 1 wr_lcd (comm,0x0c); //整体显示关,光标显示开,关反白闪烁
124 1 }
125
126
127
128 /*----------------显示图形-----------------*/
129 void img_disp (uchar code *img)
130 {
131 1 uchar i,j;
132 1 for(j=0;j<32;j++) //上半屏
133 1 {
134 2 for(i=0;i<8;i++)
135 2 {
136 3 wr_lcd (comm,0x34); //8位控制端口,选择扩充指令集
137 3 wr_lcd (comm,y+j); //选择图形区Y轴坐标
138 3 wr_lcd (comm,x1+i); //选择图形区X轴坐标
139 3 wr_lcd (comm,0x30); //选择基本指令集
140 3 wr_lcd (dat,img[j*16+i*2]); //写图形数据
141 3 wr_lcd (dat,img[j*16+i*2+1]);
142 3 }
143 2 }
144 1 for(j=32;j<64;j++) //下半屏
145 1 {
146 2 for(i=0;i<8;i++)
147 2 {
148 3 wr_lcd (comm,0x34);
149 3 wr_lcd (comm,y+j-32);
150 3 wr_lcd (comm,x2+i);
151 3 wr_lcd (comm,0x30);
152 3 wr_lcd (dat,img[j*16+i*2]);
153 3 wr_lcd (dat,img[j*16+i*2+1]);
154 3 }
155 2 }
156 1 wr_lcd (comm,0x36); //写入数据后选择图形显示
157 1 }
158
159
160
161
162 /*--------------显示点阵----------------*/
163 void lat_disp (uchar data1,uchar data2)
164 {
165 1 uchar i,j,k,x;
166 1 x=x1;
167 1 for(k=0;k<2;k++)
168 1 {
169 2 for(j=0;j<16;j++)
170 2 {
171 3 for(i=0;i<8;i++) //偶数行显示的点阵
172 3 {
173 4 wr_lcd (comm,0x34); //8位控制端口,选择扩充指令集
174 4 wr_lcd (comm,y+j*2);
175 4 wr_lcd (comm,x+i);
176 4 wr_lcd (comm,0x30); //选择基本指令集
177 4 wr_lcd (dat,data1); //写入数据
178 4 wr_lcd (dat,data1);
C51 COMPILER V8.02 LCD 05/16/2009 13:41:49 PAGE 4
179 4 }
180 3 for(i=0;i<8;i++) //奇数行显示的点阵
181 3 {
182 4 wr_lcd (comm,0x34);
183 4 wr_lcd (comm,y+j*2+1);
184 4 wr_lcd (comm,x+i);
185 4 wr_lcd (comm,0x30);
186 4 wr_lcd (dat,data2);
187 4 wr_lcd (dat,data2);
188 4 }
189 3 }
190 2 x=x2;
191 2 }
192 1 wr_lcd (comm,0x36); //写入数据后选择显示
193 1 }
194
195
196 /*------------画点-------------*/
197 void Locat_Dot(uchar x_loc, uchar y_loc)
198 {
199 1 uchar Line,Column;
200 1 uchar move;
201 1 uint ori_data;
202 1 uint dot_data;
203 1 uchar value1,value2;
204 1 uint temp1,temp2,s;
205 1 uchar x;
206 1 uint n=0x80;
207 1 y_loc = 63 - y_loc ;
208 1 Column = x_loc/16;
209 1 Line = y_loc;
210 1 delay(100);
211 1
212 1 if(y_loc<16)
213 1 {
214 2 x=0x98;
215 2 Line=31-Line;
216 2 }
217 1 if((y_loc>=16)&&(y_loc<32))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -