STC15W408AS library 0.12.0
Loading...
Searching...
No Matches
uart1_9bit_shared.h
Go to the documentation of this file.
1#ifndef STC15_UART19BITSHAREDH
2#define STC15_UART19BITSHAREDH
3
4#include <stdint.h>
5#include <stdbool.h>
6
7#include <sys.h>
8
32
49#define uart1_send_9bit(byte, ninth) \
50do { \
51 /* TB8 contains 9-th bit value */ \
52 TB8 = ninth; \
53 SBUF = byte; \
54 \
55 while (!TI); \
56 TI = 0; \
57} while (0)
58
75#define uart1_receive_9bit(byte, ninth) \
76do { \
77 RI=0; \
78 while(!RI); \
79 /* After RI flag set to 1 */ \
80 /* SBUF contains first 8-bit data */ \
81 /* and RB8 contains 9th bit */ \
82 byte = SBUF; \
83 ninth = RB8; \
84} while (0)
85
87
92
101#define uart1_send_byte_even_parity(byte) \
102do { \
103 /* P is even parity bit for ACC value */ \
104 ACC = byte; \
105 uart1_send_9bit(byte, P); \
106} while (0)
107
116#define uart1_send_byte_odd_parity(byte) \
117do { \
118 /* P is even parity bit for ACC value */ \
119 ACC = byte; \
120 /* For the odd parity P should be inverted*/ \
121 uart1_send_9bit(byte, !P); \
122} while (0)
123
132#define uart1_send_byte_space_parity(byte) \
133do { \
134 \
135 uart1_send_9bit(byte, 0); \
136} while (0)
137
146#define uart1_send_byte_mark_parity(byte) \
147do { \
148 /* Parity bit is always 1 */ \
149 uart1_send_9bit(byte, 1); \
150} while (0)
151
163#define uart1_receive_byte_even_parity(byte) \
164do { \
165 /* Try to receive byte */ \
166 /* util parity bit is to be valid */ \
167 bool is_parity_valid = false; \
168 while (!is_parity_valid) \
169 { \
170 /* Receive 8-bit to SBUF */ \
171 /* and parity bit to RB8 */ \
172 RI = 0; \
173 while (!RI); \
174 \
175 byte = SBUF; \
176 \
177 /* Load received 8-bit to ACC for */ \
178 /* even parity calculation */ \
179 ACC = byte; \
180 \
181 /* Validate received and calculated */ \
182 /* parity bits */ \
183 is_parity_valid = P == RB8; \
184 } \
185} while (0)
186
198#define uart1_receive_byte_odd_parity(byte) \
199do { \
200 /* Try to receive byte */ \
201 /* util parity bit is to be valid */ \
202 bool is_parity_valid = false; \
203 while (!is_parity_valid) \
204 { \
205 /* Receive 8-bit to SBUF */ \
206 /* and parity bit to RB8 */ \
207 RI = 0; \
208 while (!RI); \
209 \
210 byte = SBUF; \
211 \
212 /* Load received 8-bit to ACC for */ \
213 /* even parity calculation */ \
214 ACC = byte; \
215 \
216 /* For odd parity even parity P */ \
217 /* should be inverted */ \
218 is_parity_valid = P != RB8; \
219 } \
220} while (0)
221
233#define uart1_receive_byte_mark_parity(byte) \
234do { \
235 /* Try to receive byte */ \
236 /* util parity bit is to be valid */ \
237 bool is_parity_valid = false; \
238 while (!is_parity_valid) \
239 { \
240 RI = 0; \
241 while (!RI); \
242 \
243 byte = SBUF; \
244 \
245 /* RB8 contains parity bit */ \
246 is_parity_valid = RB8 == 1; \
247 } \
248} while (0)
249
261#define uart1_receive_byte_space_parity(byte) \
262do { \
263 /* Try to receive byte */ \
264 /* util parity bit is to be valid */ \
265 bool is_parity_valid = false; \
266 while (!is_parity_valid) \
267 { \
268 RI = 0; \
269 while (!RI); \
270 \
271 byte = SBUF; \
272 \
273 /* RB8 contains parity bit */ \
274 is_parity_valid = RB8 == 0; \
275 } \
276} while (0)
278
283
293#define uart1_send_byte_2stop_bits(byte) \
294do { \
295 uart1_send_9bit(byte, 1); \
296} while (0)
297
308#define uart1_receive_byte_2stop_bits(byte) \
309do { \
310 uart1_receive_byte_mark_parity(byte); \
311} while (0)
312
314
315#endif