STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
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() \
55do { \
56 enable_mcu_interrupts(); \
57 enable_timer0_interrupt(); \
58 TMOD &= 0xf0; \
59 TMOD |= 0x02; \
60 bit_clr(AUXR, CBIT7); \
61} while(0)
62
68#define timer0_mode2_1T_init() \
69do { \
70 enable_mcu_interrupts(); \
71 enable_timer0_interrupt(); \
72 TMOD &= 0xf0; \
73 TMOD |= 0x02; \
74 bit_set(AUXR, SBIT7); \
75} while(0)
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) \
152do { \
153 /* Load timer value */ \
154 TH0 = (0xff - ticks); \
155} while(0)
156
165#define timer0_mode2_direct_reload(th0) (TH0 = th0)
166
187#define timer0_mode2_start(ticks) \
188do { \
189 timer0_mode2_reload(ticks); \
190 \
191 TF0 = 0; /* clear timer overload flag */ \
192 TR0 = 1; /* set run timer flag */ \
193} while(0)
194
216#define timer0_mode2_direct_start(th0) \
217do { \
218 timer0_mode2_direct_reload(th0); \
219 \
220 TF0 = 0; \
221 TR0 = 1; \
222} while(0)
223
232#define timer0_mode2_stop() \
233do { \
234 TR0 = 0; /* clear run timer flag */ \
235 TF0 = 0; /* clear timer overload flag */ \
236} while(0)
237
245#define is_timer0_mode2_started() (TR0 == 1 && (is_timer0_mode2_gate_opened() || INT0 == 1))
246
248//============================== Timer0 run/stop declarations end =======================
249
250//============================== Timer0 run once declarations start =====================
254
273#define timer0_mode2_delay(ticks) \
274do { \
275 disable_timer0_interrupt(); \
276 timer0_mode2_start(ticks); \
277 /* Waiting for timer overloaded (timer overload flag set to 1) */ \
278 while(!TF0) \
279 { \
280 } \
281 timer0_mode2_stop(); \
282} while(0)
284//============================== Timer0 run once declarations end =========================
285
286#endif