📄 uart0.h
字号:
/****************************************Copyright (c)*************************
** Guangzhou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info------------------------------------------------------
** File Name: UART.h
** Last modified Date: 2004-11-29
** Last Version: 1.0
** Description: operater UART for LPC2xxx
**
**-----------------------------------------------------------------------------
** Created date: 2004-11-29
** Version: 1.0
** Description: operater UART for LPC2xxx
**
**-----------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
******************************************************************************/
#ifndef __UART_H
#define __UART_H
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
// 串口接收缓冲区大小
#ifndef UART_RECV_BUF_SIZE
#define UART_RECV_BUF_SIZE 50
#endif
// 线控制寄存器U0LCR各位
enum {
// 字长度选择
UART_WORD_LEN_5 = 0x00,
UART_WORD_LEN_6 = 0x01,
UART_WORD_LEN_7 = 0x02,
UART_WORD_LEN_8 = 0x03,
// 停止位选择
UART_STOP_BIT_1 = 0x00,
UART_STOP_BIT_2 = 0x04,
// 奇偶使能
UART_PARITY_EN = 0x08,
// 奇偶选择
UART_ODD = 0x00,
UART_EVEN = 0x10,
UART_FORCE1 = 0x20,
UART_FORCE0 = 0x30,
// 间隔使能
UART_INTERVAL_EN = 0x40,
// 除数锁存访问位使能
UART_RBR_EN = 0x80
};
// 中断标识寄存器U0IIR各位
enum
{
UART_IIR_FLAG = 0x01, // 中断标识,有中断被挂起为0。
UART_IIR_THRE = 0x02, // 发送寄存器空中断
UART_IIR_RDA = 0x04, // 接收数据可用中断
UART_IIR_RLS = 0x06, // 接收线状态中断
UART_IIR_CTI = 0x0C // 字符超时指示
};
// FIFO控制寄存器U0FCR(为与线控制寄存器合并成一个参数,各位左移8位)
enum
{
UART_FIFO_EN = 0x0100,
UART_FIFO_1 = 0x0000,
UART_FIFO_4 = 0x4000,
UART_FIFO_8 = 0x8000,
UART_FIFO_14 = 0xC000
};
// 线状态寄存器U0LSR各位
enum
{
UART_LSR_RDR = 0x01, // 接收数据就绪
UART_LSR_OE = 0x02, // 溢出错误
UART_LSR_PE = 0x04, // 奇偶错误
UART_LSR_FE = 0x08, // 帧错误
UART_LSR_BI = 0x10, // 间隔错误
UART_LSR_THRE = 0x20, // 发送保持寄存器空
UART_LSR_TEMT = 0x40, // 发送器空
UART_LSR_RXFE = 0x80 // 溢出错误
};
// 标准通信波特率(Communicate Baudrate)
enum
{
CBR_110 = 110,
CBR_300 = 300,
CBR_1200 = 1200,
CBR_2400 = 2400,
CBR_4800 = 4800,
CBR_9600 = 9600,
CBR_14400 = 14400,
CBR_19200 = 19200,
CBR_38400 = 38400,
CBR_56000 = 56000,
CBR_57600 = 57600,
CBR_115200 = 115200
};
// 默认配置
#define UART_DEFAULT_CFG (UART_WORD_LEN_8 | UART_STOP_BIT_1 | UART_FIFO_EN | UART_FIFO_8)
/******************************************************************************
** Function name: UART0_Init
** Descriptions: Initialize the UART, Set baudrate and other config.
(初始化串口,设置波特率和其它配置)
** Input: nBaudrate: the communicate baudrate (波特率)
** nConfig:the other config, eg parity... (其它配置,如奇偶校验等)
** Output: none (无)
******************************************************************************/
void UART0_Init(uint32 nBaudrate, uint16 nConfig);
/******************************************************************************
** Function name: UART0_Send
** Descriptions: Send datum with UART (从串口发送数据)
** Input: pBuf: the point of datum (指向要发送的数据的指针)
** nLen: the length of datum (要发送的数据的长度,以字节为单位)
** Output: return: the count of sended datum in fact (实际已发送数据的长度)
******************************************************************************/
uint32 UART0_Send(const void *pBuf, uint32 nLen);
/******************************************************************************
** Function name: UART0_Receive
** Descriptions: Receive datum from UART (从串口接收数据)
** Input: pBuf: the point of datum (接收数据缓冲区的指针)
** nLen: the length of datum (要接收的数据的长度,以字节为单位)
** Output: return: the count of sended datum in fact (实际已接收数据的长度)
******************************************************************************/
uint32 UART0_Receive(void *pBuf, uint32 nLen);
/******************************************************************************
** Function name: UART0_SetTimeout
** Descriptions: set the timeout of receive data (设置接收数据的超时时间)
** Input: nTimeout: the timeout value (超时时间值,以ms为单位)
** Output: NONE (无)
******************************************************************************/
void UART0_SetTimeout(uint32 nTimeout);
#ifdef __cplusplus
}
#endif
#endif // __UART_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -