STC15W408AS library
0.15.0
Loading...
Searching...
No Matches
include
counter0_mode0.h
Go to the documentation of this file.
1
#ifndef STC15_COUNTER0_MODE0H
2
#define STC15_COUNTER0_MODE0H
3
19
#include <stdint.h>
20
#include <stdbool.h>
21
22
#include <
interrupt.h
>
23
29
#define T0 P34
30
36
#define INT0 P32
37
42
49
#define counter0_mode0_init() \
50
do { \
51
enable_mcu_interrupts(); \
52
enable_timer0_interrupt(); \
53
\
54
/* TMOD.3/GATE = 0; */
\
55
/* TMOD.2/(Timer or Counter mode) = 1; */
\
56
/* TMOD.1/M1 timer0 = 0; */
\
57
/* TMOD.0/M0 timer0= 0; */
\
58
TMOD &= 0xF0; \
59
TMOD |= 0x04;
/* init Counter0 */
\
60
} while(0)
62
67
83
#define counter0_mode0_start(value) \
84
do { \
85
counter0_mode0_set_value(value); \
86
\
87
TF0 = 0; \
88
TR0 = 1; \
89
} while (0);
90
98
#define counter0_mode0_stop() \
99
do { \
100
TR0 = 0; \
101
} while (0)
102
103
111
#define is_counter0_mode0_started() (TR0 == 1 && (is_counter0_mode0_gate_opened() || INT0 == 1) )
113
118
126
#define counter0_mode0_get_value() ((((uint16_t) TH0) << 8) | TL0)
127
137
#define counter0_mode0_set_value(value) \
138
do { \
139
TH0 = (uint8_t)(value >> 8); \
140
TL0 = (uint8_t)(value & 0xff); \
141
} while(0)
143
148
156
#define counter0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
157
166
#define counter0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
167
175
#define is_counter0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
176
186
#define counter0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
187
195
#define counter0_mode0_close_gate() (bit_set(TMOD, SBIT3))
196
204
#define is_counter0_mode0_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
206
207
#endif
interrupt.h
Generated by
1.9.8