📄 serial.c
字号:
// *********************************
// LPC2000 SYSTEM WITHOUT OS
// FILE: SERIAL.C
// MODIFIED: ZPCYP 2005-3-16 20:16
// *********************************
/*
** This implements a simple (polled) RS232 serial driver.
**
** It outputs single characters on Serial Port 0,
** 8 bit, no parity, 1 stop bit.
**
** Initialize the port with init_serial_0() before calling sendchar().
**
** To monitor the characters output, use a null-modem cable to
** connect Serial Port 0 to an RS232 terminal or PC running a
** terminal emulator, e.g. HyperTerminal.
*/
#include "config.h"
#include "lpc22xx.h"
#include "main.h"
void init_serial_0(void)
{
U0LCR = 0x83; // DLAB = 1
U0DLM = (F_PCLK / 16 / UART0_BAUD) >> 8; // Set baud rate
U0DLL = (F_PCLK / 16 / UART0_BAUD) & 0xff;
U0LCR = 0x03; // N, 8, 1
//中断设置
VICIntSelect = 0x00;//所有中断通道设置为IRQ中断
VICVectCntl0 = 0x26;//定时器0中断通道分配最高优先级(向量控制器0)
// VICVectAddr0 = (unsigned int)UART0_Receive;//中断入口地址
VICIntEnable = 0x00000040 ;//使能UART0中断
}
void sendchar(char *ch)
{
while ((U0LSR & 0x40) == 0);
if (*ch == '\n') // Replace line feed with '\r'
*ch = '\r';
// if (*ch == '\n') {
// U0THR = '\r';
// while ((U0LSR & 0x40) == 0);
// }
U0THR = *ch; // Transmit
}
int receivechar(void) {
while ((U0LSR & 0x01) == 0);
return U0RBR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -