-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerial.c
65 lines (52 loc) · 2.55 KB
/
Serial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/******************************************************************************/
/* 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. */
/******************************************************************************/
#include <LPC23xx.H> /* LPC23xx definitions */
#define UART1 /* Use UART 0 for printf */
/* If UART 0 is used for printf */
#ifdef UART0
#define UxFDR U0FDR
#define UxLCR U0LCR
#define UxDLL U0DLL
#define UxDLM U0DLM
#define UxLSR U0LSR
#define UxTHR U0THR
#define UxRBR U0RBR
/* If UART 1 is used for printf */
#elif defined(UART1)
#define UxFDR U1FDR
#define UxLCR U1LCR
#define UxDLL U1DLL
#define UxDLM U1DLM
#define UxLSR U1LSR
#define UxTHR U1THR
#define UxRBR U1RBR
#endif
void init_serial (void) { /* Initialize Serial Interface */
#ifdef UART0
PINSEL0 |= 0x00000050; /* Enable TxD0 and RxD0 */
#elif defined (UART1)
PINSEL0 |= 0x40000000; /* Enable TxD1 */
PINSEL1 |= 0x00000001; /* Enable RxD1 */
#endif
UxFDR = 0; /* Fractional divider not used */
UxLCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
UxDLL = 78; /* 9600 Baud Rate @ 12.0 MHZ PCLK */
UxDLM = 0; /* High divisor latch = 0 */
UxLCR = 0x03; /* DLAB = 0 */
}
/* Implementation of putchar (also used by printf function to output data) */
int sendchar (int ch) { /* Write character to Serial Port */
while (!(UxLSR & 0x20));
return (UxTHR = ch);
}
int getkey (void) { /* Read character from Serial Port */
while (!(UxLSR & 0x01));
return (UxRBR);
}