STC15W408AS library
0.12.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
79
#define counter0_mode0_start(value) \
80
do { \
81
counter0_mode0_set_value(value); \
82
\
83
TF0 = 0; \
84
TR0 = 1; \
85
} while (0);
86
94
#define counter0_mode0_stop() \
95
do { \
96
TR0 = 0; \
97
} while (0)
98
99
107
#define is_counter0_mode0_started() (TR0 == 1 && (is_counter0_mode0_gate_opened() || INT0 == 1) )
109
114
122
#define counter0_mode0_get_value() ((((uint16_t) TH0) << 8) | TL0)
123
133
#define counter0_mode0_set_value(value) \
134
do { \
135
TH0 = (uint8_t)(value >> 8); \
136
TL0 = (uint8_t)(value & 0xff); \
137
} while(0)
139
144
152
#define counter0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
153
162
#define counter0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
163
171
#define is_counter0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
172
182
#define counter0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
183
191
#define counter0_mode0_close_gate() (bit_set(TMOD, SBIT3))
192
200
#define is_counter0_mode0_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
202
203
#endif
interrupt.h
Generated by
1.9.8