STC15W408AS library
0.12.0
Loading...
Searching...
No Matches
include
counter0_mode3.h
Go to the documentation of this file.
1
#ifndef STC15_COUNTER0_MODE3H
2
#define STC15_COUNTER0_MODE3H
3
15
#include <stdint.h>
16
#include <stdbool.h>
17
18
#include <
interrupt.h
>
19
25
#define T0 P34
26
32
#define INT0 P32
33
38
45
#define counter0_mode3_init() \
46
do { \
47
enable_mcu_interrupts(); \
48
enable_timer0_interrupt(); \
49
/* TMOD.3/GATE = 0; */
\
50
/* TMOD.2/(Timer or Counter mode) = 1; */
\
51
/* TMOD.1/M1 timer0 = 1; */
\
52
/* TMOD.0/M0 timer0= 1; */
\
53
TMOD &= 0xF0; \
54
TMOD |= 0x07;
/* init Counter0 */
\
55
} while(0)
57
62
74
#define counter0_mode3_start(value) \
75
do { \
76
counter0_mode3_set_value(value); \
77
\
78
TF0 = 0; \
79
TR0 = 1; \
80
} while (0);
81
89
#define counter0_mode3_stop() \
90
do { \
91
TR0 = 0; \
92
} while (0)
93
94
102
#define is_counter0_mode3_started() (TR0 == 1 && (is_counter0_mode3_gate_opened() || INT0 == 1) )
104
109
117
#define counter0_mode3_get_value() ((((uint16_t) TH0) << 8) | TL0)
118
128
#define counter0_mode3_set_value(value) \
129
do { \
130
TH0 = (uint8_t)(value >> 8); \
131
TL0 = (uint8_t)(value & 0xff); \
132
} while(0)
134
139
147
#define counter0_mode3_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
148
157
#define counter0_mode3_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
158
166
#define is_counter0_mode3_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
167
177
#define counter0_mode3_open_gate() (bit_clr(TMOD, CBIT3))
178
186
#define counter0_mode3_close_gate() (bit_set(TMOD, SBIT3))
187
195
#define is_counter0_mode3_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
197
198
#endif
interrupt.h
Generated by
1.9.8