SCI1_UART.h 2.5 KB
Newer Older
崔立宝's avatar
崔立宝 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/******************************************************************************
文 件 名:SCI1_UART.h
功能描述:UART模式SCI1驱动库头文件
作    者:张暄
版    本:V1.0
日    期:2016.11.17
******************************************************************************/

#ifndef _SCI1_UART_H_
#define _SCI1_UART_H_

#include "GPIO.h"
#include "CRG.h"
#include "comdef.h"

/******************************************************************************
UART 配置
******************************************************************************/
#define   SCI1_GPIO_SELECT                  SCI1_PH1_PH0
#define   SCI1_BAUD_RATE                    19200
#define   SCI1_FORMAT                       SCI1_8BIT_1STOP
#define   SCI1_PARITY_FUNC                  SCI1_PARITY_FUNC_DISABLE
#define   SCI1_PARITY_TYPE                  SCI1_EVEN_PARITY

#define   SCI1_Tx_BUFFER_SIZE               32

/******************************************************************************
UART 配置选项
******************************************************************************/
/*** SCI1可用的GPIO ***/
#define   SCI1_PH1_PH0                      0x00
#define   SCI1_PM1_PM0                      0x01

/*** UART格式 ***/
#define   SCI1_8BIT_1STOP                   0x00
#define   SCI1_9BIT_1STOP                   0x10

/*** 奇偶校验使能 ***/
#define   SCI1_PARITY_FUNC_DISABLE          0x00
#define   SCI1_PARITY_FUNC_ENABLE           0x02

/*** 奇偶校验选择 ***/
#define   SCI1_EVEN_PARITY                  0x00
#define   SCI1_ODD_PARITY                   0x01

/******************************************************************************
寄存器值预定义
******************************************************************************/
#define   SCI1_BAUD_RATE_REG                ((uint16_t)(BUSCLK / 16 / SCI1_BAUD_RATE) & 0x1FFF)
#define   SCI1_CFG_REG                      (SCI1_FORMAT | SCI1_PARITY_FUNC | SCI1_PARITY_TYPE)

/******************************************************************************
发送缓存结构
******************************************************************************/
typedef struct
{
  uint8_t Data[SCI1_Tx_BUFFER_SIZE];
  uint8_t Len;
} SCI1TxBufferStruct;

/******************************************************************************
函数声明
******************************************************************************/
void SCI1_UART_Byte_Rx(uint8_t Data);
void SCI1_UART_Byte_Tx(uint8_t Data);
void SCI1_UART_Block_Tx(uint8_t *Data, uint8_t Len);
uint8_t SCI1_UART_Get_Tx_Buffer_Status(void);
void SCI1_UART_Init(void);

#endif