STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
counter2_mode0.h
Go to the documentation of this file.
1#ifndef STC15_COUNTER2_MODE0H
2#define STC15_COUNTER2_MODE0H
3
19#include <assert.h>
20#include <stdint.h>
21#include <stdbool.h>
22
23#include <interrupt.h>
24#include <bits.h>
25
31#define T2 P31
32
37
44#define counter2_mode0_init() \
45do { \
46 enable_mcu_interrupts(); \
47 enable_timer2_interrupt(); \
48 \
49 bit_clr(AUXR, CBIT4); \
50 bit_set(AUXR, SBIT3); /* init Counter2 */ \
51} while(0)
53
58
74#define counter2_mode0_start(value) \
75do { \
76 counter2_mode0_set_value(value); \
77 \
78 bit_set(AUXR, SBIT4); \
79} while (0);
80
88#define counter2_mode0_stop() \
89do { \
90 bit_clr(AUXR, CBIT4); \
91} while (0)
92
93
101#define is_counter2_mode0_started() (test_if_bit_set(_AUXR, SBIT4))
103
108
116#define counter2_mode0_get_value() ((((uint16_t) T2H) << 8) | T2L)
117
127#define counter2_mode0_set_value(value) \
128do { \
129 static_assert(value <= 0xffff, "value to large"); \
130 const uint16_t _val = (value); \
131 T2H = (uint8_t)(_val >> 8); \
132 T2L = (uint8_t)(_val & 0xff); \
133} while(0)
135
140
148#define counter2_mode0_enable_P30_output() (bit_set(INT_CLKO, SBIT2))
149
158#define counter2_mode0_disable_P30_output() (bit_clr(INT_CLKO, CBIT2))
159
167#define is_counter2_mode0_P30_output_enabled() (test_if_bit_set(INT_CLKO, SBIT2))
169
170#endif