📄 闹钟.lst
字号:
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 闹钟
OBJECT MODULE PLACED IN 闹钟.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 闹钟.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include<reg52.h>
2 #include<stdio.h>
3 void delay(int a);
4 int outfunction(int a); //端口输出设置函数
5 void recount(); //时间计算函数
6 int alm();
7 sfr p0=0x80;
8 sfr p2=0xA0;
9 sfr p1=0x90;
10 sbit p13=0x93;
11 sbit p37=0xb7;
12 int i,j;
13 int timecount=0;//用于秒计时器的计数 定时器每250机器周期中断一次,计数4000次就达到1秒
14 int timecount2=0;//用于计时器误差的校正.
15 int temp[9],l=0,k=1,m,keyon,keynumber;//用于时间校正的临时变量
16 int year,month,date,hour,minute,second;
17 int alm_hour,alm_minute,alm_type,alm_run=1; //闹钟
18 bit stopb;
19 bit flagb;
20 //定义时间初始值
21 year=2008;
22 month=00;
23 date=00;
24 hour=0;
25 minute=0;
26 second=0;
27 alm_hour=6;
28 alm_minute=0;
29 alm_type=0;//默认闹钟关
30 int cout1[11]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X40};
31 int cout2[8]={0XFE,0XFD,0XFB,0XF7,0XEF,0XDF,0XBF,0X7F};
32 ///////////////////////////////main()////////////////////////////////////
33 main()
34 {
35 1 TMOD=0x22;
36 1 TH0=0X06;
37 1 TL0=0X06;
38 1 PT0=1; //定时器0设定为高优先级
39 1 PX0=0;//外部中断0设置为低优先级
40 1 PX1=0;
41 1 ET0=1;
42 1 EX0=1;
43 1 EX1=1;
44 1 EA=1;
45 1 TF0=0;
46 1 TR0=1;//定时器0准备开始
47 1 p37=1;
48 1 while(1)
49 1 {
50 2 p2=cout2[0];
51 2 p0=outfunction(hour/10);
52 2 delay(5);
53 2 p0=0x00;
54 2 p2=cout2[1];
55 2 p0=outfunction(hour%10);
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 2
56 2 delay(5);
57 2 p0=0x00;
58 2 p2=cout2[2];
59 2 p0=cout1[10];
60 2 delay(7);
61 2 p0=0x00;
62 2 p2=cout2[3];
63 2 p0=outfunction(minute/10);
64 2 delay(5);
65 2 p0=0x00;
66 2 p2=cout2[4];
67 2 p0=outfunction(minute%10);
68 2 delay(5);
69 2 p0=0x00;
70 2 p2=cout2[5];
71 2 p0=cout1[10];
72 2 delay(7);
73 2 p0=0x00;
74 2 p2=cout2[6];
75 2 p0=outfunction(second/10);
76 2 delay(5);
77 2 p0=0x00;
78 2 p2=cout2[7];
79 2 p0=outfunction(second%10);
80 2 delay(5);
81 2 p0=0x00;
82 2 if(alm_type==1&&alm_minute==minute&&alm_hour==hour&&alm_run==1) //判断闹钟
83 2 alm_run=alm();
84 2 if(alm_run==0&&alm_minute!=minute) alm_run=1;
85 2 recount();//换算时分秒
86 2 }
87 1 }
88 ///////////////////////////////计时中断//////////////////////////////////
89 void Timer0_Overflow() interrupt 1 using 0
90 {
91 1
92 1
93 1 if(timecount2==4700)
94 1 {
95 2 timecount++;
96 2 timecount2=0;
97 2 }
98 1 if(timecount<4000)
99 1 {
100 2 timecount++;
101 2 timecount2++;
102 2 }
103 1 else
104 1 {
105 2 timecount=0;
106 2 second++;
107 2 }
108 1
109 1 }
110 ////////////////////////////显示日期////////////////////////////////////
111 void int0() interrupt 0 using 0 //中断显示日期
112 {
113 1 j=1000;
114 1 while(j--)
115 1 {
116 2 p2=cout2[0];
117 2 p0=outfunction(year/1000);
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 3
118 2 delay(5);
119 2 p0=0x00;
120 2 p2=cout2[1];
121 2 p0=outfunction((year%1000)/100);
122 2 delay(5);
123 2 p0=0x00;
124 2 p2=cout2[2];
125 2 p0=outfunction((year%100)/10);
126 2 delay(5);
127 2 p0=0x00;
128 2 p2=cout2[3];
129 2 p0=outfunction(year%10);
130 2 delay(5);
131 2 p0=0x00;
132 2 p2=cout2[4];
133 2 p0=outfunction(month/10);
134 2 delay(5);
135 2 p0=0x00;
136 2 p2=cout2[5];
137 2 p0=outfunction(month%10);
138 2 delay(5);
139 2 p0=0x00;
140 2 p2=cout2[6];
141 2 p0=outfunction(date/10);
142 2 delay(5);
143 2 p0=0x00;
144 2 p2=cout2[7];
145 2 p0=outfunction(date%10);
146 2 delay(5);
147 2 p0=0x00;
148 2 recount();//换算时分秒
149 2 }
150 1 }
151 ///////////////////////////////时间设置////////////////////////////////////
152 void int1() interrupt 2 using 1
153 {
154 1 temp[3]=year;
155 1 temp[4]=month;
156 1 temp[5]=date;
157 1 temp[6]=alm_hour;
158 1 temp[7]=alm_minute;
159 1 temp[8]=alm_type;
160 1 m=0;
161 1 keyon=0;
162 1 keynumber=0xff;
163 1 while(1)
164 1 {
165 2
166 2
167 2 //键盘检测
168 2 if(p1==0xff);
169 2 else
170 2 {
171 3 keyon=1;
172 3 keynumber=p1;
173 3 }
174 2 if(keyon==1&&p1==0xff)
175 2 {
176 3 if(keynumber==0xfe)
177 3 {
178 4 if(m>=8)
179 4 m=0;
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 4
180 4 else
181 4 m++;
182 4 }
183 3 if(keynumber==0xfd)
184 3 {
185 4 if(m==0)
186 4 {
187 5 if(hour<23)
188 5 hour++;
189 5 else
190 5 hour=0;
191 5 }
192 4 if(m==6)
193 4 {
194 5 if(temp[m]<23)
195 5 temp[m]++;
196 5 else
197 5 temp[m]=0;
198 5 }
199 4 if(m==1)
200 4 {
201 5 if(minute<59)
202 5 minute++;
203 5 else
204 5 minute=0;
205 5 }
206 4 if(m==2)
207 4 {
208 5 if(second<59)
209 5 second++;
210 5 else
211 5 second=0;
212 5 }
213 4 if(m==7)
214 4 {
215 5 if(temp[m]<59)
216 5 temp[m]++;
217 5 else
218 5 temp[m]=0;
219 5 }
220 4 //以下3 4 5日期设定
221 4 if(m==3) //年
222 4 {
223 5 if(temp[m]<2032)
224 5 temp[m]++;
225 5 else
226 5 temp[m]=2007;
227 5 }
228 4 if(m==4) //月
229 4 {
230 5 if(temp[m]<12)
231 5 temp[m]++;
232 5 else
233 5 temp[m]=1;
234 5 }
235 4 if(m==5) //日
236 4 {
237 5 if(temp[4]==1||temp[4]==3||temp[4]==5||temp[4]==7||temp[4]==8||temp[4]==10||temp[4]==12)
238 5 {
239 6 if(temp[m]<31)
240 6 temp[m]++;
241 6 else
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 5
242 6 temp[m]=1;
243 6 }
244 5 if(temp[4]==4||temp[4]==6||temp[4]==9||temp[4]==11)
245 5 {
246 6 if(temp[m]<30)
247 6 temp[m]++;
248 6 else
249 6 temp[m]=1;
250 6 }
251 5 if(temp[4]==2)
252 5 {
253 6 if(temp[3]%4==0 && temp[3]%100!=0 || temp[3]%400==0)
254 6 {
255 7 if(temp[m]<29)
256 7 temp[m]++;
257 7 else
258 7 temp[m]=1;
259 7 }
260 6 if(!(temp[3]%4==0 && temp[3]%100!=0 || temp[3]%400==0))
261 6 {
262 7 if(temp[m]<28)
263 7 temp[m]++;
264 7 else
265 7 temp[m]=1;
266 7 }
267 6 }
268 5 }
269 4 if(m==8) //控制闹钟的开关
270 4 {
271 5 if(temp[m]==0)
272 5 temp[m]=1;
273 5 else
274 5 temp[m]=0;
275 5 }
276 4 }
277 3 if(keynumber==0xfb)
278 3 {
279 4 year=temp[3];
280 4 month=temp[4];
281 4 date=temp[5];
282 4 alm_hour=temp[6];
283 4 alm_minute=temp[7];
284 4 alm_type=temp[8];
285 4 break;
286 4 }
287 3 if(keynumber==0xf7)
288 3 {
289 4 break;
290 4 }
291 3 keyon=0;
292 3 keynumber=0xff;
293 3
294 3
295 3 }
296 2 //以下调节时的显示部分
297 2 //时分秒调节
298 2 if(m==0||m==1||m==2)
299 2 {
300 3 if(m==0&&k==-1)
301 3 delay(8);
302 3 else
303 3 {
C51 COMPILER V7.06 闹钟 11/22/2008 15:33:51 PAGE 6
304 4 p2=cout2[0];
305 4 p0=outfunction(hour/10);
306 4 delay(5);
307 4 p0=0x00;
308 4 p2=cout2[1];
309 4 p0=outfunction(hour%10);
310 4 delay(5);
311 4 p0=0x00;
312 4 }
313 3 p2=cout2[2];
314 3 p0=cout1[10];
315 3 delay(7);
316 3 p0=0x00;
317 3 if(m==1&&k==-1)
318 3 delay(8);
319 3 else
320 3 {
321 4 p2=cout2[3];
322 4 p0=outfunction(minute/10);
323 4 delay(5);
324 4 p0=0x00;
325 4 p2=cout2[4];
326 4 p0=outfunction(minute%10);
327 4 delay(5);
328 4 p0=0x00;
329 4 }
330 3 p2=cout2[5];
331 3 p0=cout1[10];
332 3 delay(7);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -