STC15W408AS library
0.15.0
Loading...
Searching...
No Matches
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
do { \
54
enable_mcu_interrupts(); \
55
enable_timer0_interrupt(); \
56
TMOD &= 0xf0; \
57
bit_set(TMOD, SBIT0); \
58
bit_clr(AUXR, CBIT7); \
59
} while(0)
60
66
#define timer0_mode1_1T_init() \
67
do { \
68
enable_mcu_interrupts(); \
69
enable_timer0_interrupt(); \
70
TMOD &= 0xf0; \
71
bit_set(TMOD, SBIT0); \
72
bit_set(AUXR, SBIT7); \
73
} while(0)
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
131
#define timer0_mode1_start(ticks) \
132
do { \
133
uint16_t value = 0xffff - ticks; \
134
/* Load timer high and low bytes value */
\
135
TL0 = value & 0xff; \
136
TH0 = (value >> 8) & 0xff; \
137
\
138
TF0 = 0;
/* clear timer overload flag */
\
139
TR0 = 1;
/* set run timer flag */
\
140
} while(0)
141
164
#define timer0_mode1_direct_start(th0, tl0) \
165
do { \
166
TH0 = th0; \
167
TL0 - tl0; \
168
\
169
TF0 = 0; \
170
TR0 = 1; \
171
} while(0)
172
181
#define timer0_mode1_stop() \
182
do { \
183
TR0 = 0;
/* clear run timer flag */
\
184
TF0 = 0;
/* clear timer overload flag */
\
185
} while(0)
186
194
#define is_timer0_mode1_started() (TR0 == 1 && (is_timer0_mode1_gate_opened() || INT0 == 1))
195
196
198
203
218
#define timer0_mode1_delay(ticks) \
219
do { \
220
bool is_gate_opened = is_timer0_mode1_gate_opened(); \
221
\
222
timer0_mode1_open_gate(); \
223
\
224
timer0_mode1_start(ticks); \
225
/* Waiting for timer overloaded (timer overload flag set to 1) */
\
226
while(!TF0) \
227
{ \
228
} \
229
timer0_mode1_stop(); \
230
\
231
if (!is_gate_opened) \
232
{ \
233
timer0_mode1_close_gate(); \
234
} \
235
} while(0)
237
238
#endif
interrupt.h
sys.h
Generated by
1.9.8