STC15W408AS library
0.17.0
Loading...
Searching...
No Matches
include
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() \
54
do { \
55
enable_mcu_interrupts(); \
56
enable_timer0_interrupt(); \
57
TMOD &= 0xf0; \
58
bit_clr(AUXR, CBIT7); \
59
} while(0)
60
69
#define timer0_mode0_1T_init() \
70
do { \
71
enable_mcu_interrupts(); \
72
enable_timer0_interrupt(); \
73
TMOD &= 0xf0; \
74
bit_set(AUXR, SBIT7); \
75
} while(0)
77
//============================== Timer0 mode0 declarations end ============================
78
79
84
89
#define timer0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
90
96
#define timer0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
97
105
#define is_timer0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
106
113
#define timer0_mode0_close_gate() (bit_set(TMOD, SBIT3))
114
121
#define timer0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
122
130
#define is_timer0_mode0_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_mode0_reload(ticks) \
152
do { \
153
uint16_t value = 0xffff - ticks; \
154
/* Load timer high and low bytes value */
\
155
TL0 = value & 0xff; \
156
TH0 = (value >> 8) & 0xff; \
157
} while(0)
158
168
#define timer0_mode0_direct_reload(th0, tl0) \
169
do { \
170
TL0 = tl0; \
171
TH0 = th0; \
172
} while(0)
173
194
#define timer0_mode0_start(ticks) \
195
do { \
196
timer0_mode0_reload(ticks); \
197
\
198
TF0 = 0;
/* clear timer overload flag */
\
199
TR0 = 1;
/* set run timer flag */
\
200
} while(0)
201
224
#define timer0_mode0_direct_start(th0, tl0) \
225
do { \
226
timer0_mode0_direct_reload(th0, tl0); \
227
\
228
TF0 = 0; \
229
TR0 = 1; \
230
} while(0)
231
240
#define timer0_mode0_stop() \
241
do { \
242
TR0 = 0;
/* clear run timer flag */
\
243
TF0 = 0;
/* clear timer overload flag */
\
244
} while(0)
245
253
#define is_timer0_mode0_started() (TR0 == 1 && (is_timer0_mode0_gate_opened() || INT0 == 1))
254
256
//============================== Timer0 run/stop declarations end =======================
257
258
//============================== Timer0 run once declarations start =====================
262
278
#define timer0_mode0_delay(ticks) \
279
do { \
280
disable_timer0_interrupt(); \
281
timer0_mode0_start(ticks); \
282
/* Waiting for timer overloaded (timer overload flag set to 1) */
\
283
while(!TF0) \
284
{ \
285
} \
286
timer0_mode0_stop(); \
287
} while(0)
289
//============================== Timer0 run once declarations end =========================
290
291
#endif
interrupt.h
sys.h
Generated by
1.9.8