Unit3 - S5 UART
Unit3 - S5 UART
1. Buffer Registers
2. Line control Register (Line/bus)
3. Baud rate Register
4. Status Register
Company Confidential www.industry-mitra.com 3
Line Control Register
LCD
Command Register 0
RS
Data Register 1
• Bit 0: This bit is used to enable/disable the FIFO for the data
received/transmitted
• 0--FIFO is Disabled
• 1--FIFO is Enabled for both Rx and Tx
• Bit 1: This is used to clear the 16 byte Rx FIFO
• 0 – No impact
• 1 – clears Rx FIFO
• Bit 2: This is used to clear the 16 byte Tx FIFO
• 0 – No impact
• 1 – clears Tx FIFO
U0THR=‘A’;
char ch;
ch=U0RBR
Company Confidential 16
UART – Block Diagram
//1 - led on
//2 - led off
#include <LPC21xx.H>
void init_uart0();
void init_uart0(){
PINSEL0=0x00000005;
U0LCR=0x83;
U0DLM=0x00;
U0DLL=0x61;
U0LCR=0x03;
}
void delay(int count){
int i,j;
for(i =0;i < count;i++)
for(j = 0;j < 5000;j++);
}
int main(){
char ch;
IO0DIR=0xFF; //Set the Direction of Pin as out
IOCLR0=0xFF; //Set the Initial state as off
init_uart0();
while(1){
while(!(U0LSR&0x01)); //chk whether receiver buffer is full or not
ch=U0RBR;
if(ch=='1'){
IOSET0=1<<4;
}
if(ch=='2'){
IOCLR0=1<<4;
}
}
}
void init_uart0(){
PINSEL0=0x00000005;
U0LCR=0x83;
U0DLM=0x00;
U0DLL=0x61;
}
int main(){
char ch;
init_uart0();
while(1){
while(!(U0LSR&0x01)); //chk whether receiver buffer is full or not
ch=U0RBR;
while(!(U0LSR&0x20)); //chk whether tr buff is empty
U0THR=ch;
}
}
U0LCR=0x03;