STC15W408AS library
0.10.0
Loading...
Searching...
No Matches
include
counter0_mode1.h
Go to the documentation of this file.
1
#ifndef STC15_COUNTER0_MODE1H
2
#define STC15_COUNTER0_MODE1H
3
21
#include <stdint.h>
22
#include <assert.h>
23
24
#include <
interrupt.h
>
25
31
#define T0 P34
32
33
38
54
#define counter0_mode1_init() \
55
do { \
56
enable_mcu_interrupts(); \
57
enable_timer0_interrupt(); \
58
\
59
TMOD &= 0xF0; \
60
TMOD |= 0x05; \
61
\
62
TF0 = 0; \
63
TR0 = 0; \
64
} while(0)
65
67
72
84
#define counter0_mode1_start(value) \
85
do { \
86
static_assert(value <= 0xffff, "value is too large"); \
87
\
88
const uint16_t _val = value; \
89
TH0 = (uint8_t) (_val >> 8); \
90
TL0 = (uint8_t) (_val & 0xFF); \
91
\
92
TF0 = 0; \
93
TR0 = 1; \
94
} while(0)
95
104
#define is_counter0_mode1_started() (TR0 == 1)
105
113
#define counter0_mode1_stop() \
114
do { \
115
TR0 = 0; \
116
TF0 = 0; \
117
} while(0)
118
120
125
133
#define counter0_mode1_get_value() ((((uint16_t) TH0) << 8) | TL0)
135
136
#endif
interrupt.h
Generated by
1.9.8