📄 lcd240128.lst
字号:
C51 COMPILER V8.02 LCD240128 09/02/2008 07:25:50 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD240128
OBJECT MODULE PLACED IN lcd240128.OBJ
COMPILER INVOKED BY: D:\Keil\C51\Bin\c51.exe lcd240128.c DB OE SMALL ROM(LARGE)
line level source
1 /***********************************/
2 /* LCD(OCM240128-1)显示程序 */
3 /* LCD 控制芯片 T6963C 带32KRAM */
4 /* MCU 型号: AT89S52 */
5 /* 时钟频率: 11.0592 MHz */
6 /* 接口方式: 直接接口(总线方式) */
7 /* 汉字显示: 图形方式 */
8 /* 开发环境: MEDWIN */
9 /* 开发日期: 08.9.1 调试成功 */
10 /* 程序编写: 嚎歌 */
11 /***********************************/
12 /**************引脚定义*************/
13 //P0口作数据线,
14 //LCD_E 接地
15 //LCD_CD接P2.0
16 //LCD_WR P2.1
17 //LCD_RD P2.2
18 //LCD_FS
19 //LCD_RESET 高电平
20 /*************各种定义**************/
21 #include <reg51.h>
22 #include <math.h>
23 #include <intrins.h>
24 /*****************变量定义*****************/
25 #define dates P0
26
27 unsigned char code fot[];
28 unsigned char code asc16[];
29 unsigned char code gstb[];
30
31 sbit cd=P2^0;
32 sbit wr=P2^1;
33 sbit rd=P2^2;
34 sbit fs=P2^3;
35 /*****************延时*****************/
36 void delay_ms(unsigned int count)
37 {
38 1 unsigned int i, j;
39 1 for(i = 0; i < count; i++)
40 1 for(j = 0; j < 0xff; j++);
41 1 }
42 /* 忙标志 */
43 #pragma disable
44 unsigned char busy(void) {
45 1 unsigned char dat;
46 1 cd=1;rd=1;wr=1;
47 1 dates=0xff;
48 1 rd=0;
49 1 dat=dates;
50 1 rd=1;
51 1 return(dat);
52 1 }
53 /* 数据,指令读写判别 */
54 #pragma disable
55 void p1(void) {
C51 COMPILER V8.02 LCD240128 09/02/2008 07:25:50 PAGE 2
56 1 while ((busy()&3)!=3) {}
57 1 }
58 /* 数据自动读判别 */
59 #pragma disable
60 void p2(void) {
61 1 while ((busy()&4)!=4) {}
62 1 }
63 /* 数据自动写判别 */
64 #pragma disable
65 void p3(void) {
66 1 while ((busy()&8)!=8) {}
67 1 }
68 /* 控制指令 */
69 #pragma disable
70 void ctrl(unsigned char dat) {
71 1 p1();
72 1 cd=1;
73 1 wr=0;
74 1 dates=dat;
75 1 wr=1;
76 1 }
77 /* 写数据 */
78 #pragma disable
79 void write(unsigned char dat) {
80 1 p1();
81 1 cd=0;
82 1 wr=0;
83 1 dates=dat;
84 1 wr=1;
85 1 cd=1;
86 1 }
87 /* 自动写 */
88 #pragma disable
89 void autowrite(unsigned char dat) {
90 1 p3();
91 1 cd=0;
92 1 wr=0;
93 1 dates=dat;
94 1 wr=1;
95 1 cd=1;
96 1 }
97 /* 读数据 */
98 #pragma disable
99 unsigned char read(void) {
100 1 unsigned char dat;
101 1 p1();
102 1 cd=0;
103 1 dates=0xff;
104 1 rd=0;
105 1 dat=dates;
106 1 rd=1;
107 1 cd=1;
108 1 return(dat);
109 1 }
110 /* 自动读数据 */
111 #pragma disable
112 unsigned char autoread(void) {
113 1 unsigned char dat;
114 1 p2();
115 1 cd=0;
116 1 dates=0xff;
117 1 rd=0;
C51 COMPILER V8.02 LCD240128 09/02/2008 07:25:50 PAGE 3
118 1 dat=dates;
119 1 rd=1;
120 1 cd=1;
121 1 return(dat);
122 1 }
123
124
125 /**************显示图形和文本**************/
126 void disp(unsigned char dat)
127 {
128 1 write(dat);
129 1 ctrl(0xc0); // 数据写,地址加一
130 1 }
131
132 /**设定图形x、y值,显示RAM中的地址指针*****/
133 void ag(unsigned char x, unsigned char y) //x为横坐标,y为纵坐标
134 {
135 1 unsigned int xy;
136 1 xy = y;
137 1 xy = xy * 30 + x + 2 * 256; // 图形区首址为0x0200
138 1 write(xy % 256); // 先写低位地址
139 1 write(xy / 256); // 再写高位地址
140 1 ctrl(0x24); // 地址指针
141 1 }
142
143 /***********设定文本x、y值*****************/
144 void at(unsigned char x, unsigned char y)
145 {
146 1 unsigned int xy;
147 1 xy = y;
148 1 xy = xy * 30 + x; // 文本区首址为0x0000
149 1 write(xy % 256); // 先写低位地址
150 1 write(xy / 256); // 再写高位地址
151 1 ctrl(0x24); // 地址指针
152 1 }
153
154 /***************点亮一点*******************/
155 void setb(unsigned char dat)
156 {
157 1 ctrl(0xf8 | dat);
158 1 }
159
160 /***************清除一点*******************/
161 void clrb(unsigned char dat)
162 {
163 1 ctrl(0xf0 | dat);
164 1 }
165
166 /**************x,y处显示光标***************/
167 void ab(unsigned char x, unsigned char y)
168 {
169 1 ctrl(0x97); //光标开
170 1 write(x);
171 1 write(y);
172 1 ctrl(0x21);
173 1 }
174
175 /*******************取消光标***************/
176 void noab(void)
177 {
178 1 ctrl(0x9c);
179 1 }
C51 COMPILER V8.02 LCD240128 09/02/2008 07:25:50 PAGE 4
180
181 /*******************lcd初始化**************/
182 void lcd_init(void)
183 {
184 1 unsigned int i;
185 1 fs = 0;
186 1 write(0x00); write(0x00); ctrl(0x40); // 文本首址
187 1 write(0x1e); write(0x00); ctrl(0x41); // 文本区域,每行30字节
188 1 write(0x00); write(0x02); ctrl(0x42); // 图形首址,0200H,
189 1 write(0x1e); write(0x00); ctrl(0x43); // 图形区域,每行30字节
190 1 ctrl(0x80); // 显示方式,CGROM有效,00-7FH为CGROM地址,80H-FFH为CGRAM
191 1 ctrl(0x9c); // 显示开关,图形启用,文本启用,光标禁止
192 1 ctrl(0xa0); // 光标形状
193 1 at(0,0);
194 1 ctrl(0xb0); //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -