lcd_ctrl.lst
来自「单片机控制lcd屏幕的程序」· LST 代码 · 共 1,198 行 · 第 1/4 页
LST
1,198 行
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD_CTRL
OBJECT MODULE PLACED IN lcd_ctrl.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd_ctrl.c OMF2 BROWSE DEBUG CODE
line level source
1 #include <at89x52.h>
2 #include <absacc.h>
3 #include <intrins.h>
4 #include <math.h>
5 #include "lcd_ctrl.h"
6 #include "mcu_main.h"
7 //xdata unsigned char WCMD _at_ (CMDADDR);//
8 //xdata unsigned char WDAT _at_ (DATADDR);
9
10 xdata unsigned char Op_Port0 _at_ (LcdPort0);//
11 xdata unsigned char Op_Port1 _at_ (LcdPort1);//
12 xdata unsigned char Op_Port2 _at_ (LcdPort2);//
13 xdata unsigned char Op_Port3 _at_ (LcdPort3);//
14
15 //////////////////////////////////////////////////////////////////////////
16 void SetParameter(unsigned char CtrReg)
17 {
18 1 unsigned char ch;
19 1 Op_Port1 =CtrReg | 0x44;
20 1 _nop_();
21 1 ch=Op_Port1;
22 1 }
23
24 ///////////////////////////////////////////////////////
25 //画点的函数----坐标和颜色
26 //Row参数是行(0--234),x参数是列(0--319,479)
27 void DrawDot(unsigned int X_coor,unsigned int Y_coor,unsigned char color)
28 {
29 1 Op_Port2 =Y_coor>>8;
30 1 Op_Port2 =Y_coor;
31 1 Op_Port1 =X_coor>>8;
32 1 Op_Port1 =X_coor;
33 1 Op_Port0 =color;
34 1 }
35
36 /////////////////////////////////////////////////////////////////////////
37 ////////////////////////clear LCD ///////////////////////////////////////
38 ////////////////////////dual scan////////////////////////////////////////
39
40 void ClearLcd(unsigned char color)
41 {
42 1 unsigned int i;
43 1 unsigned char j;
44 1 IE &= 0x67; //禁止中断
45 1 // Color_CSJ=0;
46 1 for(j=0;j<LcdHeight;j++)
47 1 {
48 2 Op_Port2 = 0x00;
49 2 Op_Port2 = j;
50 2 Op_Port1 =0x00;
51 2 Op_Port1 =0x00;
52 2
53 2 for(i=0;i<LcdWidth;i++)
54 2 {
55 3 // while (LCD_BUSY);
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 2
56 3 Op_Port0 = color;
57 3 _nop_();
58 3 }
59 2 Op_Port2 =0x01;
60 2 Op_Port2 = j;
61 2 Op_Port1 =0x00;
62 2 Op_Port1 =0x00;
63 2 for(i=0;i<LcdWidth;i++)
64 2 {
65 3 // while (LCD_BUSY);
66 3 Op_Port0 = color;
67 3 _nop_();
68 3 }
69 2 }
70 1 // Color_CSJ=1;
71 1 IE |= 0x98; //打开中断
72 1
73 1 }
74
75 ////////////////////////////////////////////////////////////////////////
76 /*画线。任意方向的斜线,直线数学方程 aX+bY=1 */
77 //////////////////////////////////////////////////////
78 //画线的函数 入口参数---线的起点和终点----color
79 void DrawLine(unsigned int xsta,unsigned int ysta,unsigned int xend,
80 unsigned int yend, unsigned char color)
81 {
82 1 int Xerr=0;
83 1 int Yerr=0;
84 1 int DeltaX;
85 1 int DeltaY;
86 1 int Distance;
87 1 int IncY;
88 1 int IncX;
89 1 unsigned int X; //列号,列间距
90 1 unsigned int Y; //两行之间的间距
91 1 unsigned int i;
92 1 DeltaX=xend-xsta; /*计算坐标增量 */
93 1 DeltaY=yend-ysta;//行间距
94 1 X=xsta; //把地址变化方式设为列方向增加
95 1 Y=ysta;
96 1 if(DeltaX > 0) //
97 1 {
98 2 IncX = 1; /*设置单步方向 */
99 2 }
100 1 else if (DeltaX == 0)
101 1 {
102 2 IncX = 0; /*垂直线 */
103 2 }
104 1 else
105 1 {
106 2 IncX=-1;
107 2 DeltaX=-DeltaX;
108 2 }
109 1 if(DeltaY > 0)
110 1 {
111 2 IncY = 1; /*设置单步方向 */
112 2 }
113 1 else if (DeltaY == 0)
114 1 {
115 2 IncY = 0; /*水平线 */
116 2 }
117 1 else
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 3
118 1 {
119 2 IncY=-1;
120 2 DeltaY=-DeltaY;
121 2 }
122 1 if(DeltaX > DeltaY)
123 1 {
124 2 Distance = DeltaX;
125 2 }
126 1 else
127 1 {
128 2 Distance = DeltaY;
129 2 }
130 1 for (i=0;i<Distance + 1;i++)
131 1 { /*画线输出 */
132 2 DrawDot(X,Y,color);
133 2 Xerr += DeltaX;
134 2 Yerr += DeltaY;
135 2 if(Xerr > Distance)
136 2 {
137 3 Xerr -= Distance;
138 3 X += IncX; //
139 3 }
140 2 if(Yerr > Distance)
141 2 {
142 3 Yerr -= Distance;
143 3 Y += IncY; //
144 3 }
145 2 }
146 1 }
147
148
149
150
151 //////////////////////////////////////////////////////////////////////////
152 //////////////////////////////////////////////////////////////////////////
153 //在一个320X240的平面上画圆
154
155 void circle(int x,y,r,char color)
156 {
157 1 /*
158 1 float xdata angle;
159 1 int xdata CoodX,CoodY;
160 1 */
161 1 float angle;
162 1 int CoodX,CoodY;
163 1 for(angle=0;angle<6.28;angle+=0.01)
164 1 {
165 2 //drawPixel(x+r*cos(angle),y+r*sin(angle));
166 2
167 2 CoodY=y+r*cos(angle);//x 是列坐标,Y是行坐标
168 2 CoodX=x+r*sin(angle);
169 2 DrawDot(CoodY,CoodX,color);
170 2 // DrawInitail(CoodY,CoodX);
171 2 // WriteData(color);
172 2 }
173 1 }
174 /////////////////////////////////////////////////////////////////////
175 //用对称的方式画圆,速度比较快
176 /*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 */
177 void circle1(unsigned int Ox,Oy, unsigned char Rx,color)
178
179 {
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 4
180 1
181 1 // unsigned int xdata xx,rr,xt,yt,rs,row,col;
182 1 unsigned int xx,rr,xt,yt,rs,row,col;
183 1
184 1 yt=Rx;
185 1
186 1 rr=Rx*Rx+1; //补偿 1 修正方形
187 1
188 1 rs=(yt+(yt>>1))>>1; //(*0.75)分开1/8圆弧来画
189 1 //SetReg(0x00,0x0c);
190 1 for (xt=0;xt<=rs;xt++)
191 1
192 1 {
193 2
194 2 xx=xt*xt;
195 2
196 2 while ((yt*yt)>(rr-xx)) yt--;
197 2
198 2 row=Ox+xt; //第一象限
199 2
200 2 col=Oy-yt;
201 2
202 2 //W_DOT(row,col);
203 2
204 2 DrawDot(row,col,color);
205 2 row=Ox-xt; //第二象限
206 2
207 2 //W_DOT(row,col);
208 2
209 2 DrawDot(row,col,color);
210 2 col=Oy+yt; //第三象限
211 2
212 2 //W_DOT(row,col);
213 2
214 2 DrawDot(row,col,color);
215 2 row=Ox+xt; //第四象限
216 2
217 2 //W_DOT(row,col);
218 2 DrawDot(row,col,color);
219 2
220 2 /***************45度镜象画另一半***************/
221 2
222 2 row=Ox+yt; //第一象限
223 2
224 2 col=Oy-xt;
225 2
226 2 //W_DOT(row,col);
227 2
228 2 DrawDot(row,col,color);
229 2 row=Ox-yt; //第二象限
230 2
231 2 //W_DOT(row,col);
232 2
233 2 DrawDot(row,col,color);
234 2 col=Oy+xt; //第三象限
235 2
236 2 //W_DOT(row,col);
237 2
238 2 DrawDot(row,col,color);
239 2 row=Ox+yt; //第四象限
240 2
241 2 //W_DOT(row,col);
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 5
242 2
243 2 DrawDot(row,col,color);
244 2 }
245 1
246 1 }
247
248
249
250
251 /////////////////////////////////////////////////////
252 /////disp_char/////////////////////////////////////
253 void disp_char(unsigned int Ox,Oy,unsigned char CharX,CharY, const unsigned char CharData[] ,unsigned char
- color)
254 {
255 1 unsigned char CharByte;
256 1 unsigned int Xindex,Yindex;
257 1 unsigned char i,temp_char;
258 1 for (Yindex=0;Yindex<CharY;Yindex++)
259 1 {
260 2 for(Xindex=0;Xindex<CharX;Xindex++)
261 2 {
262 3 CharByte = CharData[Yindex*Xindex + Xindex]; //
263 3 temp_char = 0x01;
264 3 for(i=0;i++;i<8)
265 3 {
266 4 if(CharByte&temp_char)
267 4 DrawDot(Ox,Oy,color);
268 4 temp_char *=2;
269 4 Ox++;
270 4 }
271 3 }
272 2 Ox -= CharX*8; //?
273 2 Oy++;
274 2 }
275 1 }
276
277
C51 COMPILER V8.02 LCD_CTRL 06/10/2008 00:34:13 PAGE 6
ASSEMBLY LISTING OF GENERATED OBJECT CODE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?