STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
timer0_mode0.h
Go to the documentation of this file.
1#ifndef STC15_TIMER0_MODE0H
2#define STC15_TIMER0_MODE0H
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 INTO P32
42
43//============================== Timer0 mode0 declarations begin ==========================
47
56#define timer0_mode0_12T_init() \
57do { \
58 enable_mcu_interrupts(); \
59 disable_timer0_interrupt(); \
60 TMOD &= 0xf0; \
61 bit_clr(AUXR, CBIT7); \
62} while(0)
63
72#define timer0_mode0_1T_init() \
73do { \
74 enable_mcu_interrupts(); \
75 disable_timer0_interrupt(); \
76 TMOD &= 0xf0; \
77 bit_set(AUXR, SBIT7); \
78} while(0)
80//============================== Timer0 mode0 declarations end ============================
81
82
87
92#define timer0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
93
99#define timer0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
100
108#define is_timer0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
109
116#define timer0_mode0_close_gate() (bit_set(TMOD, SBIT3))
117
124#define timer0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
125
133#define is_timer0_mode0_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
134
136//============================== Timer0 get mode, divider, pins declarations end =======
137
138
139//============================== Timer0 run/stop declarations start =====================
143
144
154#define timer0_mode0_reload(ticks) \
155do { \
156 uint16_t value = 0xffff - ticks; \
157 /* Load timer high and low bytes value */ \
158 TL0 = value & 0xff; \
159 TH0 = (value >> 8) & 0xff; \
160} while(0)
161
171#define timer0_mode0_direct_reload(th0, tl0) \
172do { \
173 TL0 = tl0; \
174 TH0 = th0; \
175} while(0)
176
197#define timer0_mode0_start(ticks) \
198do { \
199 timer0_mode0_reload(ticks); \
200 \
201 TF0 = 0; /* clear timer overload flag */ \
202 TR0 = 1; /* set run timer flag */ \
203} while(0)
204
227#define timer0_mode0_direct_start(th0, tl0) \
228do { \
229 timer0_mode0_direct_reload(th0, tl0); \
230 \
231 TF0 = 0; \
232 TR0 = 1; \
233} while(0)
234
243#define timer0_mode0_stop() \
244do { \
245 TR0 = 0; /* clear run timer flag */ \
246 TF0 = 0; /* clear timer overload flag */ \
247} while(0)
248
256#define is_timer0_mode0_started() (TR0 == 1 && (is_timer0_mode0_gate_opened() || INT0 == 1))
257
259//============================== Timer0 run/stop declarations end =======================
260
261//============================== Timer0 run once declarations start =====================
265
281#define timer0_mode0_delay(ticks) \
282do { \
283 bool is_gate_opened = is_timer0_mode0_gate_opened(); \
284 \
285 timer0_mode0_open_gate(); \
286 \
287 timer0_mode0_start(ticks); \
288 /* Waiting for timer overloaded (timer overload flag set to 1) */ \
289 while(!TF0) \
290 { \
291 } \
292 timer0_mode0_stop(); \
293 \
294 if (!is_gate_opened) \
295 { \
296 timer0_mode0_close_gate(); \
297 } \
298} while(0)
300//============================== Timer0 run once declarations end =========================
301
302#endif