32 #ifndef __STC8x_UART_H_
33 #define __STC8x_UART_H_
44 #if (PER_LIB_MCU_MUODEL == STC8Ax)
46 #elif (PER_LIB_MCU_MUODEL == STC8Cx)
48 #elif (PER_LIB_MCU_MUODEL == STC8Fx)
50 #elif (PER_LIB_MCU_MUODEL == STC8Gx)
52 #elif (PER_LIB_MCU_MUODEL == STC8Hx)
60 #ifndef PER_LIB_MCU_MUODEL
63 #define PER_LIB_MCU_MUODEL STC8Ax
67 #ifndef PER_LIB_UART_CTRL
70 #define PER_LIB_UART_CTRL 1
74 #ifndef PER_LIB_UART_INIT_CTRL
77 #define PER_LIB_UART_INIT_CTRL 1
81 #ifndef PER_LIB_UART_NVIC_CTRL
84 #define PER_LIB_UART_NVIC_CTRL 1
88 #ifndef PER_LIB_UART_WORK_CTRL
91 #define PER_LIB_UART_WORK_CTRL 1
143 #if (PER_LIB_MCU_MUODEL == STC8Cx ||PER_LIB_MCU_MUODEL == STC8Gx || PER_LIB_MCU_MUODEL == STC8Hx)
157 #if ( PER_LIB_UART_CTRL == 1)
159 #if (PER_LIB_UART_INIT_CTRL == 1)
210 #if (PER_LIB_UART_NVIC_CTRL == 1)
216 #define UART1_GET_RX_FLAG() (SCON & 0x01)
223 #define UART2_GET_RX_FLAG() (S2CON & 0x01)
230 #define UART3_GET_RX_FLAG() (S3CON & 0x01)
237 #define UART4_GET_RX_FLAG() (S4CON & 0x01)
244 #define UART1_CLEAR_RX_FLAG() do{SCON &= 0xFE;}while(0)
251 #define UART2_CLEAR_RX_FLAG() do{S2CON &= 0xFE;}while(0)
258 #define UART3_CLEAR_RX_FLAG() do{S3CON &= 0xFE;}while(0)
265 #define UART4_CLEAR_RX_FLAG() do{S4CON &= 0xFE;}while(0)
272 #define UART1_GET_TX_FLAG() (SCON & 0x02)
279 #define UART2_GET_TX_FLAG() (S2CON & 0x02)
286 #define UART3_GET_TX_FLAG() (S3CON & 0x02)
293 #define UART4_GET_TX_FLAG() (S4CON & 0x02)
300 #define UART1_CLEAR_TX_FLAG() do{SCON &= 0xFD;}while(0)
307 #define UART2_CLEAR_TX_FLAG() do{S2CON &= 0xFD;}while(0)
314 #define UART3_CLEAR_TX_FLAG() do{S3CON &= 0xFD;}while(0)
321 #define UART4_CLEAR_TX_FLAG() do{S4CON &= 0xFD;}while(0)
346 #if (PER_LIB_MCU_MUODEL == STC8Ax || PER_LIB_MCU_MUODEL == STC8Fx)
366 #elif (PER_LIB_MCU_MUODEL == STC8Cx || PER_LIB_MCU_MUODEL == STC8Gx || PER_LIB_MCU_MUODEL == STC8Hx)
397 #define NVIC_UART1_CTRL(run) do{ ES = run; }while(0)
405 #define NVIC_UART2_CTRL(run) do{ IE2 = (IE2 & 0xFE) | (run); }while(0)
413 #define NVIC_UART3_CTRL(run) do{ IE2 = (IE2 & 0xF7) | (run << 3); }while(0)
421 #define NVIC_UART4_CTRL(run) do{ IE2 = (IE2 & 0xEF) | (run << 4); }while(0)
429 #define NVIC_UART1_PRI(pri) \
431 IPH = (IPH & 0xEF) | ((pri & 0x02) << 3); \
432 IP = (IP & 0xEF) | ((pri & 0x01) << 4); \
441 #define NVIC_UART2_PRI(pri) \
443 IP2H = (IP2H & 0xFE) | ((pri & 0x02) >> 1); \
444 IP2 = (IP2 & 0xFE) | (pri & 0x01); \
447 #if (PER_LIB_MCU_MUODEL == STC8Cx || PER_LIB_MCU_MUODEL == STC8Gx || PER_LIB_MCU_MUODEL == STC8Hx)
454 #define NVIC_UART3_PRI(pri) \
456 IP3H = (IP3H & 0xFE) | ((pri & 0x02) >> 1); \
457 IP3 = (IP3 & 0xFE) | (pri & 0x01); \
466 #define NVIC_UART4_PRI(pri) \
468 IP3H = (IP3H & 0xFD) | (pri & 0x02); \
469 IP3 = (IP3 & 0xFD) | (pri & 0x01) << 1; \
476 #if (PER_LIB_UART_WORK_CTRL == 1)
533 #define UART1_GET_BUSY_FLAG() (G_Uart_Busy_Flg & 0x01)
543 #define UART2_GET_BUSY_FLAG() (G_Uart_Busy_Flg & 0x02)
553 #define UART3_GET_BUSY_FLAG() (G_Uart_Busy_Flg & 0x04)
563 #define UART4_GET_BUSY_FLAG() (G_Uart_Busy_Flg & 0x08)
571 #define UART1_SET_BUSY_FLAG() do{G_Uart_Busy_Flg |= 0x01;}while(0)
580 #define UART2_SET_BUSY_FLAG() do{G_Uart_Busy_Flg |= 0x02;}while(0)
589 #define UART3_SET_BUSY_FLAG() do{G_Uart_Busy_Flg |= 0x04;}while(0)
598 #define UART4_SET_BUSY_FLAG() do{G_Uart_Busy_Flg |= 0x08;}while(0)
607 #define UART1_CLEAR_BUSY_FLAG() do{G_Uart_Busy_Flg &= 0xFE;}while(0)
616 #define UART2_CLEAR_BUSY_FLAG() do{G_Uart_Busy_Flg &= 0xFD;}while(0)
625 #define UART3_CLEAR_BUSY_FLAG() do{G_Uart_Busy_Flg &= 0xFB;}while(0)
634 #define UART4_CLEAR_BUSY_FLAG() do{G_Uart_Busy_Flg &= 0xF7;}while(0)
642 #define UART1_RECEIVE_BYTE(byte) do{byte = SBUF;}while(0)
650 #define UART2_RECEIVE_BYTE(byte) do{byte = S2BUF;}while(0)
658 #define UART3_RECEIVE_BYTE(byte) do{byte = S3BUF;}while(0)
666 #define UART4_RECEIVE_BYTE(byte) do{byte = S4BUF;}while(0)
NVICPri_Type
Definition: ELL_CORE.h:99
BOOL
Definition: ELL_CORE.h:50
FSCSTATE
Definition: ELL_CORE.h:65
GPIOSWPort_Type
Definition: ELL_CORE.h:81
unsigned long uint32_t
Definition: ELL_TYPE.h:74
unsigned int uint16_t
Definition: ELL_TYPE.h:73
unsigned char uint8_t
Definition: ELL_TYPE.h:72
UART_BRTMode_Type
串口波特率发生器指令周期枚举体。
Definition: STC8x_UART.h:126
@ UART_BRT_12T
Definition: STC8x_UART.h:128
@ UART_BRT_1T
Definition: STC8x_UART.h:127
void UART4_Isr_Send_String(const uint8_t *str)
串口4发送一个字符串函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART2_Isr_Send_Array(const uint8_t *str, uint16_t len)
串口2发送一个数组函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE NVIC_UART1_Init(NVICPri_Type pri, BOOL run)
串口1中断初始化函数。
UART_BRTGen_Type
串口波特率发生器枚举体。
Definition: STC8x_UART.h:113
@ UART_BRT_TIM4
Definition: STC8x_UART.h:117
@ UART_BRT_TIM2
Definition: STC8x_UART.h:115
@ UART_BRT_TIM1
Definition: STC8x_UART.h:114
@ UART_BRT_TIM3
Definition: STC8x_UART.h:116
UARTMode_Type
串口工作模式枚举体。
Definition: STC8x_UART.h:100
@ UART_8bit_BRTx
Definition: STC8x_UART.h:102
@ UART_9bit_Fixed_BRTx
Definition: STC8x_UART.h:103
@ UART_SyncShift
Definition: STC8x_UART.h:101
@ UART_9bit_BRTx
Definition: STC8x_UART.h:104
void UART3_Isr_Send_Byte(uint8_t dat)
串口3发送一个字节函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART1_Isr_Send_String(const uint8_t *str)
串口1发送一个字符串函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART3_Isr_Send_String(const uint8_t *str)
串口3发送一个字符串函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART1_Isr_Send_Byte(uint8_t dat)
串口1发送一个字节函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE UART1_Init(const UART_InitType *uartx)
串口1初始化函数。
void UART3_Isr_Send_Array(const uint8_t *str, uint16_t len)
串口3发送一个数组函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE UART4_Init(const UART_InitType *uartx)
串口4初始化函数。
void UART1_Isr_Send_Array(const uint8_t *str, uint16_t len)
串口1发送一个数组函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART2_Isr_Send_String(const uint8_t *str)
串口2发送一个字符串函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE GPIO_UART4_SWPort(GPIOSWPort_Type port)
串口4切换复用IO函数。
uint8_t G_Uart_Busy_Flg
串口忙标志位,这是ELL库自定义从防止多串口冲突的变量。
FSCSTATE NVIC_UART4_Init(BOOL run)
串口4中断初始化函数。
FSCSTATE NVIC_UART2_Init(NVICPri_Type pri, BOOL run)
串口2中断初始化函数。
void UART4_Isr_Send_Array(const uint8_t *str, uint16_t len)
串口4发送一个数组函数, 需要开启中断,并在中断服务函数中清除发送标志位。
void UART4_Isr_Send_Byte(uint8_t dat)
串口4发送一个字节函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE UART2_Init(const UART_InitType *uartx)
串口2初始化函数。
void UART2_Isr_Send_Byte(uint8_t dat)
串口2发送一个字节函数, 需要开启中断,并在中断服务函数中清除发送标志位。
FSCSTATE GPIO_UART2_SWPort(GPIOSWPort_Type port)
串口2切换复用IO函数。
FSCSTATE NVIC_UART3_Init(BOOL run)
串口3中断初始化函数。
FSCSTATE GPIO_UART3_SWPort(GPIOSWPort_Type port)
串口3切换复用IO函数。
FSCSTATE GPIO_UART1_SWPort(GPIOSWPort_Type port)
串口1切换复用IO函数。
FSCSTATE UART3_Init(const UART_InitType *uartx)
串口3初始化函数。
串口初始化结构体句柄,初始化时请定义该句柄,并用其地址来传参。
Definition: STC8x_UART.h:140
BOOL RxEnable
Definition: STC8x_UART.h:151
BOOL BRTDouble
Definition: STC8x_UART.h:147
UART_BRTMode_Type BRTMode
Definition: STC8x_UART.h:146
BOOL Relay
Definition: STC8x_UART.h:150
uint32_t BaudRate
Definition: STC8x_UART.h:148
UARTMode_Type Mode
Definition: STC8x_UART.h:141
UART_BRTGen_Type BRTGen
Definition: STC8x_UART.h:142
uint8_t BRTGenClkDiv
Definition: STC8x_UART.h:144
BOOL MulitComm
Definition: STC8x_UART.h:149