📄 serial.c
字号:
/******************************************************************************/
/* SERIAL.C: Low Level Serial Routines */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
//<<< Use Configuration Wizard in Context Menu >>>
#include <LPC21xx.H> /* LPC21xx definitions */
#include "serial.h"
#define CR 0x0D
/* implementation of putchar (also used by printf function to output data) */
int sendchar (int ch) /* Write character to Serial Port */
{
if (ch == '\n') {
while (!(U0LSR & 0x20));
U0THR = CR; /* output CR */
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getkey (void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void serial_init() /* initialize the serial interface */
{
PINSEL0|=0X00000005;
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
// <o> Baudrate Selection
// <195=> 4800 bps
// <97=> 9600 bps
// <65=> 14400 bps
// <49=> 19200 bps
// <24=> 38400 bps
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
//U0DLL = 78; /* 9600 Baud Rate @ 12MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -