📄 clock.lst
字号:
C51 COMPILER V8.02 CLOCK 03/30/2008 19:41:33 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE CLOCK
OBJECT MODULE PLACED IN clock.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE clock.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 数字时钟
3 时钟频率24MHz
4 */
5
6 #include<reg51.h>
7 #include<intrins.h>
8
9 unsigned char code LED_CODES[]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
10
11 unsigned char hhh,hhl,mmh,mml,ssh,ssl;
12 unsigned char hhls,hhhs,mmhs,mmls;
13 unsigned char display_array[6]={0xc0,0xc0,0xc0,0xc0,0xc0,0xc0};
14 unsigned char display_set[6]={0xff,0xff,0xff,0xff,0xff,0xff};
15 unsigned char tt1=0,tt2=0,tt3=8;
16 unsigned char display_flag=0;
17 unsigned char flash=0;
18
19 void init();
20 void delay(int d);
21 void display0(unsigned char *p);
22 void display1();
23 void display2();
24
25 void main()
26 {
27 1 TMOD=0x11;
28 1 TH0=0x3C;
29 1 TL0=0xAF;
30 1 TH1=0x00;
31 1 TL1=0x00;
32 1 IT0=1;
33 1 IT1=1;
34 1 EA=1;
35 1 ET0=1;
36 1 ET1=1;
37 1 TR0=1;
38 1 TR1=1;
39 1 EX0=1;
40 1 EX1=1;
41 1 init();
42 1 while(1)
43 1 {
44 2 display_array[0]=LED_CODES[ssl];
45 2 display_array[1]=LED_CODES[ssh];
46 2 display_array[2]=LED_CODES[mml];
47 2 display_array[3]=LED_CODES[mmh];
48 2 display_array[4]=LED_CODES[hhl];
49 2 display_array[5]=LED_CODES[hhh];
50 2 if(display_flag==0)
51 2 display0(display_array);
52 2 else if(display_flag==1)
53 2 display1();
54 2 else if(display_flag==2)
55 2 display2();
C51 COMPILER V8.02 CLOCK 03/30/2008 19:41:33 PAGE 2
56 2 }
57 1 }
58
59 void timer1() interrupt 1 //秒计时器
60 {
61 1 TH0=0x3C;
62 1 TL0=0xAF;
63 1 tt1++;
64 1 if(tt1==5) //40为一秒
65 1 {
66 2 ssl++;
67 2 if(ssl==10)
68 2 {
69 3 ssh++;
70 3 ssl=0;
71 3 }
72 2 if(ssh==6)
73 2 {
74 3 mml++;
75 3 ssh=0;
76 3 }
77 2 if(mml==10)
78 2 {
79 3 mmh++;
80 3 mml=0;
81 3 }
82 2 if(mmh==6)
83 2 {
84 3 hhl++;
85 3 mmh=0;
86 3 }
87 2 if(hhl==10)
88 2 {
89 3 hhh++;
90 3 hhl=0;
91 3 }
92 2 if(hhl==4&&hhh==2)
93 2 {
94 3 hhh=0;
95 3 hhl=0;
96 3 }
97 2 tt1=0;
98 2 }
99 1 }
100
101 void timer2() interrupt 3 //闪烁延时
102 {
103 1 TH1=0x00;
104 1 TL1=0x00;
105 1 tt2++;
106 1 if(tt2==tt3)
107 1 {
108 2 if(flash==0)
109 2 {
110 3 flash=1;
111 3 tt3=8;
112 3 }
113 2 else
114 2 {
115 3 flash=0;
116 3 tt3=12;
117 3 }
C51 COMPILER V8.02 CLOCK 03/30/2008 19:41:33 PAGE 3
118 2 tt2=0;
119 2 }
120 1 }
121
122 void display0(unsigned char *p) //显示6个数码管
123 {
124 1 int k;
125 1 P2=0x80;
126 1 for(k=5;k>=0;k--)
127 1 {
128 2 P2=_crol_(P2,1);
129 2 P1=p[k];
130 2 delay(1);
131 2 }
132 1 }
133
134 void display1() //设置小时时的显示
135 {
136 1 if(flash==0)
137 1 {
138 2 display_set[5]=LED_CODES[hhhs];
139 2 display_set[4]=LED_CODES[hhls];
140 2 display_set[3]=0xff;
141 2 display_set[2]=0xff;
142 2 display_set[1]=0xff;
143 2 display_set[0]=0xff;
144 2 display0(display_set);
145 2 }
146 1 else
147 1 {
148 2 display_set[5]=0xff;
149 2 display_set[4]=0xff;
150 2 display_set[3]=0xff;
151 2 display_set[2]=0xff;
152 2 display_set[1]=0xff;
153 2 display_set[0]=0xff;
154 2 display0(display_set);
155 2 }
156 1 }
157
158 void display2() //设置分钟时的显示
159 {
160 1 if(flash==0)
161 1 {
162 2 display_set[5]=0xff;
163 2 display_set[4]=0xff;
164 2 display_set[3]=LED_CODES[mmhs];
165 2 display_set[2]=LED_CODES[mmls];
166 2 display_set[1]=0xff;
167 2 display_set[0]=0xff;
168 2 display0(display_set);
169 2 }
170 1 else
171 1 {
172 2 display_set[5]=0xff;
173 2 display_set[4]=0xff;
174 2 display_set[3]=0xff;
175 2 display_set[2]=0xff;
176 2 display_set[1]=0xff;
177 2 display_set[0]=0xff;
178 2 display0(display_set);
179 2 }
C51 COMPILER V8.02 CLOCK 03/30/2008 19:41:33 PAGE 4
180 1 }
181
182 void delay(int d) //普通延时
183 {
184 1 unsigned char i,j;
185 1 for(i=d;i>0;i--)
186 1 for(j=50;j>0;j--);
187 1 }
188
189 void init() //初始化
190 {
191 1 P1=0x00;
192 1 hhh=hhl=mmh=mml=ssh=ssl=0x00;
193 1 }
194
195 void mint0() interrupt 0 //外部中断0,set1键
196 {
197 1 display_flag++;
198 1 if(display_flag==1)
199 1 {
200 2 hhhs=hhh;
201 2 hhls=hhl;
202 2 }
203 1 if(display_flag==2)
204 1 {
205 2 mmhs=mmh;
206 2 mmls=mml;
207 2 }
208 1 if(display_flag==3)
209 1 {
210 2 display_flag=0;
211 2 if(hhh!=hhhs||hhl!=hhls||mmh!=mmhs||mml!=mmls)
212 2 {
213 3 ssl=0;
214 3 ssh=0;
215 3 }
216 2 hhh=hhhs;
217 2 hhl=hhls;
218 2 mmh=mmhs;
219 2 mml=mmls;
220 2 }
221 1 delay(1);
222 1 }
223
224 void mint1() interrupt 2 //外部中断1,set2键
225 {
226 1 if(display_flag==1)
227 1 { //设定时
228 2 hhls++;
229 2 if(hhls==10)
230 2 {
231 3 hhhs++;
232 3 hhls=0;
233 3 }
234 2 if(hhls==4&&hhhs==2)
235 2 {
236 3 hhhs=0;
237 3 hhls=0;
238 3 }
239 2 }
240 1 if(display_flag==2)
241 1 { //设定分
C51 COMPILER V8.02 CLOCK 03/30/2008 19:41:33 PAGE 5
242 2 mmls++;
243 2 if(mmls==10)
244 2 {
245 3 mmhs++;
246 3 mmls=0;
247 3 }
248 2 if(mmhs==6)
249 2 mmhs=0;
250 2 }
251 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 592 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 27 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 + -