📄 lcd.lst
字号:
C51 COMPILER V7.02b LCD 08/02/2005 17:09:33 PAGE 1
C51 COMPILER V7.02b, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN lcd.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*----------------------------------------------------------------------------------------*/
2 //240*128液晶显示驱动程序
3 //控制器件为:AT89S52
4 //T6963C接口:直接访问形式
5 //程序设计:卢印举
6 /*----------------------------------------------------------------------------------------*/
7 #include <reg51.h>
8 #include <math.h>
9 #include <hzk.c>
10
11 //信号管脚定义(全局变量)(注意:因为液晶数据口接P0,直接访问方式)
12 unsigned char xdata Lcd_Cmd_Reg _at_ 0xfdff; // C/D-P2.0 CE-P2.1 p2.0=1 p2.1=0
13 unsigned char xdata Lcd_Data_Reg _at_ 0xfcff; // C/D-P2.0 CE-P2.1 p2.0=0 p2.1=0
14
15 //以8*8字符计算,显示屏横向、纵向可以显示的点阵坐标;左、上、右、下以及当前的位置坐标
16 #define LCD_LEFT 0
17 #define LCD_TOP 0
18 #define LCD_RIGHT 239
19 #define LCD_BOTTOM 127
20 unsigned char data Lcd_CurrentX,Lcd_CurrentY,Lcd_Mask;
21
22 unsigned char data LeftMask[]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
23 unsigned char data RightMask[]={0xff,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
24
25 /*----------------------------------------------------------------------------------------*/
26 //延时子程序
27 /*----------------------------------------------------------------------------------------*/
28 void Lcddelay(unsigned int t)
29 { unsigned int i,j;
30 1 for(i=0;i<t;i++)
31 1 for(j=0;j<10;j++)
32 1 ;
33 1 }
34
35 void lcdwc(unsigned char cmdcode)
36 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ; //当Lcd_Cmd_Reg低两位不同时为1
37 1 Lcd_Cmd_Reg = cmdcode;
38 1 }
39
40 void lcdwc2(unsigned char cmdcode,unsigned char cmddata)
41 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
42 1 Lcd_Data_Reg = cmddata;
43 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
44 1 Lcd_Cmd_Reg = cmdcode;
45 1 }
46
47 void lcdwc3(unsigned char cmdcode,unsigned char cmddata,unsigned char cmddata2)
48 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
49 1 Lcd_Data_Reg = cmddata;
50 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
51 1 Lcd_Data_Reg = cmddata2;
52 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
53 1 Lcd_Cmd_Reg = cmdcode;
54 1 }
55
C51 COMPILER V7.02b LCD 08/02/2005 17:09:33 PAGE 2
56 void lcdwd(unsigned char dispdata) //写数据
57 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
58 1 Lcd_Data_Reg = dispdata;
59 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
60 1 Lcd_Cmd_Reg = 0xc0;
61 1 }
62
63 unsigned char lcdrdata(void) //读数据
64 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
65 1 Lcd_Cmd_Reg = 0xc5;
66 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
67 1 return Lcd_Data_Reg;
68 1 }
69
70 void lcdpos(void) //内部写数指针定位
71 { unsigned int CurrentAddress;
72 1 CurrentAddress = Lcd_CurrentY * 30 ;
73 1 CurrentAddress += Lcd_CurrentX/8;
74 1 lcdwc3(0x24,CurrentAddress & 0xff,CurrentAddress/256);
75 1 }
76
77 unsigned char lcdrd(void) //读数据
78 { lcdpos();
79 1 return lcdrdata();
80 1 }
81
82 void lcdcursornextbyte(void) //当前坐标移动到下一个点
83 { Lcd_CurrentX+=8;
84 1 if(Lcd_CurrentX > LCD_RIGHT)
85 1 { Lcd_CurrentX = LCD_LEFT;
86 2 Lcd_CurrentY++;
87 2 if(Lcd_CurrentY > LCD_BOTTOM) Lcd_CurrentY = LCD_TOP;
88 2 }
89 1 }
90
91 void displaybyte(unsigned char dispdata)
92 { lcdpos();
93 1 if(Lcd_Mask == 0xff) lcdwd(dispdata);
94 1 else
95 1 { unsigned char d=lcdrd();
96 2 d&=(~Lcd_Mask);
97 2 d|=(dispdata & Lcd_Mask);
98 2 lcdwd(d);
99 2 }
100 1 lcdcursornextbyte();
101 1 }
102
103 void Fill_Scr(unsigned char FillData) //LCD整屏显示
104 { Lcd_Mask=0xff;
105 1 for(Lcd_CurrentX = LCD_LEFT,Lcd_CurrentY = LCD_TOP;1;)
106 1 { displaybyte(FillData);
107 2 if((Lcd_CurrentX == LCD_LEFT) && (Lcd_CurrentY == LCD_TOP)) break;
108 2 }
109 1 }
110
111 void lcdreset() //初始化LCD屏
112 { lcdwc(0x80);
113 1 lcdwc(0x98);
114 1 lcdwc3(0x42,0,0);
115 1 lcdwc3(0x43,30,0);
116 1 }
117
C51 COMPILER V7.02b LCD 08/02/2005 17:09:33 PAGE 3
118 void displaychinesechardot(unsigned int Index);
119 void displayenglishchardot(unsigned int Index);
120 void putsizeimage(unsigned char XSIZE,unsigned char YSIZE,unsigned char code *s);
121
122 void putchar(unsigned int uChar) //信息显示
123 { unsigned int i;
124 1 if(uChar<128)
125 1 for(i=0;i != ENGLISHCHARNUMBER;i++)
126 1 { if(uChar ==EnglishCode[i])
127 2 { displayenglishchardot(i);
128 3 break;
129 3 }
130 2 }
131 1 else
132 1 for(i=0;i != CHINESECHARNUMBER;i++)
133 1 { if(uChar ==ChineseCode[i])
134 2 { displaychinesechardot(i);
135 3 break;
136 3 }
137 2 }
138 1 }
139
140 void put_str(unsigned char code *s) //显示汉字或英文字符
141 { unsigned int i;
142 1 for (;*s != 0;s++)
143 1 { i=*s;
144 2 if(*s > 127)
145 2 { s++;
146 3 i=i*256+*s;
147 3 }
148 2 if(i == '\n')
149 2 { Lcd_CurrentX = LCD_LEFT;
150 3 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1)
151 3 Lcd_CurrentY=LCD_TOP;
152 3 else
153 3 Lcd_CurrentY+=CHINESECHARSIZE;
154 3 }
155 2 putchar(i);
156 2 }
157 1 }
158
159 void put_str_xy(unsigned char x,unsigned char y,unsigned char code *s)//显示汉字或英文字符
160 { Lcd_CurrentX=x;
161 1 Lcd_CurrentY=y;
162 1 put_str(s);
163 1 }
164
165 void displaychinesechardot(unsigned int Index)
166 { unsigned char code *s;
167 1 s=ChineseCharDot+Index*CHINESECHARDOTSIZE;
168 1 if(Lcd_CurrentX > LCD_RIGHT-CHINESECHARSIZE+1)
169 1 { Lcd_CurrentX = LCD_LEFT;
170 2 Lcd_CurrentY+=CHINESECHARSIZE;
171 2 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1) Lcd_CurrentY=LCD_TOP;
172 2 }
173 1 putsizeimage(CHINESECHARSIZE,CHINESECHARSIZE,s);
174 1 }
175
176 void displayenglishchardot(unsigned int Index)
177 { unsigned char code *s;
178 1 s=EnglishCharDot+Index*ENGLISHCHARDOTSIZE;
179 1 if(Lcd_CurrentX > LCD_RIGHT-ENGLISHCHARSIZE+1)
C51 COMPILER V7.02b LCD 08/02/2005 17:09:33 PAGE 4
180 1 { Lcd_CurrentX = LCD_LEFT;
181 2 Lcd_CurrentY+=CHINESECHARSIZE;
182 2 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1)
183 2 Lcd_CurrentY=LCD_TOP;
184 2 }
185 1 putsizeimage(ENGLISHCHARSIZE,CHINESECHARSIZE,s);
186 1 }
187
188 void point(unsigned char bitdata)
189 { if(bitdata==0)
190 1 bitdata=0xf0+(0x7-(Lcd_CurrentX & 0x7));
191 1 else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -