📄 timer_soft.lst
字号:
C51 COMPILER V7.06 TIMER_SOFT 01/29/2008 10:59:25 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE TIMER_SOFT
OBJECT MODULE PLACED IN timer_soft.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE modules\timer_soft\timer_soft.c LARGE OPTIMIZE(9,SPEED) INCDIR(.\;.\;.\) DE
-FINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\timer_soft.lst) OBJECT(timer_soft.obj)
stmt level source
1 /*C**************************************************************************
2 * NAME: timer_soft.c
3 *----------------------------------------------------------------------------
4 * Copyright (c) 2003 Atmel.
5 *----------------------------------------------------------------------------
6 * RELEASE: c5131-usb-kbd-light-1_0_2
7 * REVISION: 1.8
8 *----------------------------------------------------------------------------
9 * PURPOSE:
10 * This file controls the temporizations of the application.
11 * The tempo value is a define symbol in c51_time.h file.
12 * The oscillator value is a parameter in c51_time.h file.
13 *****************************************************************************/
14
15 /*_____ I N C L U D E S ____________________________________________________*/
16 #include "config.h"
17 #include "timer_soft.h"
18
19 /*_____ M A C R O S ________________________________________________________*/
20
21
22 /*_____ D E F I N I T I O N S ______________________________________________*/
23 /*V**************************************************************************
24 * NAME: gl_soft_timer_tick
25 *----------------------------------------------------------------------------
26 * PURPOSE:
27 * Number of ms since mcu reset.
28 * This variable is used by soft timers, it must be updated periodically (usually
29 * by timer interrupt routine).
30 *****************************************************************************/
31 volatile Uint32 data gl_soft_timer_tick;
32
33 /*_____ D E C L A R A T I O N S ____________________________________________*/
34
35 /*F**************************************************************************
36 * NAME: tempo
37 *----------------------------------------------------------------------------
38 * PARAMS:
39 * delay: tempo value in ms
40 * return: none
41 *----------------------------------------------------------------------------
42 * PURPOSE:
43 * This function manages the temporization.
44 *----------------------------------------------------------------------------
45 * EXAMPLE:
46 * tempo(TIMER_1_S); // Wait 1 sec.
47 *----------------------------------------------------------------------------
48 * NOTE:
49 *----------------------------------------------------------------------------
50 * REQUIREMENTS:
51 *****************************************************************************/
52 void tempo(Uint16 delay)
53 {
54 1 register Timer16s timer;
C51 COMPILER V7.06 TIMER_SOFT 01/29/2008 10:59:25 PAGE 2
55 1
56 1 timer=set_timer16s(delay);
57 1 while (!std_timeout16s(timer));
58 1 }
59
60
61 #ifndef I_HAVE_SETUP_SOFT_TIMER_TICK
62 Uint16 gl_reminder_inc_ms;
63
64 #ifdef SOFT_TIMER_CUSTOM_FOSC
65 Uint16 REMINDER_INC_MS;
66
67 /*F**************************************************************************
68 * NAME: reload_TH0
69 *----------------------------------------------------------------------------
70 * PARAMS:
71 * return: value to load on TH0
72 *----------------------------------------------------------------------------
73 * PURPOSE:
74 * This function calculate the value to load in TH0 when FOSC is custom (FOSC
75 * is not a precomputed value).
76 * This function update REMINDER_INC_MS to keep accuracy of timers.
77 *----------------------------------------------------------------------------
78 * EXAMPLE:
79 *----------------------------------------------------------------------------
80 * NOTE:
81 *----------------------------------------------------------------------------
82 * REQUIREMENTS:
83 *****************************************************************************/
84 Byte reload_TH0(void)
85 {
86 1 Byte b;
87 1 Byte n;
88 1
89 1 REMINDER_INC_MS=((Uint16)FOSC/(Uint16)12*(Uint16)INC_MS);
90 1 b=(REMINDER_INC_MS>>8);
91 1 if (b&128) b=0;
92 1 else if (b&64) b=128;
93 1 else if (b&32) b=192;
94 1 else if (b&16) b=224;
95 1 else if (b&8) b=240;
96 1 else if (b&4) b=248;
97 1 else if (b&2) b=252;
98 1 else if (b&1) b=254;
99 1 else b=255;
100 1 REMINDER_INC_MS=((Uint16)b<<8)-REMINDER_INC_MS;
101 1 // Do REMINDER_INC_MS*12*65536/FOSC with the maximum accuracy<=>REMINDER_INC_MS*3*2^18/FOSC
102 1 for (n=0;n<18;n++)
103 1 {
104 2 if (REMINDER_INC_MS&32768)
105 2 {
106 3 REMINDER_INC_MS/=FOSC;
107 3 REMINDER_INC_MS*=3;
108 3 }
109 2 else REMINDER_INC_MS<<=1;
110 2 }
111 1 return b;
112 1 }
113 #endif
114
115
116 /*F**************************************************************************
C51 COMPILER V7.06 TIMER_SOFT 01/29/2008 10:59:25 PAGE 3
117 * NAME: init_soft_timers
118 *----------------------------------------------------------------------------
119 * PARAMS:
120 * return: none
121 *----------------------------------------------------------------------------
122 * PURPOSE:
123 * This function initialise the soft timer library.
124 *----------------------------------------------------------------------------
125 * EXAMPLE:
126 * init_soft_timer();
127 *----------------------------------------------------------------------------
128 * NOTE:
129 *----------------------------------------------------------------------------
130 * REQUIREMENTS:
131 *****************************************************************************/
132 void init_soft_timers (void)
133 {
134 1 gl_soft_timer_tick=0;
135 1 gl_reminder_inc_ms=0;
136 1 TL0 = 0;
137 1 TH0 = RELOAD_TH0;
138 1 TMOD |= 0x01; // timer0 is mode1 : 16 bits
139 1 Set_timer0_x1_mode(); // timer0 always in x1 mode, even if x2 mode is set for std clk.
140 1 TR0=1;
141 1 Enable_interrupt(); //Enable global interrupt
142 1 ET0=1;
143 1 }
144
145
146 /*F**************************************************************************
147 * NAME: Timer0_interrupt
148 *----------------------------------------------------------------------------
149 * PARAMS:
150 * return: none
151 *----------------------------------------------------------------------------
152 * PURPOSE:
153 * This function is the interrupt program for the timer 0.
154 *----------------------------------------------------------------------------
155 * EXAMPLE:
156 *----------------------------------------------------------------------------
157 * NOTE:
158 *----------------------------------------------------------------------------
159 * REQUIREMENTS:
160 *****************************************************************************/
161 Interrupt (void Timer0_interrupt(void),IRQ_T0)
162 {
163 1 // TIMER0_OVF, interrupt cleared by hardware
164 1 TH0|=RELOAD_TH0; // Update Physical Clock ( logical OR to keep accuracy after long IT )
165 1 // Update gl_soft_timer_tick : number of ms till Reset, REMINDER_INC_MS to keep accuracy
166 1 gl_soft_timer_tick+=(((gl_reminder_inc_ms+=REMINDER_INC_MS)<REMINDER_INC_MS)?INC_MS+1:INC_MS);
167 1 }
168 #endif
169
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 362 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 4 ----
PDATA SIZE = ---- ----
DATA SIZE = 4 ----
IDATA SIZE = ---- ----
C51 COMPILER V7.06 TIMER_SOFT 01/29/2008 10:59:25 PAGE 4
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 + -