STC15W408AS library 0.15.0
Loading...
Searching...
No Matches
uart1_mode1_timer2_12T.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 = 0xFF3F,
75 baudrate_2400 = 0xFF9F,
77 baudrate_4800 = 0xFFCF,
79 baudrate_9600 = 0xFFE7,
81
101#define uart1_mode1_timer2_12T_init(pins) \
102do { \
103 \
104 enable_mcu_interrupts(); \
105 disable_uart1_interrupt(); \
106 disable_timer2_interrupt(); \
107 \
108 PCON &= 0x3F; \
109 SCON = 0x50; \
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_mode1_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_mode1_timer2_12T_ticks(baudrate) (65536 - ((((MAIN_Fosc / 12) / baudrate) >> 2) >> get_frequency_divider_scale()))
166
178#define uart1_mode1_timer2_12T_start_ext(baudrate) \
179do { \
180 const uint16_t ticks = uart1_mode1_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_mode1_timer2_12T_stop (bit_clr(AUXR, CBIT4))
198
205#define is_uart1_mode1_timer2_12T_started() (test_if_bit_set(AUXR, SBIT4))
206
207#endif
uart1_mode1_timer2_12t_baudrate_t
UART1 precalculated baudrates.
Definition uart1_mode1_timer2_12T.h:71
@ baudrate_2400
2400 baudrate
Definition uart1_mode1_timer2_12T.h:75
@ baudrate_1200
1200 baudrate
Definition uart1_mode1_timer2_12T.h:73
@ baudrate_9600
9600 baudrate
Definition uart1_mode1_timer2_12T.h:79
@ baudrate_4800
4800 baudrate
Definition uart1_mode1_timer2_12T.h:77