⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.h

📁 FAT16 Filesystem on Philips LPC2000 series processors
💻 H
字号:
#ifndef INC_UART_H
#define INC_UART_H

#include "types.h"

#define UART_BAUD(baud) (uint16_t)((PCLK / ((baud) * 16.0)) + 0.5)

///////////////////////////////////////////////
// Definitions for typical UART 'baud' settings
///////////////////////////////////////////////
#define B1200         UART_BAUD(1200)
#define B9600         UART_BAUD(9600)
#define B19200        UART_BAUD(19200)
#define B38400        UART_BAUD(38400)
#define B57600        UART_BAUD(57600)
#define B115200       UART_BAUD(115200)

////////////////////////////////////////////////
// Definitions for typical UART 'mode' settings
////////////////////////////////////////////////
#define UART_8N1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_1)
#define UART_7N1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_1)
#define UART_8N2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_2)
#define UART_7N2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_2)
#define UART_8E1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_1)
#define UART_7E1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_1)
#define UART_8E2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_2)
#define UART_7E2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_2)
#define UART_8O1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_1)
#define UART_7O1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_1)
#define UART_8O2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_2)
#define UART_7O2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_2)

/////////////////////////////////////////////////
// Definitions for typical UART 'fmode' settings
/////////////////////////////////////////////////
#define UART_FIFO_OFF (0x00)
#define UART_FIFO_1   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG1)
#define UART_FIFO_4   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG4)
#define UART_FIFO_8   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG8)
#define UART_FIFO_14  (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG14)

///////////////////////////////////////////////////////////
// init a serial port, typical function call is:
// serial0Init(UART_BAUD(9600), UART_8N1, UART_FIFO_8)
///////////////////////////////////////////////////////////

void serial0Init(uint16_t baud, uint8_t mode, uint8_t fmode);
void serial0Write (const uchar * buff, int count);
int serial0Read (uchar * buff, int count);
void serial0Putch (const uchar ch);
void serial0Puts (const uchar *str);
bool serial0RxHasData (void);
bool serial0TxHasData (void);
int serial0RxCharCount (void);
uchar serial0Getch (void);
void serial0ISR (void) __attribute__((interrupt));

void serial1Init(uint16_t baud, uint8_t mode, uint8_t fmode);
void serial1Write (const uchar * buff, int count);
void serial1Putch (const uchar ch);
void serial1Puts (const uchar *str);
bool serial1RxHasData (void);
bool serial1TxHasData (void);
uchar serial1Getch (void);
void serial1ISR (void) __attribute__((interrupt));

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -