STC15W408AS library 0.9.0
timer0_mode2.h
Go to the documentation of this file.
1#ifndef STC15_TIMER0_MODE2H
2#define STC15_TIMER0_MODE2H
3
28#include <sys.h>
29#include <bits.h>
30#include <interrupt.h>
31
32#include <stdint.h>
33#include <stdbool.h>
34
35#include <timer_structs.h>
36
42#define INT0 P32
43
44//============================== Timer0 mode2 declarations begin ==========================
48
54#define timer0_mode2_12T_init() \
55{ \
56 enable_mcu_interrupts(); \
57 enable_timer0_interrupt(); \
58 TMOD &= 0xf0; \
59 TMOD |= 0x02; \
60 bit_clr(AUXR, CBIT7); \
61}
62
68#define timer0_mode2_1T_init() \
69{ \
70 enable_mcu_interrupts(); \
71 enable_timer0_interrupt(); \
72 TMOD &= 0xf0; \
73 TMOD |= 0x02; \
74 bit_set(AUXR, SBIT7); \
75}
77//============================== Timer0 mode2 declarations end ============================
78
79
84
89#define timer0_mode2_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
90
96#define timer0_mode2_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
97
105#define is_timer0_mode2_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
106
113#define timer0_mode2_close_gate() (bit_set(TMOD, SBIT3))
114
121#define timer0_mode2_open_gate() (bit_clr(TMOD, CBIT3))
122
130#define is_timer0_mode2_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
131
133//============================== Timer0 get mode, divider, pins declarations end =======
134
135
136//============================== Timer0 run/stop declarations start =====================
140
141
151#define timer0_mode2_reload(ticks) \
152{ \
153 /* Load timer value */ \
154 TH0 = (0xff - ticks); \
155}
156
165#define timer0_mode2_direct_reload(th0) (TH0 = th0)
166
183#define timer0_mode2_start(ticks) \
184{ \
185 timer0_mode2_reload(ticks); \
186 \
187 TF0 = 0; /* clear timer overload flag */ \
188 TR0 = 1; /* set run timer flag */ \
189}
190
208#define timer0_mode2_direct_start(th0) \
209{ \
210 timer0_mode2_direct_reload(th0); \
211 \
212 TF0 = 0; \
213 TR0 = 1; \
214}
215
224#define timer0_mode2_stop() \
225{ \
226 TR0 = 0; /* clear run timer flag */ \
227 TF0 = 0; /* clear timer overload flag */ \
228}
229
237#define is_timer0_mode2_started() (TR0 == 1 && (is_timer0_mode2_gate_opened() || INT0 == 1))
238
240//============================== Timer0 run/stop declarations end =======================
241
242//============================== Timer0 run once declarations start =====================
246
262#define timer0_mode2_delay(ticks) \
263{ \
264 timer0_mode2_start(ticks); \
265 /* Waiting for timer overloaded (timer overload flag set to 1) */ \
266 while(!TF0) \
267 { \
268 } \
269 timer0_mode2_stop(); \
270}
272//============================== Timer0 run once declarations end =========================
273
274#endif