📄 serial.c
字号:
/******************************************************************************/
/* This file is part of the uVision/ARM development tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
/******************************************************************************/
/* */
/* SERIAL.C: Low Level Serial Routines */
/* */
/******************************************************************************/
//#include <LPC21xx.H> /* LPC21xx definitions */
#include "lpc210x.h"
#define CR 0x0D
void init_serial_1 (void) { /* Initialize Serial Interface */
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
UART1_LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
UART1_DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
UART1_LCR = 0x03; /* DLAB = 0 */
}
int putchar_1 (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(UART1_LSR & 0x20));
UART1_THR = CR; /* output CR */
}
while (!(UART1_LSR & 0x20));
return (UART1_THR = ch);
}
int getchar_1 (void) { /* Read character from Serial Port */
while (!(UART1_LSR & 0x01));
return (UART1_RBR);
}
// ****************************
void init_serial_0 (void) { /* Initialize Serial Interface */
PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 */
UART0_LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
UART0_DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
UART0_LCR = 0x03; /* DLAB = 0 */
// defines
// UART_BAUD calculates a division rate given a baud rate
// for use with uart0Init() and uart1Init()
// example: uart0Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
//
// BEWARE: additional code will be generated if 'baud' is not a contant
//#define UART_BAUD(baud) (uint16_t)((PCLK+baud*8L)/(baud*16))
// set the baudrate
// U0LCR = ULCR_DLAB_ENABLE; // select divisor latches
// U0DLL = (uint8_t)baud; // set for baud low byte
// U0DLM = (uint8_t)(baud >> 8); // set for baud high byte
}
int putchar_0 (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(UART0_LSR & 0x20));
UART0_THR = CR; /* output CR */
}
while (!(UART0_LSR & 0x20));
return (UART0_THR = ch);
}
int getchar_0 (void) { /* Read character from Serial Port */
while (!(UART0_LSR & 0x01));
return (UART0_RBR);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -