STC15W408AS library 0.9.0
timer2_mode0.h
Go to the documentation of this file.
1#ifndef STC15_TIMER2_MODE0H
2#define STC15_TIMER2_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
40
48#define timer2_mode0_12T_init() \
49{ \
50 enable_mcu_interrupts(); \
51 enable_timer2_interrupt(); \
52 AUXR &= 0xE2; \
53}
54
63#define timer2_mode0_1T_init() \
64{ \
65 enable_mcu_interrupts(); \
66 enable_timer2_interrupt(); \
67 AUXR &= 0xE2; \
68 AUXR |= 0x05; \
69}
71
76
83#define timer2_mode0_enable_P30_output() (bit_set(INT_CLKO, SBIT2))
84
90#define timer2_mode0_disable_P30_output() (bit_clr(INT_CLKO, CBIT2))
91
99#define is_timer2_mode0_P30_output_enabled() (test_if_bit_set(INT_CLKO, SBIT2))
100
102
107
124#define timer2_mode0_start(ticks) \
125{ \
126 timer2_mode0_reload(ticks); \
127 \
128 bit_set(AUXR, SBIT4); \
129}
130
147#define timer2_mode0_direct_start(th0, tl0) \
148{ \
149 timer2_mode0_direct_reload(th0, tl0); \
150 \
151 bit_set(AUXR, SBIT4); \
152}
153
160#define timer2_mode0_stop() { \
161 bit_clr(AUXR, CBIT4); /* clear T2 run flag */ \
162}
163
171#define is_timer2_mode0_started() (test_if_bit_set(AUXR, SBIT4))
172
182#define timer2_mode0_reload(ticks) \
183{ \
184 uint16_t value = 0xffff - ticks; \
185 T2L = value & 0xff; \
186 T2H = (value >> 8) & 0xff; \
187}
188
198#define timer2_mode0_direct_reload(th2, tl2) \
199{ \
200 T2H = th2; \
201 T2L = tl2; \
202}
203
205
210
217#define timer2_mode0_enable_as_uart1_baud_rate() (bit_set(AUXR, SBIT0))
218
225#define timer2_mode0_disable_as_uart1_baud_rate() (bit_clr(AUXR, CBIT0))
226
235#define is_timer2_mode0_as_uart1_baud_rate_enabled() (test_if_bit_set(AUXR, SBIT0))
236
238
239#endif