STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
uart1_mode1_timer2_1T.h
Go to the documentation of this file.
1#ifndef STC15_UART1MODE1_T212H
2#define STC15_UART1MODE1_T212H
3
53#include <stdint.h>
54
55#include <sys.h>
56#include <bits.h>
57#include <frequency.h>
58#include <interrupt.h>
59#include <uart1_shared.h>
60#include <uart1_8bit_shared.h>
61
67typedef enum
68#if __SDCC_VERSION_MAJOR == 4 && __SDCC_VERSION_MINOR >= 5
69 : uint16_t
70#endif
71{
73 baudrate_1200 = 0xF6FF,
75 baudrate_2400 = 0xFB80,
77 baudrate_4800 = 0xFDC0,
79 baudrate_9600 = 0xFEE0,
87 baudrate_115200 = 0xFFE8
89
90
110#define uart1_mode1_timer2_1T_init(pins) \
111do { \
112 \
113 enable_mcu_interrupts(); \
114 disable_uart1_interrupt(); \
115 disable_timer2_interrupt(); \
116 \
117 PCON &= 0x3F; \
118 SCON = 0x50; \
119 \
120 /* The clock source of Timer 2 is SYSclk/12. AUXR.T2x12 = 0 */ \
121 /* AUXR.UART_M0x6 = 0 */ \
122 /* Timer2 is not started. AUXR.T2R = 0 */ \
123 /* Timer2 are used as timer. AUXR.T2_C/T = 0 */ \
124 AUXR &= 0xC2; \
125 \
126 /* Select Timer2 as UART1 baud rate generator. AUXR.S1ST2 = 1; */ \
127 bit_set(AUXR, SBIT0); \
128 /* The clock source of Timer 2 is SYSclk. AUXR.T2x12 = 1 */ \
129 bit_set(AUXR, SBIT2); \
130 \
131 /* Point-to-point mode */ \
132 bit_clr(CLK_DIV, CBIT4); \
133 \
134 /* Set AUXR1 bits 6, 7 to select RxD/TxD pins */ \
135 AUXR1 &= 0x3F; \
136 AUXR1 |= pins; \
137} while(0)
138
151#define uart1_mode1_timer2_1T_start(baudrate) \
152do { \
153 /* Set TH TL values */ \
154 T2L = baudrate & 0xFF; \
155 T2H = baudrate >> 8; \
156 \
157 /* Start Timer2 */ \
158 bit_set(AUXR, SBIT4); \
159} while(0)
160
176#define uart1_mode1_timer2_1T_ticks(baudrate) (65536 - (((MAIN_Fosc / baudrate) >> 2) >> get_frequency_divider_scale()))
177
189#define uart1_mode1_timer2_1T_start_ext(baudrate) \
190do { \
191 const uint16_t ticks = uart1_mode1_timer2_1T_ticks(baudrate);\
192 \
193 /* Set TH TL values */ \
194 T2L = ticks & 0xFF; \
195 T2H = ticks >> 8; \
196 \
197 /* Start Timer2 */ \
198 bit_set(AUXR, SBIT4); \
199} while (0)
200
201
209#define uart1_mode1_timer2_1T_stop (bit_clr(AUXR, CBIT4))
210
217#define is_uart1_mode1_timer2_1T_started() (test_if_bit_set(AUXR, SBIT4))
218
219
220#endif
uart1_mode1_timer2_1t_baudrate_t
UART1 precalculated baudrates.
Definition uart1_mode1_timer2_1T.h:71
@ baudrate_2400
2400 baudrate
Definition uart1_mode1_timer2_1T.h:75
@ baudrate_1200
1200 baudrate
Definition uart1_mode1_timer2_1T.h:73
@ baudrate_19200
19200 baudrate
Definition uart1_mode1_timer2_1T.h:81
@ baudrate_9600
9600 baudrate
Definition uart1_mode1_timer2_1T.h:79
@ baudrate_38400
38400 baudrate
Definition uart1_mode1_timer2_1T.h:83
@ baudrate_4800
4800 baudrate
Definition uart1_mode1_timer2_1T.h:77
@ baudrate_115200
115200 baudrate
Definition uart1_mode1_timer2_1T.h:87
@ baudrate_57600
57600 baudrate
Definition uart1_mode1_timer2_1T.h:85