📄 timer.lst
字号:
C51 COMPILER V7.06 TIMER 05/07/2009 08:52:36 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TIMER
OBJECT MODULE PLACED IN Timer.OBJ
COMPILER INVOKED BY: E:\k51\C51\BIN\C51.EXE Timer.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /**********************************************
2 * File: Timer.C
3 * Description: Timer Function
4 * Created Date: 2007-10-01
5 * Last Modified: 2007-10-01
6 * Author: Jeffrey - Schicksal@126.com
7 * Notes: None
8 **********************************************/
9 #include "Atmel/AT89X51.h"
10 #include "INTRINS.H"
11 #include "timer.h"
12 #include "MAX7219.h"
13 #include "DS1620.h"
14 #include "keys.h"
15
16 #define TH0_VALUE 0x06
17 #define TL0_VALUE 0x00
18
19 unsigned int timer_tick;
20 unsigned int timer_tick_500ms;
21
22 /**********************************************
23 * Function: TIMER_Init
24 * Input Variables: None
25 * Return Variables: None
26 * Usage: T0 Initialization
27 *********************************************/
28 void TIMER_Init(void)
29 {
30 1
31 1 ET0 = 0; // 关闭T0的中断
32 1 TMOD = 0x00; // T0工作在模式0
33 1 TCON = 0x00; // 暂时未启动T0
34 1 TL0 = TL0_VALUE;
35 1 TH0 = TH0_VALUE; // 产生2ms中断 |24 MHz 晶振
36 1 ET0 = 1; // 打开T2的中断
37 1
38 1 timer_tick = 0;
39 1 timer_tick_500ms = 0;
40 1 }
41
42 /**********************************************
43 * Function: timer0_interrupt
44 * Input Variables: None
45 * Return Variables: None
46 * Usage: TIMER_Interrupt Service Routine
47 *********************************************/
48 void timer0_interrupt(void) interrupt 5 using 1
49 {
50 1 EA = 0; // 关全局中断
51 1 TF0 = 0; // 清中断标志
52 1
53 1 timer_tick++; // 2ms
54 1
55 1 if ( timer_tick == 250 ) // 1s = 2ms X 500
C51 COMPILER V7.06 TIMER 05/07/2009 08:52:36 PAGE 2
56 1 {
57 2 timer_tick_500ms += 1; // 秒计数增1
58 2 timer_tick = 0; // 2ms计数清零
59 2 }
60 1
61 1 TL0 = TL0_VALUE; // T0初值装载
62 1 TH0 = TH0_VALUE; // 产生2ms中断 |24 MHz 晶振
63 1 EA = 1; // 开中断
64 1 }
65
66 /**********************************************
67 * Function: TIMER_Start
68 * Input Variables: None
69 * Return Variables: None
70 * Usage: Start T0
71 *********************************************/
72 void TIMER_Start()
73 {
74 1 TR0 = 1; // 启动T0
75 1 }
76
77
78 volatile unsigned char time[4]={12,0,0,0};
79 volatile unsigned char alarm[2]={7,0};
80
81 extern volatile unsigned char flag;
82 extern volatile unsigned char alarm_flag;
83 extern volatile unsigned char change_timeflag;
84 extern volatile unsigned char change_adjustflag;
85
86 /**********************************************
87 *Function: void Display_Time()
88 * Input Variables: None
89 * Return Variables: None
90 * Usage: Display Time
91 *********************************************/
92 void Display_Time()
93 {
94 1 unsigned char data_dp[6] ;
95 1 unsigned char i;
96 1 if(timer_tick_500ms>0)
97 1 {
98 2
99 2 time[3]++;
100 2
101 2 if (time[1]==0xff)
102 2 {
103 3 time[1]=59;
104 3 }
105 2
106 2 if (time[0]==0xff)
107 2 {
108 3 time[0]=23;
109 3 }
110 2
111 2 if (time[3]>1)
112 2 {
113 3 time[3]=0;
114 3 time[2]++;
115 3 }
116 2
117 2 if (time[2]>=60)
C51 COMPILER V7.06 TIMER 05/07/2009 08:52:36 PAGE 3
118 2 {
119 3 time[2]-=60;
120 3 time[1]++;
121 3 }
122 2 if (time[1]>=60)
123 2 {
124 3 time[1]-=60;
125 3 time[0]++;
126 3 }
127 2 if (time[0]>=24)
128 2 time[0]-=24;
129 2
130 2 if (change_adjustflag==0) // 显示时钟
131 2 {
132 3 for (i=0;i<4;i+=2)
133 3 {
134 4 data_dp[i]=time[i/2]/10;
135 4 data_dp[i+1]=time[i/2]%10;
136 4 }
137 3 data_dp[2]=data_dp[2]|(1<<7);
138 3 data_dp[3]=data_dp[3]|(1<<7);
139 3 if (change_timeflag==0)
140 3 {
141 4 if (time[2]%2==1)
142 4 {
143 5 data_dp[2]=data_dp[2]-0x80;
144 5 data_dp[3]=data_dp[3]-0x80;
145 5 }
146 4 }
147 3 else
148 3 {
149 4 if (change_timeflag==1)
150 4 {
151 5 // 正在修改小时
152 5 if (time[3]==0)
153 5 {
154 6 data_dp[0]=0x0f;
155 6 data_dp[1]=0x0f;
156 6 }
157 5 }
158 4 else
159 4 {
160 5 // 正在修改分钟
161 5 if (time[3]==0)
162 5 {
163 6 data_dp[2]=0x8f;
164 6 data_dp[3]=0x8f;
165 6 }
166 5 }
167 4 }
168 3 }
169 2 else // 修改闹表
170 2 {
171 3 if (alarm_flag==0) // 没有闹表
172 3 {
173 4 for (i=0;i<4;i++)
174 4 data_dp[i]=0x0a;
175 4 if (time[2]%2==0)
176 4 {
177 5 data_dp[2]=data_dp[2]|(1<<7);
178 5 data_dp[3]=data_dp[3]|(1<<7);
179 5 }
C51 COMPILER V7.06 TIMER 05/07/2009 08:52:36 PAGE 4
180 4 }
181 3 else // 有闹表
182 3 {
183 4 for (i=0;i<4;i+=2)
184 4 {
185 5 data_dp[i]=alarm[i/2]/10;
186 5 data_dp[i+1]=alarm[i/2]%10;
187 5 }
188 4 data_dp[2]=data_dp[2]|(1<<7);
189 4 data_dp[3]=data_dp[3]|(1<<7);
190 4 if (change_timeflag==0)
191 4 {
192 5 if (time[2]%2==1)
193 5 {
194 6 data_dp[2]=data_dp[2]-0x80;
195 6 data_dp[3]=data_dp[3]-0x80;
196 6 }
197 5 }
198 4 else
199 4 {
200 5 if (change_timeflag==1)
201 5 {
202 6 // 正在修改小时
203 6 if (time[3]==0)
204 6 {
205 7 data_dp[0]=0x0f;
206 7 data_dp[1]=0x0f;
207 7 }
208 6 }
209 5 else
210 5 {
211 6 // 正在修改分钟
212 6 if (time[3]==0)
213 6 {
214 7 data_dp[2]=0x8f;
215 7 data_dp[3]=0x8f;
216 7 }
217 6 }
218 5 }
219 4 }
220 3 }
221 2 for (i=0;i<4;i++)
222 2 write_7219(i+1,data_dp[i]);
223 2
224 2 timer_tick_500ms=0; // 清500ms计数
225 2 }
226 1 }
227
228
229 /**********************************************
230 *Function: void Check_Alarm()
231 * Input Variables: None
232 * Return Variables: None
233 * Usage: Display Time
234 *********************************************/
235 void Check_Alarm()
236 {
237 1 if ((time[0]==alarm[0]) && (time[1]==alarm[1]) && (alarm_flag==1) && (change_adjustflag==0))
238 1 {
239 2 SetBuzzer(0x00); // 闹铃响
240 2 }
241 1 }
C51 COMPILER V7.06 TIMER 05/07/2009 08:52:36 PAGE 5
242
243
244
245
246
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 457 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 7
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 + -