?? text1.lst
字號:
C51 COMPILER V8.02 TEXT1 09/12/2006 00:20:29 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE TEXT1
OBJECT MODULE PLACED IN Text1.OBJ
COMPILER INVOKED BY: E:\Keil8\C51\BIN\C51.EXE Text1.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<AT89X51.h>
2 unsigned char code dispcode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40};//共陰極
3 unsigned char dispbitcode[]={0x00,0x21,0x42,0x63,0x84,0xA5,0xC6,0xE7};//管子的選擇
4 unsigned char dispbuf[8]={0,0,10,0,0,10,2,1}; //16為顯示間斷號符
5 unsigned char dispbym[8]={1,2,7,0,6,0,0,2};
6 unsigned char dispbitcnt;
7 unsigned char second;
8 unsigned char minite;
9 unsigned char hour;
10 unsigned char day;
11 unsigned char month;
12 unsigned char yearh;
13 unsigned char yearl;
14 unsigned int tcnt;
15 unsigned char mstcnt;
16 unsigned char i,j;
17 void main(void)
18 {
19 1 TMOD=0x02; //設置模式為定時器T0的模式2 (8位自動重裝計數初值的計數值)
20 1 TH0=0x06; //設置計數器初值,靠TH0存儲重裝的計數值X0=256-250=6
21 1 TL0=0x06;
22 1 TR0=1; //啟動T0
23 1 ET0=1; //開啟定時器T0中斷允許
24 1 EA=1; //開啟中斷總控制
25 1 yearh=20;
26 1 yearl=6;
27 1 month=7;
28 1 day=21;
29 1 hour=12; //初始值為12:00:00
30 1 while(1)
31 1 {
32 2 if(P0_0==0) //掃描秒鐘按鈕
33 2 {
34 3 for(i=5;i>0;i--) //按鈕抖動消除
35 3 for(j=248;j>0;j--); //計時
36 3 if(P0_0==0)
37 3 {
38 4 second++;
39 4 if(second==60)
40 4 {
41 5 second=0;
42 5 }
43 4 dispbuf[0]=second%10;
44 4 dispbuf[1]=second/10;
45 4 while(P0_0==0);
46 4 }
47 3 }
48 2
49 2 if(P0_1==0) //掃描分鐘按鈕
50 2 {
51 3 for(i=5;i>0;i--)
52 3 for(j=248;j>0;j--);
53 3 if(P0_1==0)
54 3 {
55 4 minite++;
C51 COMPILER V8.02 TEXT1 09/12/2006 00:20:29 PAGE 2
56 4 if(minite==60)
57 4 {
58 5 minite=0;
59 5 }
60 4 dispbuf[3]=minite%10;
61 4 dispbuf[4]=minite/10;
62 4 while(P0_1==0);
63 4 }
64 3 }
65 2
66 2 if(P0_2==0) //掃描時鐘按鈕
67 2 {
68 3 for(i=5;i>0;i--)
69 3 for(j=248;j>0;j--);
70 3 if(P0_2==0)
71 3 {
72 4 hour++;
73 4 if(hour==24)
74 4 {
75 5 hour=0;
76 5 }
77 4 dispbuf[6]=hour%10;
78 4 dispbuf[7]=hour/10;
79 4 while(P0_2==0);
80 4 }
81 3 }
82 2
83 2 if(P0_3==0)
84 2 {
85 3 for(i=5;i>0;i--)
86 3 for(j=248;j>0;j--);
87 3 if(P0_3==0)
88 3 {
89 4 day++;
90 4 if(month==2&&((yearl==0&&yearh%4==0)||(yearl!=0&&yearl%4==0))&&day==30)day=1;
91 4 else if(month==2&&day==29)day=1;
92 4 else if((month==4||month==6||month==9||month==11)&&day==31)day=1;
93 4 else if(day==32)day=1;
94 4 dispbym[0]=day%10;
95 4 dispbym[1]=day/10;
96 4 while(P0_3==0);
97 4 }
98 3 }
99 2
100 2 if(P0_4==0)
101 2 {
102 3 for(i=5;i>0;i--)
103 3 for(j=248;j>0;j--);
104 3 if(P0_4==0)
105 3 {
106 4 month++;
107 4 if(month==13)month=1;
108 4 dispbym[2]=month%10;
109 4 dispbym[3]=month/10;
110 4 while(P0_4==0);
111 4 }
112 3 }
113 2
114 2 if(P0_5==0)
115 2 {
116 3 for(i=5;i>0;i--)
117 3 for(j=248;j>0;j--);
C51 COMPILER V8.02 TEXT1 09/12/2006 00:20:29 PAGE 3
118 3 if(P0_5==0)
119 3 {
120 4 yearl++;
121 4 if(yearl==100)
122 4 {
123 5 yearl=0;
124 5 yearh++;
125 5 if(yearh==100)yearh=20;
126 5 }
127 4 dispbym[4]=yearl%10;
128 4 dispbym[5]=yearl/10;
129 4 dispbym[6]=yearh%10;
130 4 dispbym[7]=yearh/10;
131 4 while(P0_5==0);
132 4 }
133 3 }
134 2
135 2 }
136 1 }
137
138 void t0(void)interrupt 1 using 0 //t0的中斷程序
139 {
140 1 mstcnt++;
141 1 if(mstcnt==8) //8次250us為2ms,即每隔2ms掃描一個數碼管
142 1 {
143 2 mstcnt=0;
144 2 P1=dispcode[dispbuf[dispbitcnt]];
145 2 P2=dispcode[dispbym[dispbitcnt]];
146 2 P3=0xff;
147 2 P3=dispbitcode[dispbitcnt]; //管子的選擇
148 2 dispbitcnt++;
149 2 if(dispbitcnt==8)
150 2 {
151 3 dispbitcnt=0;
152 3 }
153 2 }
154 1 tcnt++;
155 1 if(tcnt==4000) //定時器的定時計數,4000次250us為1秒
156 1 {
157 2 tcnt=0;
158 2 second++;
159 2 if(second==60) //從秒到時層層嵌套,程序較為精練
160 2 {
161 3 second=0;
162 3 minite++;
163 3 if(minite==60)
164 3 {
165 4 minite=0;
166 4 hour++;
167 4 if(hour==24)
168 4 {
169 5 hour=0;
170 5 day++;
171 5 if(month==2&&((yearl==0&&yearh%4==0)||(yearl!=0&&yearl%4==0))&&day==30)day=1;
172 5 else if(month==2&&day==29)day=1;
173 5 else if((month==4||month==6||month==9||month==11)&&day==31)day=1;
174 5 else if(day==32)day=1;
175 5 if(day==1)
176 5 {
177 6 month++;
178 6 if(month==13)
179 6 {
C51 COMPILER V8.02 TEXT1 09/12/2006 00:20:29 PAGE 4
180 7 month=1;
181 7 yearl++;
182 7 if(yearl==100)
183 7 {
184 8 yearl=0;
185 8 yearh++;
186 8 if(yearh==100)
187 8 {
188 9 yearh=20;
189 9 }
190 8 }
191 7 }
192 6 }
193 5 }
194 4 }
195 3 }
196 2 dispbuf[0]=second%10; //送顯示數據
197 2 dispbuf[1]=second/10;
198 2
199 2 dispbuf[3]=minite%10;
200 2 dispbuf[4]=minite/10;
201 2
202 2 dispbuf[6]=hour%10;
203 2 dispbuf[7]=hour/10;
204 2
205 2 dispbym[0]=day%10;
206 2 dispbym[1]=day/10;
207 2
208 2 dispbym[2]=month%10;
209 2 dispbym[3]=month/10;
210 2
211 2 dispbym[4]=yearl%10;
212 2 dispbym[5]=yearl/10;
213 2
214 2 dispbym[6]=yearh%10;
215 2 dispbym[7]=yearh/10;
216 2 }
217 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 803 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 37 ----
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 + -