📄 upsd_timer.lst
字号:
C51 COMPILER V7.00 UPSD_TIMER 02/10/2003 10:48:04 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE UPSD_TIMER
OBJECT MODULE PLACED IN upsd_timer.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE upsd_timer.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------------------
2 uPSD_TIMER.C
3
4 uPSD Timer0 Device Driver Functions
5 06/2002 Ver 0.1 - Initial Version
6 08/2002 Ver 0.2 - Timer 0 reload calcualted from FREQ_OSC define
7
8 Note: Some functions have been commented out so as to remove linker warnings
9 for code segments that are not used.
10
11
12 Copyright 2002 STMicroelectrons Inc.
13
14 This example demo code is provided as is and has no warranty,
15 implied or otherwise. You are free to use/modify any of the provided
16 code at your own risk in your applications with the expressed limitation
17 of liability (see below) so long as your product using the code contains
18 at least one uPSD products (device).
19
20 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
21 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
22 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
23 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
24 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
25 ------------------------------------------------------------------------------*/
26
27 #pragma optimize(8,size)
28 #include "upsd3200.h"
29 #include "upsd_timer.h"
30 #include "upsd_hardware.h"
31
32 /*------------------------------------------------------------------------------
33 Local Variable Declarations
34 ------------------------------------------------------------------------------*/
35 static unsigned int idata timer0_tick;
36 unsigned int timer0_value;
37
38 /*------------------------------------------------------------------------------
39 static void timer0_isr (void);
40
41 This function is an interrupt service routine for TIMER 0. It should never
42 be called by a C or assembly function. It will be executed automatically
43 when TIMER 0 overflows.
44 ------------------------------------------------------------------------------*/
45 static void timer0_isr (void) interrupt 1 using 1
46 {
47 1 /*------------------------------------------------
48 1 Stop timer, adjust the timer 0 counter so that we get another
49 1 interrupt in 10ms, and restart the timer.
50 1 ------------------------------------------------*/
51 1 TR0 = 0; /* stop timer 0 */
52 1
53 1 TL0 = (timer0_value & 0x00FF);
54 1 TH0 = (timer0_value >> 8);
55 1
C51 COMPILER V7.00 UPSD_TIMER 02/10/2003 10:48:04 PAGE 2
56 1 TR0 = 1; /* start timer 0 */
57 1
58 1 timer0_tick++; // Increment global var timer_tick (number of 10ms ticks)
59 1 }
60
61 /*------------------------------------------------------------------------------
62 void timer0_init(void);
63
64 This function enables TIMER 0. TIMER 0 will generate a synchronous interrupt
65 once every 100Hz.
66 ------------------------------------------------------------------------------*/
67 void timer0_init (void)
68 {
69 1 EA = 0; /* disable interrupts */
70 1
71 1 timer0_tick = 0;
72 1
73 1 TR0 = 0; /* stop timer 0 */
74 1
75 1 TMOD &= 0xF0; /* clear timer 0 mode bits - bottom 4 bits */
76 1 TMOD |= 0x01; /* put timer 0 into 16-bit no prescale */
77 1
78 1 // Calculate timer tollover based on FREQ_OSC to be 10ms periods (100hz)
79 1 timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);
80 1
81 1 TL0 = (timer0_value & 0x00FF);
82 1 TH0 = (timer0_value >> 8);
83 1
84 1 PT0 = 1; /* set high priority for timer 0 */
85 1 ET0 = 1; /* enable timer 0 interrupt */
86 1
87 1 TR0 = 1; /* start timer 0 */
88 1
89 1 EA = 1; /* enable interrupts */
90 1 }
91
92
93 /*------------------------------------------------------------------------------
94 unsigned int timer0_count (void);
95
96 This function returns the current timer0 tick count.
97 ------------------------------------------------------------------------------*/
98 unsigned int timer0_count (void)
99 {
100 1 unsigned int t;
101 1
102 1 EA = 0; // disable ints so we cna read steady value
103 1 t = timer0_tick;
104 1 EA = 1; // enable
105 1 return(t);
106 1 }
107
108
109 /*------------------------------------------------------------------------------
110 void timer0_delay (
111 unsigned count);
112
113 This function waits for 'count' timer ticks to pass.
114 ------------------------------------------------------------------------------*/
115 void timer0_delay (unsigned int count)
116 {
117 1 unsigned int start_count;
C51 COMPILER V7.00 UPSD_TIMER 02/10/2003 10:48:04 PAGE 3
118 1
119 1 start_count = timer0_count(); /* get the start count */
120 1
121 1 while ((timer0_count() - start_count) <= count) /* wait for count "ticks" */
122 1 {
123 2 }
124 1 }
125
126
127 void delay_10ms()
128 {
129 1 timer0_delay(1);
130 1 }
131
132 void delay_1sec(void)
133 {
134 1 timer0_delay(100);
135 1 }
136
137 void delay_2sec(void)
138 {
139 1 delay_1sec();
140 1 delay_1sec();
141 1 }
142 /*
143 void delay_10sec(void)
144 {
145 delay_2sec();
146 delay_2sec();
147 delay_2sec();
148 delay_2sec();
149 delay_2sec();
150 }
151
152 void delay_0_5sec(void)
153 {
154 timer0_delay(50);
155 }
156
157 void delay_0_1sec(void)
158 {
159 timer0_delay(10);
160 }
161 */
162
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 132 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 ----
IDATA SIZE = 2 ----
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 + -