STC15W408AS library 0.10.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
53#define timer0_mode0_12T_init() \
54do { \
55 enable_mcu_interrupts(); \
56 enable_timer0_interrupt(); \
57 TMOD &= 0xf0; \
58 bit_clr(AUXR, CBIT7); \
59} while(0)
60
66#define timer0_mode0_1T_init() \
67do { \
68 enable_mcu_interrupts(); \
69 enable_timer0_interrupt(); \
70 TMOD &= 0xf0; \
71 bit_set(AUXR, SBIT7); \
72} while(0)
74//============================== Timer0 mode0 declarations end ============================
75
76
81
86#define timer0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
87
93#define timer0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
94
102#define is_timer0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
103
110#define timer0_mode0_close_gate() (bit_set(TMOD, SBIT3))
111
118#define timer0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
119
127#define is_timer0_mode0_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
128
130//============================== Timer0 get mode, divider, pins declarations end =======
131
132
133//============================== Timer0 run/stop declarations start =====================
137
138
148#define timer0_mode0_reload(ticks) \
149do { \
150 uint16_t value = 0xffff - ticks; \
151 /* Load timer high and low bytes value */ \
152 TL0 = value & 0xff; \
153 TH0 = (value >> 8) & 0xff; \
154} while(0)
155
165#define timer0_mode0_direct_reload(th0, tl0) \
166do { \
167 TL0 = tl0; \
168 TH0 = th0; \
169} while(0)
170
187#define timer0_mode0_start(ticks) \
188do { \
189 timer0_mode0_reload(ticks); \
190 \
191 TF0 = 0; /* clear timer overload flag */ \
192 TR0 = 1; /* set run timer flag */ \
193} while(0)
194
213#define timer0_mode0_direct_start(th0, tl0) \
214do { \
215 timer0_mode0_direct_reload(th0, tl0); \
216 \
217 TF0 = 0; \
218 TR0 = 1; \
219} while(0)
220
229#define timer0_mode0_stop() \
230do { \
231 TR0 = 0; /* clear run timer flag */ \
232 TF0 = 0; /* clear timer overload flag */ \
233} while(0)
234
242#define is_timer0_mode0_started() (TR0 == 1 && (is_timer0_mode0_gate_opened() || INT0 == 1))
243
245//============================== Timer0 run/stop declarations end =======================
246
247//============================== Timer0 run once declarations start =====================
251
267#define timer0_mode0_delay(ticks) \
268do { \
269 bool is_gate_opened = is_timer0_mode0_gate_opened(); \
270 \
271 timer0_mode0_open_gate(); \
272 \
273 timer0_mode0_start(ticks); \
274 /* Waiting for timer overloaded (timer overload flag set to 1) */ \
275 while(!TF0) \
276 { \
277 } \
278 timer0_mode0_stop(); \
279 \
280 if (!is_gate_opened) \
281 { \
282 timer0_mode0_close_gate(); \
283 } \
284} while(0)
286//============================== Timer0 run once declarations end =========================
287
288#endif