📄 xiaonaozhong.lst
字号:
C51 COMPILER V8.08 XIAONAOZHONG 06/29/2008 23:34:51 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE XIAONAOZHONG
OBJECT MODULE PLACED IN xiaonaozhong.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE xiaonaozhong.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //******************************************//
2 //********电子小闹钟************************//
3 //********AT89S51***************************//
4 //********晶振用12M*************************//
5
6
7 #include "reg51.h"
8 #define uchar unsigned char
9 #define uint unsigned int
10 char DATA_7SEG[]={0x28,0xEB,0x32,0xA2,0xE1,0xA4,0x24,0xEA,0x20,
11 0xA0,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};/*0~9的数码管段码*/
12 uchar hour=0,min=0,sec=0; /*时、分、秒单元清零*/
13 uchar deda=0; /*5mS计数单元清零*/
14 uchar t_hour=0,t_min=0; /*闹时时、分单元清零*/
15 bit d_05s=0; /*0.5秒标志*/
16 bit o_f=0; /*闹时启/停标志*/
17 uchar set=0; /*模式设定标志*/
18 uchar m=0;
19 uchar flag=0; /*RAM掉电标志*/
20 void delay(uint k); /*延时子函数*/
21 void conv(); /*走时单元转换*/
22 void p_out(); /*判别闹时到否子函数*/
23 void dirve(); /*走时时间输出驱动子函数*/
24 void t_dirve(); /*闹时时间输出驱动子函数*/
25 sbit P3_4=P3^4; //模式设定键set(P3.4)
26 sbit P3_5=P3^5; //时调整键hour(P3.5)
27 sbit P3_7=P3^7; //分调整键min(P3.7)
28 sbit P1_7=P1^7;
29 sbit P3_1=P3^1;
30 //********************************************//
31 //********************************************//
32 /*闹时启/停子函数*/
33 void time1_of()
34 {uchar m;
35 1 if(P3_7==0)delay(1);
36 1 if(P3_7==0)o_f=1;
37 1 for(m=0;m<30;m++)
38 1 {
39 2 t_dirve();
40 2 P1=DATA_7SEG[t_min/10];P2=0xdf;delay(1);
41 2 if(P2^5==0){if(o_f==1)P1_7=0;}else P1_7=1;
42 2 delay(1);
43 2 }
44 1 if(P3_5==0)delay(1);
45 1 if(P3_5==0) o_f=0;
46 1 for(m=0;m<30;m++)
47 1 {
48 2 t_dirve();
49 2 P1=DATA_7SEG[t_min/10];P3=0xdf;delay(1);
50 2 if(P3_1==0){if(o_f==1)P1_7=0;else P1_7=1;}
51 2 delay(1);
52 2 }
53 1 }
54 //********************************************//
55 //********************************************//
C51 COMPILER V8.08 XIAONAOZHONG 06/29/2008 23:34:51 PAGE 2
56 //********************************************//
57
58 /*走时函数*/
59 void time()
60 {
61 1 conv(); /*走时单元转换*/
62 1 dirve(); /*走时时间输出驱动子函数*/
63 1 p_out(); /*判别闹时到否子函数*/
64 1 }
65 //********************************************//
66 //********************************************//
67 //********************************************//
68 /*定时器T0 5mS初始化*/
69 void init_timer()
70 {
71 1 TMOD=0x01; //定时器T0工作在方式1,为16位计数器
72 1 TH0=0xEC;//16位定时器5ms定时初值
73 1 TL0=0x78; //
74 1 IE=0x82;//开中断总允许位,允许定时器T0
75 1 EA=1;
76 1 TR0=1; //启动定时器T0
77 1 }
78 //********************************************//
79 //********************************************//
80
81 //********************************************//
82 /*扫描按键子函数*/
83 void scan_key()
84 { if(P3_4==0)
85 1 delay(1);
86 1 if(P3_4==0)set++;
87 1 if(set==4)set=0;
88 1 if(set==1)flag==0x55;
*** WARNING C275 IN LINE 88 OF XIAONAOZHONG.C: expression with possibly no effect
89 1 F0:if(P3_4==0)goto F0; /*按键未释放,在此等候*/
90 1 }
91 //********************************************//
92 //********************************************//
93 //********************************************//
94 /*延时子函数*/
95 void delay(uint k)
96 {
97 1 uint i,j;
98 1 for(i=0;i<k;i++)
99 1 for(j=0;j<121;j++)
100 1 {;}
101 1 }
102
103 //********************************************//
104 //********************************************//
105 //********************************************//
106 /*5mS定时中断服务子函数*/
107 void zd(void) interrupt 1
108 {
109 1 TH0=0xEC;
110 1 TL0=0x78;
111 1 deda++;
112 1 }
113 //********************************************//
114 //********************************************//
115 //********************************************//
116 /*调整走时时间*/
C51 COMPILER V8.08 XIAONAOZHONG 06/29/2008 23:34:51 PAGE 3
117 void time_adj()
118 {uchar m;
119 1 if(P3_5==0)delay(1);
120 1 if(P3_5==0)hour++;
121 1 if(hour==24)hour=0;
122 1 for(m=0;m<30;m++)
123 1 {
124 2 dirve();
125 2 if(P2^6==0)P1_7=0;
126 2 else P1_7=1;
127 2 delay(1);
128 2 }
129 1 if(P3_7==0)delay(1);
130 1 if(P3_7==0)min++;
131 1 if(min==60)min=0;
132 1 for(m=0;m<30;m++)
133 1
134 1 {
135 2
136 2 dirve();
137 2 if(P2^6==0)P1_7=0;
138 2 else P1_7=1;
139 2 delay(1);
140 2 }
141 1 }
142 //********************************************//
143 //********************************************//
144 //********************************************//
145
146 /*调整闹时时间*/
147 void time1_adj()
148
149 {uchar m;
150 1 if(P3_5==0)delay(1);
151 1 if(P3_5==0)t_hour++;
152 1 if(t_hour==24)t_hour=0;
153 1 for(m=0;m<30;m++)
154 1 {
155 2 t_dirve();
156 2 }
157 1 if(P3_7==0)delay(1);
158 1 if(P3_7==0)t_min++;
159 1 if(t_min==60)t_min=0;
160 1 for(m=0;m<30;m++)
161 1 {
162 2 t_dirve();
163 2
164 2 }
165 1 }
166 //********************************************//
167 //********************************************//
168 //********************************************//
169 /*时、分、秒单元及走时单元转换*/
170 void conv()
171 {
172 1 if(deda=200){sec++;deda=0;}
*** WARNING C276 IN LINE 172 OF XIAONAOZHONG.C: constant in condition expression
173 1 if(sec==60){min++;sec=0;}
174 1 if(min==60){hour++;min=0;}
175 1 if(hour==24){hour=0;}
176 1 }
177 //********************************************//
C51 COMPILER V8.08 XIAONAOZHONG 06/29/2008 23:34:51 PAGE 4
178 //********************************************//
179 //********************************************//
180 /*走时时间输出驱动子函数*/
181 void dirve()
182 {
183 1 P1=DATA_7SEG[hour/10];P2=0x7f;delay(1);
184 1 P1=DATA_7SEG[hour%10];P2=0xbf;delay(1);
185 1 if(d_05s==1){if(P2^6==0)P1_7=0;else P1_7=1;}
186 1 delay(1);
187 1 P1=DATA_7SEG[min/10];P2=0xfd;delay(1);
188 1 if(o_f==1){if(P2^5==0)P1_7=0;else P1_7=1;delay(1);}
189 1 P1=DATA_7SEG[min%10];P2=0xef;delay(1);
190 1 }
191 //********************************************//
192 //********************************************//
193 /*闹时时间输出驱动子函数*/
194 void t_dirve()
195 {
196 1 P1=DATA_7SEG[t_hour/10];P2=0x7f;delay(1);
197 1 if(P2^7==0)P1_7=0;else P1_7=1;
198 1 delay(1);
199 1 P1=DATA_7SEG[t_hour%10];P2=0xbf;delay(1);
200 1 P1=DATA_7SEG[t_min/10];P2=0xdf;delay(1);
201 1 P1=DATA_7SEG[t_min%10];P2=0xef;delay(1);
202 1 }
203 //********************************************//
204 //********************************************//
205 /*判别闹时到否子函数*/
206 void p_out()
207 {
208 1 if(o_f==1)
209 1 {
210 2 if(t_hour==hour)
211 2 {if(t_min==min)
212 3 if(P2^4==0){P1_7=0;delay(1);}
213 3 else P1_7=1;
214 3 }
215 2 }
216 1 }
217 //********************************************//
218 //********************************************//
219 /*主函数*/
220 void main()
221 {
222 1 init_timer(); /*定时器T0初始化*/
223 1 while(1) /*无限循环*/
224 1 {
225 2 if(P3^4==0)
226 2 scan_key(); /*有按键,调用按键扫描子函数*/
227 2 switch(set) /*根据set键值散转*/
228 2 {
229 3 case 0:time();break; /*走时时间程序*/
230 3 case 1:time1_adj();break; /*闹时时间调整*/
231 3 case 2:time_adj();break; /*走时时间调整*/
232 3 case 3:time1_of();break; /*启/停闹时*/
233 3 default:break; /*其它退出*/
234 3 }
235 2 if(flag!=0x55) /*判断掉电标志*/
236 2 {for(m=0;m<100;m++) /*点亮四个8字400mS*/
237 3 {
238 4 P1=0x80;P2=0x7f;delay(1);
239 4 P1=0x80;P2=0xbf;delay(1);
C51 COMPILER V8.08 XIAONAOZHONG 06/29/2008 23:34:51 PAGE 5
240 4 P1=0x80;P2=0xdf;delay(1);
241 4 P1=0x80;P2=0xef;delay(1);
242 4 }
243 3 P1=0xff;P3=0xff;delay(400); /*熄灭四个8字400mS*/
244 3 }
245 2 }
246 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 741 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 26 3
IDATA SIZE = ---- ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -