Professional Documents
Culture Documents
#Include "Stdio.h" #Include "LPC214x.h" #Include "UART.h"
#Include "Stdio.h" #Include "LPC214x.h" #Include "UART.h"
1 #include "stdio.h"
2 #include "LPC214x.h"
3 #include "UART.h"
4
5
6 void UART1_isr(void) __irq
7 {
8 UART0_PutChar(UART1_GetChar());
9 VICVectAddr = 0;
10 }
11
12
13 void Uart0Init(unsigned int baudrate)
14 {
15 unsigned int FDiv;
16 PINSEL0 |= 0x00000005; //Enable RxD0 and TxD0
17 U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
18 FDiv = (15000000 / 16 ) / baudrate ; //
19 U0DLM = FDiv /256; //0x00;
20 U0DLL = FDiv %256; //0x97;
21 U0LCR = 0x03; // DLAB = 0
22 }
23
24
25 void Uart1Init(unsigned int baudrate)
26 {
27 unsigned int FDiv;
28 PINSEL0 |= 0x00050000; //Enable RxD1 and TxD1
29 U1LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
30 FDiv = (15000000 / 16 ) / baudrate ; //
31 U1DLM = FDiv /256; //0x00;
32 U1DLL = FDiv %256; //0x97;
33 U1LCR = 0x03; // DLAB = 0
34
35 U1IER = 0x01;
36 VICVectCntl1 = 0x20 | 7;
37 VICVectAddr1 = (unsigned int)UART1_isr;
38 VICIntEnable |= 1<<7;
39 }
40
41
42 unsigned char UART0_GetChar(void)
43 {
44 while(!(U0LSR & 0x01));
45 return(U0RBR);
46 }
47
48 unsigned char UART1_GetChar(void)
49 {
50 while(!(U1LSR & 0x01));
51 return(U1RBR);
52 }
53
54 unsigned char UART0_PutChar(unsigned char Ch)
55 {
56 while(!(U0LSR & 0x20));
57 U0THR = Ch;
58 return Ch;
59 }
60
61
62 unsigned char UART1_PutChar(unsigned char Ch)
63 {
64 while(!(U1LSR & 0x20));
65 U1THR = Ch;
66 return Ch;
67 }
68
69 void UART1_PutS(unsigned char *Ch)
70 {