📄 1302.lst
字号:
C51 COMPILER V7.02b 1302 03/20/2009 20:12:09 PAGE 1
C51 COMPILER V7.02b, COMPILATION OF MODULE 1302
OBJECT MODULE PLACED IN 1302.OBJ
COMPILER INVOKED BY: D:\Keil uVision 2\C51\BIN\C51.EXE 1302.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg51.h>
2 #define uint unsigned int
3 #define uchar unsigned char
4 sbit ds_rst=P2^3;
5 sbit ds_io=P2^4;
6 sbit ds_clk=P2^5;
7 sbit s0=P3^0;
8 sbit s1=P3^1;
9 sbit s2=P3^2;
10 sbit s3=P3^3;
11 sbit LCD_EN=P3^4;
12 sbit LCD_RS=P3^5;
13 bit flag;
14
15 void LCD_display();
16
17 uchar taa[]={"20 - - W "};
18 uchar tab[]={" : : @_@! "};
19 uchar tad[7];
20 uchar nian,yue,ri,zhou,sh,fen,miao;
21 void delayms(uint z)
22 {
23 1 uint x,y;
24 1 for(x=0;x<=110;x++)
25 1 for(y=0;y<=z;y++);
26 1 }
27 void break_init()
28 {
29 1 TMOD=0x01;
30 1 TH0=(65535-50000)/256;
31 1 TL0=(65535-50000)%256;
32 1 EA=1;
33 1 ET0=1;
34 1 TR0=1;
35 1 }
36 /***************时钟1302***********************************/
37 void DS_write_byte(uchar date)
38 {
39 1 uchar i;
40 1 ds_rst=1;
41 1 for(i=0;i<8;i++)
42 1 {
43 2 if((date&0x01)==1)
44 2 ds_io=1;
45 2 else
46 2 ds_io=0;
47 2 date>>=1;
48 2 ds_clk=1;
49 2 ds_clk=0;
50 2 }
51 1 }
52
53 uchar DS_read_byte()
54 {
55 1 uchar date,i;
C51 COMPILER V7.02b 1302 03/20/2009 20:12:09 PAGE 2
56 1 ds_rst=1;
57 1 for(i=0;i<8;i++)
58 1 {
59 2 if(ds_io==1)
60 2 date=(date>>1)|0x80;
61 2 else
62 2 date=date>>1;
63 2
64 2 ds_clk=1;
65 2 ds_clk=0;
66 2 }
67 1 return date;
68 1 }
69
70 void DS_write_com(uchar add,uchar date)
71 {
72 1 ds_rst=0;
73 1 ds_clk=0;
74 1 ds_rst=1;
75 1 DS_write_byte(add);
76 1 delayms(15);
77 1 DS_write_byte(date);
78 1 ds_rst=0;
79 1 }
80
81 uchar DS_read(uchar add)
82 {
83 1 uchar date;
84 1 ds_rst=0;
85 1 ds_clk=0;
86 1 ds_rst=1;
87 1 DS_write_byte(add);
88 1 delayms(15);
89 1 date=DS_read_byte();
90 1 ds_rst=0;
91 1 return date;
92 1 }
93
94 /***************液晶1062**************************************/
95 void LCD_write_com(uchar com)
96 {
97 1 P0=com; //写入命令
98 1 LCD_RS=0;
99 1 delayms(5);
100 1 LCD_EN=1;
101 1 delayms(5);
102 1 LCD_EN=0;
103 1 }
104 void LCD_write_data(uchar date)
105 {
106 1 P0=date; //写入数据
107 1 LCD_RS=1;
108 1 delayms(5);
109 1 LCD_EN=1;
110 1 delayms(5);
111 1 LCD_EN=0;
112 1 }
113 void LCD_init()
114 {
115 1 uchar i;
116 1 LCD_write_com(0x38);//显示16*2接口
117 1 LCD_write_com(0x01);//清屏
C51 COMPILER V7.02b 1302 03/20/2009 20:12:09 PAGE 3
118 1 LCD_write_com(0x0c);//00001DCB,D开显示C显示光标B光标闪烁
119 1 LCD_write_com(0x06);//000001NS,N1指针、光标加一,N0指针、光标减一。S1整屏左移N1/右移N0,S0整屏不移动
120 1 LCD_write_com(0x80);
121 1 for(i=0;i<16;i++)
122 1 {
123 2 LCD_write_data(taa[i]);
124 2 delayms(5);
125 2 }
126 1 LCD_write_com(0x80+0x40);
127 1 for(i=0;i<16;i++)
128 1 {
129 2 LCD_write_data(tab[i]);
130 2 delayms(5);
131 2 }
132 1 }
133 void LCD_sfm(uchar add,uchar line,uchar date)
134 {
135 1 uchar shi,ge;
136 1 shi=(date>>4)&0x0f;
137 1 ge=date&0x0f;
138 1 if(ge==10)
139 1 shi++;
140 1 if(line==0)
141 1 LCD_write_com(0x80+add);
142 1 else
143 1 LCD_write_com(0x80+0x40+add);
144 1 LCD_write_data(0x30+shi);
145 1 LCD_write_data(0x30+ge);
146 1 }
147 void LCD_sfm1(uchar add,uchar line,uchar date,uchar addr)
148 {
149 1 uchar shi,ge,temp;
150 1 shi=date/10;
151 1 ge=date%10;
152 1 temp=(temp&0x0f)|shi;
153 1 temp<<=4;
154 1 temp=temp|ge;
155 1 DS_write_com(addr,temp);
156 1 if(line==0)
157 1 LCD_write_com(0x80+add);
158 1 else
159 1 LCD_write_com(0x80+0x32+add);
160 1 LCD_write_data(0x30+shi);
161 1 LCD_write_data(0x30+ge);
162 1 }
163 /*****************按键控制***************************************************/
164 LCD_key()
165 {
166 1 uchar add;
167 1 while(s0==0)
168 1 {
169 2 delayms(50);
170 2 while(s0==0)
171 2 {
172 3 flag=1;
173 3 if(add==0)
174 3 {
175 4 LCD_write_com(0x80+0x54);
176 4 LCD_write_com(0x0f);
177 4 }
178 3 if((add<15)&(add!=0)==1)
179 3 LCD_write_com(0x81+add);
C51 COMPILER V7.02b 1302 03/20/2009 20:12:09 PAGE 4
180 3 if(add>=15)
181 3 LCD_write_com(0x80+0x33+add);
182 3 while(s0!=1);
183 3 add++;
184 3 while(add==24)
185 3 add=0;
186 3 }
187 2 }
188 1 while(s1==0)
189 1 {
190 2 delayms(5);
191 2 while(s1==0)
192 2 {
193 3 switch(add)
194 3 {
195 4 case 3:nian++;while(nian==100) nian=0;LCD_sfm1(2,0,nian,0x8c);LCD_write_com(0x80+3);break;
196 4 case 6:yue++;while(yue==13) yue=0;LCD_sfm1(5,0,yue,0x88);LCD_write_com(0x80+6);break;
197 4 case 9:ri++;while(ri==31) ri=0;LCD_sfm1(8,0,ri,0x86);LCD_write_com(0x80+9);break;
198 4 case 14:zhou++;while(zhou==8) zhou=0;LCD_sfm1(13,0,zhou,0x8a);LCD_write_com(0x80+13);break;
199 4 case 17:sh++;while(sh==24) sh=0;LCD_sfm1(16,1,sh,0x84);LCD_write_com(0x80+0x40+3);break;
200 4 case 20:fen++;while(fen==60) fen=0;LCD_sfm1(19,1,fen,0x82);LCD_write_com(0x80+0x40+6);break;
201 4 case 23:miao++;while(miao==60) miao=0;LCD_sfm1(22,1,miao,0x80);LCD_write_com(0x80+0x40+9);break;
202 4 }
203 3 while(s1!=1);
204 3 }
205 2 }
206 1 while(s2==0)
207 1 {
208 2 delayms(5);
209 2 while(s2==0)
210 2 {
211 3 switch(add)
212 3 {
213 4 case 3:nian--;while(nian==0) nian=99;LCD_sfm1(2,0,nian,0x8c);LCD_write_com(0x80+3);break;
214 4 case 6:yue--;while(yue==0) yue=12;LCD_sfm1(5,0,yue,0x88);LCD_write_com(0x80+6);break;
215 4 case 9:ri--;while(ri==0) ri=31;LCD_sfm1(8,0,ri,0x86);LCD_write_com(0x80+9);break;
216 4 case 14:zhou--;while(zhou==0) zhou=7;LCD_sfm1(13,0,zhou,0x8a);LCD_write_com(0x80+13);break;
217 4 case 17:sh--;while(sh==0) sh=23;LCD_sfm1(16,1,sh,0x84);LCD_write_com(0x80+0x40+3);break;
218 4 case 20:fen--;while(fen==0) fen=59;LCD_sfm1(19,1,fen,0x82);LCD_write_com(0x80+0x40+6);break;
219 4 case 23:miao--;while(miao==0) miao=59;LCD_sfm1(22,1,miao,0x80);LCD_write_com(0x80+0x40+9);break;
220 4 }
221 3 while(s1!=1);
222 3 }
223 2 }
224 1
225 1 while(s3==0)
226 1 {
227 2 delayms(5);
228 2 while(s3==0)
229 2 {
230 3 add=1;
231 3 LCD_write_com(0x80+0x40+add);
232 3 LCD_write_com(0x0c);
233 3 flag=0;
234 3 while(s3!=1);
235 3 }
236 2 }
237 1 }
238 /******************显示********************************************/
239 void DS_clock()
240 {
241 1 uchar add=0x81,i;
C51 COMPILER V7.02b 1302 03/20/2009 20:12:09 PAGE 5
242 1 for(i=0;i<7;i++)
243 1 {
244 2 tad[i]=DS_read(add);
245 2 add+=2;
246 2 }
247 1 }
248 void LCD_display() //显示数据
249 {
250 1 LCD_sfm(2,0,tad[6]); //年
251 1 LCD_sfm(5,0,tad[4]); //月
252 1 LCD_sfm(8,0,tad[3]); //日
253 1 LCD_sfm(13,0,tad[5]); //周
254 1 LCD_sfm(2,1,tad[2]); //时
255 1 LCD_sfm(5,1,tad[1]); //分
256 1 LCD_sfm(8,1,tad[0]); //秒
257 1 nian=tad[6];yue=tad[4];ri=tad[3];zhou=tad[5];sh=tad[2];fen=tad[1];miao=tad[0];
258 1 }
259
260 /********************主函数********************************************************/
261 main()
262 {
263 1 break_init();
264 1 LCD_init();
265 1 while(1)
266 1 {
267 2
268 2 while(flag==0)
269 2 {
270 3 DS_clock();
271 3 LCD_display();
272 3 }
273 2 }
274 1 }
275 time0() interrupt 1
276 {
277 1 TH0=(65535-50000)/256;
278 1 TL0=(65535-50000)%256;
279 1 LCD_key();
280 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1181 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 48 11
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 + -