STC15W408AS library
0.9.0
include
timer0_mode1.h
Go to the documentation of this file.
1
#ifndef STC15_TIMER0_MODE1H
2
#define STC15_TIMER0_MODE1H
3
27
#include <
sys.h
>
28
#include <bits.h>
29
#include <
interrupt.h
>
30
31
#include <stdint.h>
32
#include <stdbool.h>
33
34
#include <timer_structs.h>
35
41
#define INT0 P32
42
47
52
#define timer0_mode1_12T_init() \
53
{ \
54
enable_mcu_interrupts(); \
55
enable_timer0_interrupt(); \
56
TMOD &= 0xf0; \
57
bit_set(TMOD, SBIT0); \
58
bit_clr(AUXR, CBIT7); \
59
}
60
66
#define timer0_mode1_1T_init() \
67
{ \
68
enable_mcu_interrupts(); \
69
enable_timer0_interrupt(); \
70
TMOD &= 0xf0; \
71
bit_set(TMOD, SBIT0); \
72
bit_set(AUXR, SBIT7); \
73
}
75
80
86
#define timer0_mode1_close_gate() (bit_set(TMOD, SBIT3))
87
94
#define timer0_mode1_open_gate() (bit_clr(TMOD, CBIT3))
95
103
#define is_timer0_mode1_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
104
106
111
127
#define timer0_mode1_start(ticks) \
128
{ \
129
uint16_t value = 0xffff - ticks; \
130
/* Load timer high and low bytes value */
\
131
TL0 = value & 0xff; \
132
TH0 = (value >> 8) & 0xff; \
133
\
134
TF0 = 0;
/* clear timer overload flag */
\
135
TR0 = 1;
/* set run timer flag */
\
136
}
137
156
#define timer0_mode1_direct_start(th0, tl0) \
157
{ \
158
TH0 = th0; \
159
TL0 - tl0; \
160
\
161
TF0 = 0; \
162
TR0 = 1; \
163
}
164
173
#define timer0_mode1_stop() \
174
{ \
175
TR0 = 0;
/* clear run timer flag */
\
176
TF0 = 0;
/* clear timer overload flag */
\
177
}
178
186
#define is_timer0_mode1_started() (TR0 == 1 && (is_timer0_mode1_gate_opened() || INT0 == 1))
187
188
190
195
210
#define timer0_mode1_delay(ticks) \
211
{ \
212
bool is_gate_opened = is_timer0_mode1_gate_opened(); \
213
\
214
timer0_mode1_open_gate(); \
215
\
216
timer0_mode1_start(ticks); \
217
/* Waiting for timer overloaded (timer overload flag set to 1) */
\
218
while(!TF0) \
219
{ \
220
} \
221
timer0_mode1_stop(); \
222
\
223
if (!is_gate_opened) \
224
{ \
225
timer0_mode1_close_gate(); \
226
} \
227
}
229
230
#endif
interrupt.h
sys.h
Generated by
1.9.4