STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
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() \
46do { \
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
78#define counter0_mode3_start(value) \
79do { \
80 counter0_mode3_set_value(value); \
81 \
82 TF0 = 0; \
83 TR0 = 1; \
84} while (0);
85
93#define counter0_mode3_stop() \
94do { \
95 TR0 = 0; \
96} while (0)
97
98
106#define is_counter0_mode3_started() (TR0 == 1 && (is_counter0_mode3_gate_opened() || INT0 == 1) )
108
113
121#define counter0_mode3_get_value() ((((uint16_t) TH0) << 8) | TL0)
122
132#define counter0_mode3_set_value(value) \
133do { \
134 TH0 = (uint8_t)(value >> 8); \
135 TL0 = (uint8_t)(value & 0xff); \
136} while(0)
138
143
151#define counter0_mode3_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
152
161#define counter0_mode3_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
162
170#define is_counter0_mode3_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
171
181#define counter0_mode3_open_gate() (bit_clr(TMOD, CBIT3))
182
190#define counter0_mode3_close_gate() (bit_set(TMOD, SBIT3))
191
199#define is_counter0_mode3_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
201
202#endif