STC15W408AS library 0.10.0
Loading...
Searching...
No Matches
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
35
42#define counter0_mode0_init() \
43do { \
44 enable_mcu_interrupts(); \
45 enable_timer0_interrupt(); \
46 \
47 /* TMOD.3/GATE = 0; */ \
48 /* TMOD.2/(Timer or Counter mode) = 1; */ \
49 /* TMOD.1/M1 timer0 = 0; */ \
50 /* TMOD.0/M0 timer0= 0; */ \
51 TMOD |= 0x04; /* init Counter0 */ \
52} while(0)
54
59
71#define counter0_mode0_start(value) \
72do { \
73 counter0_mode0_set_value(value); \
74 \
75 TF0 = 0; \
76 TR0 = 1; \
77} while (0);
78
86#define counter0_mode0_stop() \
87do { \
88 TR0 = 0; \
89} while (0)
90
91
99#define is_counter0_mode0_started() (TR0 == 1 && (is_counter0_mode0_gate_opened() || INT0 == 1) )
101
106
114#define counter0_mode0_get_value() ((((uint16_t) TH0) << 8) | TL0)
115
125#define counter0_mode0_set_value(value) \
126do { \
127 TH0 = (uint8_t)(value >> 8); \
128 TL0 = (uint8_t)(value & 0xff); \
129} while(0)
131
136
144#define counter0_mode0_enable_P35_output() (bit_set(INT_CLKO, SBIT0))
145
154#define counter0_mode0_disable_P35_output() (bit_clr(INT_CLKO, CBIT0))
155
163#define is_counter0_mode0_P35_output_enabled() (test_if_bit_set(INT_CLKO, SBIT0))
164
174#define counter0_mode0_open_gate() (bit_clr(TMOD, CBIT3))
175
183#define counter0_mode0_close_gate() (bit_set(TMOD, SBIT3))
184
192#define is_counter0_mode0_gate_opened() (test_if_bit_cleared(TMOD, SBIT3))
194
195#endif