STC15W408AS library
0.12.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
38
#define INT0 P32
39
44
60
#define counter0_mode1_init() \
61
do { \
62
enable_mcu_interrupts(); \
63
enable_timer0_interrupt(); \
64
\
65
TMOD &= 0xF0; \
66
TMOD |= 0x05; \
67
\
68
TF0 = 0; \
69
TR0 = 0; \
70
} while(0)
71
73
78
90
#define counter0_mode1_start(value) \
91
do { \
92
static_assert(value <= 0xffff, "value is too large"); \
93
\
94
const uint16_t _val = value; \
95
TH0 = (uint8_t) (_val >> 8); \
96
TL0 = (uint8_t) (_val & 0xFF); \
97
\
98
TF0 = 0; \
99
TR0 = 1; \
100
} while(0)
101
110
#define is_counter0_mode1_started() (TR0 == 1)
111
119
#define counter0_mode1_stop() \
120
do { \
121
TR0 = 0; \
122
TF0 = 0; \
123
} while(0)
124
126
131
139
#define counter0_mode1_get_value() ((((uint16_t) TH0) << 8) | TL0)
141
142
#endif
interrupt.h
Generated by
1.9.8