📄 clock.lst
字号:
C51 COMPILER V7.06 CLOCK 11/05/2008 20:16:11 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE CLOCK
OBJECT MODULE PLACED IN clock.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE clock.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /************************************************
2 应用范例 3-5
3 标题:范例 3-5
4 版本:1.0//
5 Target: STC89C52RC
6 程序描述:这个程序说明如何利用单片机做个
7 电子钟
8 *************************************************/
9 #include<reg51.h>
10 #define uint unsigned int
11 #define uchar unsigned char
12 code seven_seg[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
13 code bit_select[6] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
14 char counter[3] = {0,0,0};
15 uint x,y,z,a,b,c,d;
16 sbit key1 = P3^0;
17 sbit key2 = P3^1;
18 sbit key3 = P3^2;
19 sbit key4 = P3^3;
20 sbit FMQ = P3^4;
21 sbit JDQ = P3^5;
22 uchar key1_state,key2_state,key3_state,key4_state,key1_flog;
23 /************************************************
24 延迟子函数
25 *************************************************/
26 void delay(uchar i)
27 {
28 1 while(i)
29 1 i--;
30 1 }
31 /**********************************************
32 初始化T0,每250uS中断一次
33 ***********************************************/
34 void timer0_init()
35 {
36 1 TMOD = 0x02;
37 1 TH0 = 0x06;
38 1 TL0 = 0x06;
39 1 TR0 = 1;
40 1 ET0 = 1;
41 1 EA = 1;
42 1 }
43 /**********************************************
44 T0的中断服务子程序
45 ***********************************************/
46 void timer0_isr() interrupt 1
47 {
48 1 x++;
49 1 if(x == 2000)
50 1 {
51 2 x = 0;
52 2 y++;
53 2 z = !z;
54 2 if(y == 2)
55 2 {
C51 COMPILER V7.06 CLOCK 11/05/2008 20:16:11 PAGE 2
56 3 counter[0]++;
57 3 y = 0;
58 3 }
59 2 }
60 1 }
61 /**********************************************
62 记时子函数
63 ***********************************************/
64 void counter_add1()
65 {
66 1 if(counter[0] >= 60)
67 1 {
68 2 counter[0] = 0;
69 2 counter[1]++;
70 2 }
71 1 if(counter[1] >= 60)
72 1 {
73 2 counter[1] = 0;
74 2 counter[2]++;
75 2 }
76 1 if(d == 0 && counter[2] > 24)
77 1 counter[2] = 0;
78 1 if(d == 1 && counter[2] > 13)
79 1 counter[2] = counter[2]-12;
80 1
81 1 }
82 /**********************************************
83 LED显示器显示子函数
84 ***********************************************/
85 void display()
86 {
87 1 uchar i;
88 1 P0 = a|seven_seg[counter[0]%10];
89 1 P2 = bit_select[0];
90 1 delay(100);
91 1 P0 = a|seven_seg[counter[0]/10];
92 1 P2 = bit_select[1];
93 1 delay(100);
94 1 P0 = b|seven_seg[counter[1]%10];
95 1 P2 = bit_select[2];
96 1 delay(100);
97 1 P0 = seven_seg[counter[1]/10];
98 1 P2 = b|bit_select[3];
99 1 delay(100);
100 1 i = 0x80*z;
101 1 i = 0x7f|i;
102 1 P0 = c|seven_seg[counter[2]%10]&i;
103 1 P2 = bit_select[4];
104 1 delay(100);
105 1 P0 = c|seven_seg[counter[2]/10];
106 1 P2 = bit_select[5];
107 1 delay(100);
108 1 }
109 /********************************************
110 按键检测子程序
111 ********************************************/
112 uchar gote_key()
113 {
114 1 if(key1 == 0 )
115 1 {
116 2 key1 = 1;
117 2 delay(100);
C51 COMPILER V7.06 CLOCK 11/05/2008 20:16:11 PAGE 3
118 2 if(key1 == 0)
119 2 key1_state = 1; //记忆key1按下的状态
120 2 }
121 1 if(key1 == 1 && key1_state == 1)
122 1 {
123 2 key1_state = 0;
124 2 key1_flog++;
125 2 }
126 1 if(key1_flog == 4)
127 1 key1_flog = 0;
128 1 return(key1_flog);
129 1 }
130 /********************************************
131 按键设置子程序
132 *********************************************/
133 void key_setup()
134 {
135 1 uchar i;
136 1 i = gote_key();
137 1 if(i == 3)
138 1 {
139 2 y =0;
140 2 if(key2 == 0)
141 2 {
142 3 key2 = 1;
143 3 ;;
144 3 if(key2 == 0)
145 3 key2_state= 1;
146 3 }
147 2 if(key2 == 1 && key2_state == 1)
148 2 {
149 3 key2_state = 0;
150 3 counter[0]++;
151 3 if(counter[0]>= 60)
152 3 counter[0] = 0;
153 3 }
154 2 if(key3 == 0 )
155 2 {
156 3 key3 = 1;
157 3 ;;
158 3 if(key3 == 0)
159 3 key3_state = 1;
160 3 }
161 2 if(key3 == 1 && key3_state == 1)
162 2 {
163 3 key3_state = 0;
164 3 counter[0]--;
165 3 if(counter[0] < 0)
166 3 counter[0] = 59;
167 3 }
168 2
169 2 a = z*0xff;
170 2 }
171 1 else a = 0;
172 1 //////
173 1 if(i == 2)
174 1 {
175 2 y =0;
176 2 if(key2 == 0)
177 2 {
178 3 key2 = 1;
179 3 ;;
C51 COMPILER V7.06 CLOCK 11/05/2008 20:16:11 PAGE 4
180 3 if(key2 == 0)
181 3 key2_state= 1;
182 3 }
183 2 if(key2 == 1 && key2_state == 1)
184 2 {
185 3 key2_state = 0;
186 3 counter[1]++;
187 3 if(counter[1]>= 60)
188 3 counter[1] = 0;
189 3 }
190 2 if(key3 == 0 )
191 2 {
192 3 key3 = 1;
193 3 ;;
194 3 if(key3 == 0)
195 3 key3_state = 1;
196 3 }
197 2 if(key3 == 1 && key3_state == 1)
198 2 {
199 3 key3_state = 0;
200 3 counter[1]--;
201 3 if(counter[1] < 0)
202 3 counter[1] = 59;
203 3 }
204 2
205 2 b = z*0xff;
206 2 }
207 1 else b = 0;
208 1
209 1 /////
210 1 if(i == 1)
211 1 {
212 2 y =0;
213 2 if(key2 == 0)
214 2 {
215 3 key2 = 1;
216 3 ;;
217 3 if(key2 == 0)
218 3 key2_state= 1;
219 3 }
220 2 if(key2 == 1 && key2_state == 1)
221 2 {
222 3 key2_state = 0;
223 3 counter[2]++;
224 3 if(counter[2] > 23 && d == 0)
225 3 counter[2] = 0;
226 3 if(counter[2] > 12 && d == 1)
227 3 counter[2] = 1;
228 3 }
229 2 if(key3 == 0 )
230 2 {
231 3 key3 = 1;
232 3 ;;
233 3 if(key3 == 0)
234 3 key3_state = 1;
235 3 }
236 2 if(key3 == 1 && key3_state == 1)
237 2 {
238 3 key3_state = 0;
239 3 counter[2]--;
240 3 if(counter[2] < 0 && d == 0)
241 3 counter[2] = 23;
C51 COMPILER V7.06 CLOCK 11/05/2008 20:16:11 PAGE 5
242 3 if(counter[2] < 1 && d == 1)
243 3 counter[2] = 12;
244 3 }
245 2 c = z*0xff;
246 2 }
247 1 else c = 0;
248 1 ////////
249 1 if(key4 == 0)
250 1 {
251 2 key4 = 1;
252 2 ;;
253 2 if(key4 == 0)
254 2 key4_state = 1;
255 2 }
256 1 if(key4 == 1 && key4_state == 1)
257 1 {
258 2 d = !d;
259 2 key4_state = 0;
260 2
261 2 }
262 1
263 1 }
264 /*********************************************
265 主函数
266 **********************************************/
267 void main()
268 {
269 1 timer0_init();
270 1 while(1)
271 1 {
272 2 key_setup();
273 2 display();
274 2 counter_add1();
275 2 }
276 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 921 ----
CONSTANT SIZE = 32 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 22 ----
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 + -