📄 timer.lst
字号:
C51 COMPILER V7.50 TIMER 05/22/2007 20:05:12 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE TIMER
OBJECT MODULE PLACED IN .\timer.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\SourceFile\timer.c BROWSE DEBUG OBJECTEXTEND PRINT(.\timer.lst) OBJECT(.
-\timer.obj)
line level source
1
2 /***************************************************************************************
3 ****************************************************************************************
4 * FILE : timer.c
5 * Description : timer and MSTimer
6 *
7 * Copyright (c) 2003~2007 by WANG SHAOWEI. All Rights Reserved.
8 *
9 * History:
10 * Version Name Date Description
11 1.0 Wang Shaowei 2003/07/16 Initial Version (MCU System)
12 2.0 Wang Shaowei 2005/06/01 MS2
13 3.0 Wang Shaowei 2007/03/11 MS3
14
15 ****************************************************************************************
16 ****************************************************************************************/
17
18
19 /*
20 寄存器说明:
21 1 TCON:中断标志寄存器
22 TF1(8F) T1中断标志位
23 TR1(8E) T1启停位
24 TF0(8D) T0中断标志位
25 TR0(8C) T0启停位
26 2 TMOD:定时器方式寄存器
27 GATE | C/~T | M1,M0 |GATE | C/~T | M1,M0 |
28 \______________________________/ 0 ~INT0 0 定时器 0 , 0 -----方式0
29 T1 无关 1 计数器 0 , 1 -----方式1
30 对应 1 ~INT0 模式 1 , 0 -----方式2
31 INT1 有关 1 , 1 -----方式3
32
33
34 3 工作方式:
35 方式0:13位计数器TL的搞三位不用
36 方式1:16位计数器
37 方式2:可循环8位计数器,适用于UART
38 方式3:T0与T1不同
39 定时器1 只能按不需要中断的方式2工作
40 此模式下定时器0 的TL0 及TH0 作为两个独立的8 位计数器/定时器
41 TL0 占用定时器0 的TF0 TH0
42 TL1 占用定时器1 的TR1和TF1
43
44 */
45
46
47 #include "common.h"
48
49
50
51
52
53
54 typedef struct
C51 COMPILER V7.50 TIMER 05/22/2007 20:05:12 PAGE 2
55 {
56 U16 delay;
57 Function pCallBack;
58 }MSTIMER_T;
59
60
61 static U8 data MSTimerID = 0;
62 static U8 idata MSTimerMode = 0;
63 static MSTIMER_T idata MSTimerArray[MSTIMER_NUMBER];
64
65
66
67
68
69
70 /*==================================================================
71 * Function : MSTimerService
72 * Description : MSTimer service, will be called in Timer2InterruptService
73 * Input Para : void
74 * Output Para : void
75 * Return Value: void
76 ==================================================================*/
77 void MSTimerService(void)
78 {
79 1
80 1 U8 i = 0;
81 1 U8 MSTimerID_Map;
82 1 MSTimerID_Map = MSTimerID;
83 1
84 1 while(MSTimerID_Map)
85 1 {
86 2 if((MSTimerID_Map & 0x01) == 1)
87 2 {
88 3 if(!(--MSTimerArray[i].delay))
89 3 {
90 4 if(GETBIT(MSTimerMode, i))
91 4 {
92 5 MSG_SEND_MSG(MSG_MSTIMER, i);
93 5 MSG_SEND_DATA((U16)(MSTimerArray[i].pCallBack));
94 5 }
95 4 else
96 4 {
97 5 (*(MSTimerArray[i].pCallBack))();
98 5 }
99 4 RESETBIT(MSTimerID, i);
100 4 }
101 3 }
102 2
103 2 MSTimerID_Map = MSTimerID_Map >> 1;
104 2 i++;
105 2 }
106 1 }
107
108
109 /*==================================================================
110 * Function : timer_mstimer_start
111 * Description : start a virtual timer base on system timer
112 make sure there is enough timer, that is MSTIMER_MAX is big enough
113 * Input Para : U1 Mode : 0: pCallBack will be executed in interrupt
114 1: pCallBack will be executed in message handling
115 U16 Delay : delay time, in the unit of system timer (normally it is 20ms).
116 so the max delay time is 65535 * 20 ms
C51 COMPILER V7.50 TIMER 05/22/2007 20:05:12 PAGE 3
117 MSTimerCallbackFunc pCallBack : callback function when MSTimer arrives
118 * Output Para : void
119 * Return Value: U8 : return ID,if have no ID ,return 0xFF.
120 ==================================================================*/
121 U8 MSTimerStart(MSTimerHandelMode Mode, U16 Delay, Function pCallBack)
122 {
123 1 U8 i;
124 1
125 1 for(i = 0; i < MSTIMER_NUMBER; i++)
126 1 {
127 2
128 2 if(!GETBIT(MSTimerID, i))
129 2 {
130 3 MSTimerArray[i].delay = Delay;
131 3 MSTimerArray[i].pCallBack = pCallBack;
132 3 if(Mode)
133 3 {
134 4 SETBIT(MSTimerMode, i);
135 4 }
136 3 else
137 3 {
138 4 RESETBIT(MSTimerMode, i);
139 4 }
140 3
141 3 SETBIT(MSTimerID, i);
142 3
143 3 return(i);
144 3 }
145 2 }
146 1
147 1 ERRprintf("MSStartTimer\n");
148 1 return 0xFF;
149 1 }
150
151
152 /*==================================================================
153 * Function : MSTimerStop
154 * Description : stop MSTimer
155 * Input Para : U8 Id : timer ID, should be less than MSTIMER_MAX
156 * Output Para : void
157 * Return Value: void
158 ==================================================================*/
159 void MSTimerStop(U8 Id)
160 {
161 1 if(Id < MSTIMER_NUMBER)
162 1 {
163 2 RESETBIT(MSTimerID, Id);
164 2 }
165 1 else
166 1 {
167 2 ERRprintf("timer_mstimer_stop\n");
168 2 }
169 1 }
170
171
172 #if 0
/*==================================================================
* Function : timer0_process
* Description :
* Input Para :
* Output Para :
* Return Value:
C51 COMPILER V7.50 TIMER 05/22/2007 20:05:12 PAGE 4
==================================================================*/
void timer0_process(void)
{
}
#endif
185
186
187 #if 0
/*==================================================================
* Function : timer1_process
* Description :
* Input Para :
* Output Para :
* Return Value:
==================================================================*/
void timer1_process(void)
{
}
#endif
200
201
202 /*==================================================================
203 * Function : timer2_process
204 * Description :
205 * Input Para :
206 * Output Para :
207 * Return Value:
208 ==================================================================*/
209 void timer2_process(void)
210 {
211 1 if(MSTimerID > 0)
212 1 {
213 2 MSTimerService();
214 2 }
215 1
216 1 routine_process(); /*运行例行任务程序*/
217 1 }
218
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 318 ----
CONSTANT SIZE = 46 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 7
IDATA SIZE = 21 ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -