📄 clok.lst
字号:
C51 COMPILER V8.09 CLOK 07/18/2008 22:08:58 PAGE 1
C51 COMPILER V8.09, COMPILATION OF MODULE CLOK
OBJECT MODULE PLACED IN clok.OBJ
COMPILER INVOKED BY: F:\ApplicationSoftware\Keil\C51\BIN\C51.EXE clok.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<reg52.h>
2
3 #define uchar unsigned char
4 #define uint unsigned int
5
6 sbit rs=P2^7;
7 sbit rw =P2^6;
8 sbit lcden=P2^5;
9
10 sbit timeadj=P3^5;
11 sbit timeadd=P3^4;
12 sbit timedec=P3^3;
13 uchar pushnum;
14 static char count,sec,min,hou;
15
16 uchar code table1[]= "TIME 08-03-20";
17 uchar code table2[]= " 00:00:00 ";
18
19 void delay(uint z)
20 {
21 1 uint x,y;
22 1 for(x=z;x>0;x--)
23 1 for(y=110;y>0;y--);
24 1 }
25
26 void write_com(uchar com)
27 {
28 1 rs=0;
29 1 rw=0;
30 1 lcden=0;
31 1 P0=com;
32 1 delay(5);
33 1 lcden=1;
34 1 delay(5);
35 1 lcden=0;
36 1 }
37
38 void write_date(uchar date)
39 {
40 1 rs=1;
41 1 rw=0;
42 1 lcden=0;
43 1 P0=date;
44 1 delay(5);
45 1 lcden=1;
46 1 delay(5);
47 1 lcden=0;
48 1 }
49
50 void init()
51 {
52 1 uchar num;
53 1 lcden=0;
54 1 min=00;
55 1 sec=00;
C51 COMPILER V8.09 CLOK 07/18/2008 22:08:58 PAGE 2
56 1 hou=00;
57 1 write_com(0x38); //设置显示模式:数据总线长度8,两行,5*7字体
58 1 delay(5);
59 1 write_com(0x0c); //显示开关设置:显示状态开,光标不显示,不闪烁
60 1 delay(5);
61 1 write_com(0x06); //设置输入方式:光标右移一格,AC加一,字符不动
62 1 delay(5);
63 1 write_com(0x01); //清屏
64 1 delay(5);
65 1 write_com(0x80); //DDRAM7位地址设置:初始地址设为0x00
66 1 delay(5);
67 1
68 1 for(num=0;num<15;num++)
69 1 {
70 2 write_date(table1[num]);
71 2 delay(5);
72 2 }
73 1
74 1 write_com(0x80+0x40);
75 1
76 1 for(num=0;num<14;num++)
77 1 {
78 2 write_date(table2[num]);
79 2 delay(5);
80 2 }
81 1
82 1 TMOD=0x01;
83 1 TH0=0x4C;
84 1 TL0=0x00;
85 1 EA=1;
86 1 ET0=1;
87 1 TR0=1;
88 1
89 1 }
90
91
92 void update_time(uchar LEDadd_num,uchar time)
93 {
94 1 uchar shi,ge;
95 1 shi=time/10;
96 1 ge=time%10;
97 1 write_com(0x80+0x40+LEDadd_num);
98 1 write_date(0x30+shi);
99 1 write_date(0x30+ge);
100 1 }
101
102 void keyscan()
103 {
104 1 if(timeadj==0)
105 1 {
106 2 delay(5);
107 2 if(timeadj==0)
108 2 {
109 3 while(!timeadj);
110 3 pushnum++;
111 3 switch(pushnum)
112 3 {
113 4 case 1:
114 4 TR0=0;
115 4 write_com(0x80+0x40+10); //地址指针在秒的十位
116 4 write_com(0x0f);//光标显示并闪烁(在当前地址的下一位)
117 4 break;
C51 COMPILER V8.09 CLOK 07/18/2008 22:08:58 PAGE 3
118 4 case 2:
119 4 write_com(0x80+0x40+7);//地址指针在分的十位
120 4 break;
121 4 case 3:
122 4 write_com(0x80+0x40+4);
123 4 break;
124 4 case 4:
125 4 pushnum=0;
126 4 write_com(0x0c);//关闭光标显示和闪烁
127 4 TR0=1;
128 4 break;
129 4 }
130 3 }
131 2 }
132 1
133 1
134 1 if(pushnum!=0)
135 1 {
136 2 if(timeadd==0)
137 2 {
138 3 delay(5);
139 3 if(timeadd==0)
140 3 {
141 4 while(!timeadd);
142 4 if(pushnum==1)
143 4 {
144 5 if(sec==59)
145 5 sec=-1;
146 5 sec++; //加后为0
147 5 update_time(10,sec);
148 5 write_com(0x80+0x40+10);
149 5 }
150 4 if(pushnum==2)
151 4 {
152 5 if(min==59)
153 5 min=-1;
154 5 min++;
155 5 update_time(7,min);
156 5 write_com(0x80+0x40+7);
157 5 }
158 4 if(pushnum==3)
159 4 {
160 5 if(hou==23)
161 5 hou=-1;
162 5 hou++;
163 5 update_time(4,hou);
164 5 write_com(0x80+0x40+4);
165 5 }
166 4 }
167 3 }
168 2 if(timedec==0)
169 2 {
170 3 delay(5);
171 3 if(timedec==0)
172 3 {
173 4 while (! timedec );
174 4 if(pushnum==1)
175 4 {
176 5 /* if(sec==0)
177 5 {
178 5 sec=59;
179 5 update_time(10,sec);
C51 COMPILER V8.09 CLOK 07/18/2008 22:08:58 PAGE 4
180 5 write_com(0x80+0x40+10);
181 5 }
182 5 */
183 5 if(sec==0)
184 5 sec=60;
185 5 sec--; //减后为59
186 5 update_time(10,sec);
187 5 write_com(0x80+0x40+10);
188 5
189 5 }
190 4 if(pushnum==2)
191 4 {
192 5
193 5 if(min==0)
194 5 min=60;
195 5 min--;
196 5 update_time(7,min);
197 5 write_com(0x80+0x40+7);
198 5 }
199 4 if(pushnum==3)
200 4 {
201 5 if(hou==0)
202 5 hou=24;
203 5 hou--;
204 5 update_time(4,hou);
205 5 write_com(0x80+0x40+4);
206 5 }
207 4 }
208 3 }
209 2 }
210 1 }
211
212 void main()
213 {
214 1 init();
215 1 while(1)
216 1 {
217 2 if(count==20)
218 2 {
219 3 count=0;
220 3 sec++;
221 3 if(sec==60)
222 3 {
223 4 sec=0;
224 4 min++;
225 4 if(min==60)
226 4 {
227 5 min=0;
228 5 hou++;
229 5 if(hou==24)
230 5 hou=0;
231 5 update_time(4,hou);//时判断完后,送液晶刷新显示
232 5 }
233 4 update_time(7,min); //分判断完后,送液晶刷新显示
234 4 }
235 3 update_time(10,sec); //秒判断完后,送液晶刷新显示
236 3
237 3 }
238 2 keyscan();
239 2 }
240 1 }
241
C51 COMPILER V8.09 CLOK 07/18/2008 22:08:58 PAGE 5
242 void timer0() interrupt 1
243 {
244 1 TH0=0x4C;
245 1 TL0=0x00;
246 1 count++;
247 1 }
248
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 517 ----
CONSTANT SIZE = 31 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -