STC15W408AS library
0.15.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
64
#define counter0_mode1_init() \
65
do { \
66
enable_mcu_interrupts(); \
67
enable_timer0_interrupt(); \
68
\
69
TMOD &= 0xF0; \
70
TMOD |= 0x05; \
71
\
72
TF0 = 0; \
73
TR0 = 0; \
74
} while(0)
75
77
82
94
#define counter0_mode1_start(value) \
95
do { \
96
static_assert(value <= 0xffff, "value is too large"); \
97
\
98
const uint16_t _val = value; \
99
TH0 = (uint8_t) (_val >> 8); \
100
TL0 = (uint8_t) (_val & 0xFF); \
101
\
102
TF0 = 0; \
103
TR0 = 1; \
104
} while(0)
105
114
#define is_counter0_mode1_started() (TR0 == 1)
115
123
#define counter0_mode1_stop() \
124
do { \
125
TR0 = 0; \
126
TF0 = 0; \
127
} while(0)
128
130
135
143
#define counter0_mode1_get_value() ((((uint16_t) TH0) << 8) | TL0)
145
146
#endif
interrupt.h
Generated by
1.9.8