📄 uart.h
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: uart.h
** Latest modified Date: 2008-8-20
** Latest Version: 1.0
** Descriptions: 串口外设的头文件
**
**--------------------------------------------------------------------------------------------------------
** Created by: CaiWenqi
** Created date: 2008-8-20
** Version: 1.0
** Descriptions: The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
*********************************************************************************************************/
#ifndef __uart_h
#define __uart_h
/*********************************************************************************************************
Config for UART_LCR Register
*********************************************************************************************************/
#define LEN_5BIT 0 /* 配置数据长度 */
#define LEN_6BIT 1
#define LEN_7BIT 2
#define LEN_8BIT 3
#define STOP_2BIT (1 << 2) /* 配置停止位2bit */
#define PARITY_EN (1 << 3) /* 是否校验 */
#define PARITY_E (1 << 4) /* 偶校验 */
#define BREAK_EN (1 << 6) /* 强制TX为0 */
/*********************************************************************************************************
Config for UART_MCR Register
*********************************************************************************************************/
#define LOOP_EN (1 << 4) /* 接收脱离RX,连接TX(自发自收) */
/*********************************************************************************************************
Config for UART_LSR Register
*********************************************************************************************************/
#define RBR_NEW 1 /* RBR寄存器接收到新数据 */
#define RBR_OE (1 << 1) /* RBR数据未读出就被新数据覆盖 */
#define PARITY_ERR (1 << 2) /* 校验错误 */
#define FRAME_ERR (1 << 3) /* 帧错误(停止位无效) */
#define BREAK_INT (1 << 4) /* 检测到间隔中断 */
#define THR_EMPTY (1 << 5) /* 发送保持寄存器为空 */
#define TSR_THR_EMPTY (1 << 6) /* 发送保持和移位寄存器均空 */
/*********************************************************************************************************
Config for UART_IER Register
*********************************************************************************************************/
#define RBFI_EN 1 /* 允许接收到新数据到RBR时中断 */
#define TBEI_EN (1 << 1) /* 允许发送保持寄存器为空时中断 */
#define LSI_EN (1 << 2) /* 允许接收线状态中断 */
/*********************************************************************************************************
Config for UART_IIR Register
*********************************************************************************************************/
#define HAVE_INT 1 /* 有中断发生 */
#define HAVE_THRE_INT (1 << 1) /* 有THRE中断 */
#define HAVE_RBR_INT (2 << 1) /* 有RBR中断 */
#define HAVE_LSR_INT (3 << 1) /* 有LSR中断 */
/*********************************************************************************************************
define for function
*********************************************************************************************************/
#define PARITY_DIS 0
#define PARITY_ODD 1
#define PARITY_EVEN 2
/*********************************************************************************************************
** Function name: uartConfig
** Descriptions: 设置UART基本通讯参数
** Input parameters: usBaud : 设置的波特率
** usByteLength : 可取 5, 6 ,7 ,8
** usStopbit : 可取 1, 2
** usParityCheck : PARITY_DIS -- 不进行校验
PARITY_ODD -- 进行奇校验
PARITY_EVEN-- 进行偶校验
** Output parameters: NONE
** Returned value: true -- 成功设置,false -- 设置失败
*********************************************************************************************************/
extern uint16 uartConfig (uint16 usBaud,
uint16 usByteLength,
uint16 usStopbit,
uint16 usParityCheck);
/*********************************************************************************************************
** Function name: uartSendChar
** Descriptions: 发送单个字符
** Input parameters: cChar : 发送字符
** Output parameters: NONE
** Returned value: NONE
*********************************************************************************************************/
extern void uartSendChar(char cChar);
/*********************************************************************************************************
** Function name: uartSendStr
** Descriptions: 发送字符串
** Input parameters: cStr : 字符串指针
** Output parameters: NONE
** Returned value: NONE
*********************************************************************************************************/
extern void uartSendStr(char *cStr);
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -