STC15W408AS library 0.16.0
Loading...
Searching...
No Matches
uart1_mode3_timer2_1T.h
Go to the documentation of this file.
1#ifndef STC15_UART1MODE3_T21H
2#define STC15_UART1MODE3_T21H
3
4#include <stdint.h>
5
6#include <sys.h>
7#include <bits.h>
8#include <frequency.h>
9#include <interrupt.h>
10#include <uart1_shared.h>
11#include <uart1_9bit_shared.h>
12
68typedef enum
69#if __SDCC_VERSION_MAJOR == 4 && __SDCC_VERSION_MINOR >= 5
70 : uint16_t
71#endif
72{
74 baudrate_1200 = 0xF6FF,
76 baudrate_2400 = 0xFB80,
78 baudrate_4800 = 0xFDC0,
80 baudrate_9600 = 0xFEE0,
88 baudrate_115200 = 0xFFE8
90
110#define uart1_mode3_timer2_1T_init(pins) \
111do { \
112 enable_mcu_interrupts(); \
113 disable_uart1_interrupt(); \
114 disable_timer2_interrupt(); \
115 \
116 PCON &= 0x3F; \
117 SCON = 0xD0; \
118 \
119 /* The clock source of Timer 2 is SYSclk/12. AUXR.T2x12 = 0 */ \
120 /* AUXR.UART_M0x6 = 0 */ \
121 /* Timer2 is not started. AUXR.T2R = 0 */ \
122 /* Timer2 are used as timer. AUXR.T2_C/T = 0 */ \
123 AUXR &= 0xC2; \
124 /* The clock source of Timer 2 is SYSclk. AUXR.T2x12 = 1 */ \
125 bit_set(AUXR, SBIT2); \
126 \
127 /* Select Timer2 as UART1 baud rate generator. AUXR.S1ST2 = 1; */ \
128 bit_set(AUXR, SBIT0); \
129 \
130 /* Point-to-point mode */ \
131 bit_clr(CLK_DIV, CBIT4); \
132 \
133 /* Set AUXR1 bits 6, 7 to select RxD/TxD pins */ \
134 AUXR1 &= 0x3F; \
135 AUXR1 |= pins; \
136} while (0)
137
150#define uart1_mode3_timer2_1T_start(baudrate) \
151do { \
152 /* Set TH TL values */ \
153 T2L = baudrate & 0xFF; \
154 T2H = baudrate >> 8; \
155 \
156 /* Start Timer2 */ \
157 bit_set(AUXR, SBIT4); \
158} while (0)
159
175#define uart1_mode3_timer2_1T_ticks(baudrate) (65536 - (((MAIN_Fosc / baudrate) >> 2) >> get_frequency_divider_scale()))
176
188#define uart1_mode3_timer2_1T_start_ext(baudrate) \
189do { \
190 const uint16_t ticks = uart1_mode3_timer2_1T_ticks(baudrate);\
191 \
192 /* Set TH TL values */ \
193 T2L = ticks & 0xFF; \
194 T2H = ticks >> 8; \
195 \
196 /* Start Timer2 */ \
197 bit_set(AUXR, SBIT4); \
198} while (0)
199
207#define uart1_mode3_timer2_1T_stop() (bit_clr(AUXR, CBIT4))
208
215#define is_uart1_mode3_timer2_1T_started() (test_if_bit_set(AUXR, SBIT4))
216
217#endif
uart1_mode2_timer2_1t_baudrate_t
UART1 precalculated baudrates.
Definition uart1_mode3_timer2_1T.h:72
@ baudrate_2400
2400 baudrate
Definition uart1_mode3_timer2_1T.h:76
@ baudrate_1200
1200 baudrate
Definition uart1_mode3_timer2_1T.h:74
@ baudrate_19200
19200 baudrate
Definition uart1_mode3_timer2_1T.h:82
@ baudrate_9600
9600 baudrate
Definition uart1_mode3_timer2_1T.h:80
@ baudrate_38400
38400 baudrate
Definition uart1_mode3_timer2_1T.h:84
@ baudrate_4800
4800 baudrate
Definition uart1_mode3_timer2_1T.h:78
@ baudrate_115200
115200 baudrate
Definition uart1_mode3_timer2_1T.h:88
@ baudrate_57600
57600 baudrate
Definition uart1_mode3_timer2_1T.h:86