66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
#ifndef __UART_H__
|
|
#define __UART_H__
|
|
|
|
#include "common.h"
|
|
#include "tim.h"
|
|
|
|
#define UART1_CLEAR_RX_FLAG (SCON &= ~0x01)
|
|
#define UART2_CLEAR_RX_FLAG (S2CON &= ~0x01)
|
|
#define UART3_CLEAR_RX_FLAG (S3CON &= ~0x01)
|
|
#define UART4_CLEAR_RX_FLAG (S4CON &= ~0x01)
|
|
|
|
#define UART1_CLEAR_TX_FLAG (SCON &= ~0x02)
|
|
#define UART2_CLEAR_TX_FLAG (S2CON &= ~0x02)
|
|
#define UART3_CLEAR_TX_FLAG (S3CON &= ~0x02)
|
|
#define UART4_CLEAR_TX_FLAG (S4CON &= ~0x02)
|
|
|
|
|
|
#define UART1_GET_RX_FLAG (SCON & 0x01)
|
|
#define UART2_GET_RX_FLAG (S2CON & 0x01)
|
|
#define UART3_GET_RX_FLAG (S3CON & 0x01)
|
|
#define UART4_GET_RX_FLAG (S4CON & 0x01)
|
|
|
|
#define UART1_GET_TX_FLAG (SCON & 0x02)
|
|
#define UART2_GET_TX_FLAG (S2CON & 0x02)
|
|
#define UART3_GET_TX_FLAG (S3CON & 0x02)
|
|
#define UART4_GET_TX_FLAG (S4CON & 0x02)
|
|
|
|
|
|
typedef enum //枚举串口号
|
|
{
|
|
UART_1,
|
|
UART_2,
|
|
UART_3,
|
|
UART_4,
|
|
}UARTN_enum;
|
|
|
|
typedef enum //枚举串口引脚
|
|
{
|
|
UART1_RX_P30, UART1_TX_P31, //只能使用同一行的RX和TX引脚号。不允许混用
|
|
UART1_RX_P36, UART1_TX_P37, //例如:UART1_RX_P30,UART1_TX_P37。这样不行。
|
|
UART1_RX_P16, UART1_TX_P17,
|
|
UART1_RX_P43, UART1_TX_P44,
|
|
|
|
UART2_RX_P10, UART2_TX_P11,
|
|
UART2_RX_P46, UART2_TX_P47,
|
|
|
|
UART3_RX_P00, UART3_TX_P01,
|
|
UART3_RX_P50, UART3_TX_P51,
|
|
|
|
UART4_RX_P02, UART4_TX_P03,
|
|
UART4_RX_P52, UART4_TX_P53,
|
|
|
|
|
|
}UARTPIN_enum;
|
|
|
|
extern uint8 busy[5];
|
|
|
|
|
|
void uart_init(UARTN_enum uart_n, UARTPIN_enum uart_rx_pin, UARTPIN_enum uart_tx_pin, uint32 baud,TIMN_enum tim_n);
|
|
void uart_putchar(UARTN_enum uart_n,uint8 dat);
|
|
void uart_putstr(UARTN_enum uart_n,uint8 *str);
|
|
void uart_putbuff(UARTN_enum uart_n,uint8 *p,uint32 len);
|
|
|
|
|
|
#endif
|