📄 tlc2543.lst
字号:
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TLC2543
OBJECT MODULE PLACED IN TLC2543.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE TLC2543.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /**************************************
2 TLC2543驱动程序
3 *************************************/
4
5 #include <AT89X52.h>
6 #include <intrins.h>
7
8 #define CLOCK P1_7 /*2543时钟*/
9 #define D_IN P1_6/*2543输入*/
10 #define D_OUT P1_5 /*2543输出*/
11 #define _CS P1_4 /*2543片选*/
12
13 #define uint unsigned int
14 #define uchar unsigned char
15
16 uchar b1,b2,b3,b4;
17 /*******************************************************************************************************/
18 #define E1 P1_2
19 #define E2 P1_3
20 #define RS P3_5
21 #define R_W P3_6
22 #define E P3_7
23 uchar page,column; //define page and column;
24 bit Un_Flag; //取反标志;
25 code uchar mo[]= {0x10,0xD0,0xFF,0x50,0x90,0x04,0xF4,0x54,0x5F,0x54,0x54,0x5F,0xF4,0x04,0x00,0x00,
26 0x03,0x00,0xFF,0x00,0x00,0x84,0x85,0x45,0x35,0x0F,0x15,0x25,0x65,0xC4,0x44,0x00};
27 code uchar jiao[]= {0x00,0x40,0x20,0xF0,0x98,0x97,0x92,0x92,0xF2,0x92,0x9A,0x96,0x92,0xF0,0x00,0x00,
28 0x00,0x80,0x60,0x1F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x44,0x84,0x7F,0x00,0x00};
29 code uchar dao[]= {0x00,0x00,0x00,0x3E,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0xCA,0x4E,0x40,0x70,0x00,0x00,
30 0x02,0x02,0x02,0x02,0x06,0x3A,0x12,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x00};
31 code uchar na[]= {0x20,0x30,0x2C,0xA3,0x60,0x18,0xF8,0x08,0x08,0x88,0x7F,0x88,0x08,0x08,0xF8,0x00,
32 0x10,0x32,0x13,0x12,0x0A,0x0A,0xFF,0x04,0x02,0x01,0x00,0x00,0x47,0x82,0x7F,0x00};
33 code uchar point[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};
34 code uchar mao[]= {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00};
35 code uchar num[10][16]=
36 {
37 {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/
38 {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",1*/
39 {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/
40 {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",3*/
41 {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",4*/
42 {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/
43 {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",6*/
44 {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",7*/
45 {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/
46 {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00}};/*"9",9*/
47 void delay(uchar n)
48 {
49 1 uchar i;
50 1 for(i=0;i<n;i++)
51 1 {
52 2 _nop_();
53 2 }
54 1 }
55 void F_Wate_E1() //读E1状态
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 2
56 {
57 1 E1=1;E2=0;
58 1 P2=0xff;
59 1 R_W=1;
60 1 RS=0;
61 1 E=1;
62 1 while(P2&0x80);
63 1 E=0;
64 1 }
65 void F_Wate_E2() //读E1状态
66 {
67 1 E1=0;E2=1;
68 1 P2=0xff;
69 1 R_W=1;
70 1 RS=0;
71 1 E=1;
72 1 while(P2&0x80);
73 1 E=0;
74 1 }
75 void F_Wtcode_E1(uchar cod) //向E1写指令
76 {
77 1 F_Wate_E1();
78 1 P2=cod;
79 1 R_W=0;
80 1 RS=0;
81 1 E1=1;E2=0;
82 1 E=1;
83 1 E=0;
84 1 }
85 void F_Wtcode_E2(uchar cod) //向E2写指令
86 {
87 1 F_Wate_E2();
88 1 P2=cod;
89 1 R_W=0;
90 1 RS=0;
91 1 E1=0;E2=1;
92 1 E=1;
93 1 E=0;
94 1 }
95 void F_Wtdata_E1(uchar dat) //向E1写数据
96 {
97 1 F_Wate_E1();
98 1 if(!Un_Flag)P2=dat;
99 1 else P2=~dat;
100 1 R_W=0;
101 1 RS=1;
102 1 E1=1;E2=0;
103 1 E=1;
104 1 E=0;
105 1 }
106 void F_Wtdata_E2(uchar dat) //向E2写数据
107 {
108 1 F_Wate_E2();
109 1 if(!Un_Flag)P2=dat;
110 1 else P2=~dat;
111 1 R_W=0;
112 1 RS=1;
113 1 E1=0;E2=1;
114 1 E=1;
115 1 E=0;
116 1 }
117 void F_Clear_LCD() //清屏子程序。
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 3
118 {
119 1 uchar page,count;
120 1 for(page=0xb8;page<0xc0;page++)
121 1 {
122 2 F_Wtcode_E1(page); //设置页地址
123 2 F_Wtcode_E2(page);
124 2 F_Wtcode_E1(0x40); //设置列地址
125 2 F_Wtcode_E2(0x40);
126 2 for(count=0;count<64;count++)
127 2 {
128 3 F_Wtdata_E1(0x00);
129 3 F_Wtdata_E2(0x00);
130 3 }
131 2 }
132 1 }
133 void F_Init_LCD() //初始化
134 {
135 1 F_Wtcode_E1(0x3f);
136 1 F_Wtcode_E2(0x3f);
137 1 F_Wtcode_E1(0x60);
138 1 F_Wtcode_E2(0x60);
139 1 F_Wtcode_E1(0xc0);
140 1 F_Wtcode_E2(0xc0);
141 1 F_Clear_LCD();
142 1 }
143 void F_Write_Char(uchar *Charptr) //写一汉字子程序
144 {
145 1 uchar i,column0;
146 1 F_Wtcode_E1(page|0xb8);
147 1 F_Wtcode_E2(page|0xb8); //设置页地址
148 1 column0=column;
149 1 if(column0<64)
150 1 {
151 2 F_Wtcode_E1(column0|0x40); //设置列地址
152 2 for(i=0;i<16;i++)
153 2 {
154 3 if(column0<64){F_Wtdata_E1(Charptr[i]);column0+=1;}
155 3 else break;
156 3 }
157 2 if(column0>=64)
158 2 {
159 3 F_Wtcode_E2((column0-64)|0x40);
160 3 for(;i<16;i++){F_Wtdata_E2(Charptr[i]);column0+=1;}
161 3 }
162 2 }
163 1 else if(column0<128)
164 1 {
165 2 F_Wtcode_E2((column0-64)|0x40);
166 2 for(i=0;i<16;i++)
167 2 {
168 3 F_Wtdata_E2(Charptr[i]);
169 3 column0+=1;
170 3 if(column0==128)break;
171 3 }
172 2 }
173 1
174 1 F_Wtcode_E1(page+1|0xb8);
175 1 F_Wtcode_E2(page+1|0xb8);
176 1 if(column<64)
177 1 {
178 2 F_Wtcode_E1(column|0x40);//设置列地址
179 2 for(i=16;i<32;i++)
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 4
180 2 {
181 3 if(column<64){F_Wtdata_E1(Charptr[i]);column+=1;}
182 3 else break;
183 3 }
184 2 if(column>=64)
185 2 {
186 3 F_Wtcode_E2((column-64)|0x40);
187 3 for(;i<32;i++){F_Wtdata_E2(Charptr[i]);column+=1;}
188 3 }
189 2 }
190 1 else if(column<128)
191 1 {
192 2 F_Wtcode_E2((column-64)|0x40);
193 2 for(i=16;i<32;i++)
194 2 {
195 3 F_Wtdata_E2(Charptr[i]);
196 3 column+=1;
197 3 if(column==128)break;
198 3 }
199 2 }
200 1 }
201 void F_Write_CharW(uchar *Charptr)//写一字符子程序
202 {
203 1 uchar i,column0;
204 1 F_Wtcode_E1(page|0xb8);
205 1 F_Wtcode_E2(page|0xb8); //设置页地址
206 1 if(column<64)
207 1 F_Wtcode_E1(column|0x40); //设置列地址
208 1 else
209 1 F_Wtcode_E2((column-64)|0x40);
210 1 column0=column;
211 1 for(i=0;i<8;i++)
212 1 {
213 2 if(column0<64)
214 2 F_Wtdata_E1(Charptr[i]);
215 2 else
216 2 if(column0<128)
217 2 F_Wtdata_E2(Charptr[i]);
218 2 column0+=1;
219 2 }
220 1 F_Wtcode_E1(page+1|0xb8);
221 1 F_Wtcode_E2(page+1|0xb8);
222 1 if(column<64)F_Wtcode_E1(column|0x40);
223 1 else F_Wtcode_E2((column-64)|0x40);
224 1 for(i=8;i<16;i++)
225 1 {
226 2 if(column<64)F_Wtdata_E1(Charptr[i]);
227 2 else if(column<128)F_Wtdata_E2(Charptr[i]);
228 2 column+=1;
229 2 }
230 1 }
231 /***************************************************菜单显示程序******************************************
-****************/
232
233 /**********************************驱动程序结束,主程序开始**********************************************/
234
235 /********************************************************************************************************8
-/
236
237
238 /**************************************
239 功能:TLC2543驱动模块
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 5
240 输入参数:port通道号
241 输出参数:ad转换值
242 *************************************/
243 uint read2543(uchar port)
244 {
245 1 uint ad=0,i;
246 1 CLOCK=0;
247 1 _CS=0;
248 1 port<<=4;
249 1 for(i=0;i<12;i++)
250 1 {
251 2 if(D_OUT) ad|=0x01;
252 2 D_IN=(bit)(port&0x80);
253 2 CLOCK=1;
254 2 delay(3);
255 2 CLOCK=0;
256 2 delay(3);
257 2 port<<=1;
258 2 ad<<=1;
259 2 }
260 1 _CS=1;
261 1 ad>>=1;
262 1 return(ad);
263 1 }
264 /**************************************/
265 void deal_addata(uint ad)
266 {
267 1 b1=ad%10;
268 1 b2=ad/10;
269 1 b2=b2%10;
270 1 b3=ad/100;
271 1 b3=b3%10;
272 1 b4=ad/1000;
273 1 }
274 void Page1(void)
275 {
276 1 column=0;page=0;
277 1 F_Write_Char(mo);F_Write_CharW(mao);
278 1 F_Write_CharW(num[b4]);
279 1 F_Write_CharW(num[b3]);
280 1 F_Write_CharW(num[b2]);F_Write_CharW(num[b1]);
281 1 }
282 void Page2(void)
283 {
284 1 column=0;page=2;
285 1 F_Write_Char(dao);F_Write_Char(na);F_Write_CharW(mao);
286 1 F_Write_CharW(num[0]);F_Write_CharW(point);
287 1 F_Write_CharW(num[0]);
288 1 column=64;page=2;
289 1 F_Write_CharW(num[0]);
290 1 }
291 void Page3(void)
292 {
293 1 column=0;page=0;
294 1 F_Write_Char(mo);
295 1 F_Write_Char(dao); F_Write_Char(na);
296 1 }
297
298 /**************************************
299 名称:main
300 *************************************/
301 void main()
C51 COMPILER V7.06 TLC2543 09/06/2007 04:26:33 PAGE 6
302 {
303 1 uint ad;
304 1 uchar i,j;
305 1 F_Init_LCD();
306 1 Page3();
307 1 delay(100);
308 1 delay(100);
309 1 delay(100);
310 1 delay(100);
311 1
312 1 for(i=0;i<10;i++)
313 1 {ad=read2543(0);
314 2
315 2 deal_addata(ad);
316 2 F_Init_LCD();
317 2 Page1();
318 2 for(j=0;j<100;j++)
319 2 delay(300);
320 2 Page2();
321 2 for(j=0;j<240;j++)
322 2 delay(500);
323 2 }}
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1009 ----
CONSTANT SIZE = 320 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 6 9
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -