STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
uart1_mode3_timer2_12T.h
Go to the documentation of this file.
1#ifndef STC15_UART1MODE3_T212H
2#define STC15_UART1MODE3_T212H
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 = 0xFF3F,
76 baudrate_2400 = 0xFF9F,
78 baudrate_4800 = 0xFFCF,
80 baudrate_9600 = 0xFFE7,
82
102#define uart1_mode3_timer2_12T_init(pins) \
103do { \
104 enable_mcu_interrupts(); \
105 disable_uart1_interrupt(); \
106 disable_timer2_interrupt(); \
107 \
108 PCON &= 0x3F; \
109 SCON = 0xD0; \
110 \
111 /* The clock source of Timer 2 is SYSclk/12. AUXR.T2x12 = 0 */ \
112 /* AUXR.UART_M0x6 = 0 */ \
113 /* Timer2 is not started. AUXR.T2R = 0 */ \
114 /* Timer2 are used as timer. AUXR.T2_C/T = 0 */ \
115 AUXR &= 0xC2; \
116 \
117 /* Select Timer2 as UART1 baud rate generator. AUXR.S1ST2 = 1; */ \
118 bit_set(AUXR, SBIT0); \
119 \
120 /* Point-to-point mode */ \
121 bit_clr(CLK_DIV, CBIT4); \
122 \
123 /* Set AUXR1 bits 6, 7 to select RxD/TxD pins */ \
124 AUXR1 &= 0x3F; \
125 AUXR1 |= pins; \
126} while (0)
127
140#define uart1_mode3_timer2_12T_start(baudrate) \
141do { \
142 /* Set TH TL values */ \
143 T2L = baudrate & 0xFF; \
144 T2H = baudrate >> 8; \
145 \
146 /* Start Timer2 */ \
147 bit_set(AUXR, SBIT4); \
148} while (0)
149
165#define uart1_mode3_timer2_12T_ticks(baudrate) (65536 - ((((MAIN_Fosc / 12) / baudrate) >> 2) >> get_frequency_divider_scale()))
166
178#define uart1_mode3_timer2_12T_start_ext(baudrate) \
179do { \
180 const uint16_t ticks = uart1_mode3_timer2_12T_ticks(baudrate);\
181 \
182 /* Set TH TL values */ \
183 T2L = ticks & 0xFF; \
184 T2H = ticks >> 8; \
185 \
186 /* Start Timer2 */ \
187 bit_set(AUXR, SBIT4); \
188} while (0)
189
197#define uart1_mode3_timer2_12T_stop() (bit_clr(AUXR, CBIT4))
198
205#define is_uart1_mode3_timer2_12T_started() (test_if_bit_set(AUXR, SBIT4))
206
207#endif
uart1_mode3_timer2_12t_baudrate_t
UART1 Mode3 precalculated baudrates.
Definition uart1_mode3_timer2_12T.h:72
@ baudrate_2400
2400 baudrate
Definition uart1_mode3_timer2_12T.h:76
@ baudrate_1200
1200 baudrate
Definition uart1_mode3_timer2_12T.h:74
@ baudrate_9600
9600 baudrate
Definition uart1_mode3_timer2_12T.h:80
@ baudrate_4800
4800 baudrate
Definition uart1_mode3_timer2_12T.h:78