Using UART protocol to transmit data to PC Terminal in LPC2148

Introducing the concept of a Phase Locked Loop to increase the clock given to a microcontroller, here in this example we have increased the frequency upto 60 MHz from 12 MHz using a PLL. The main purpose of a PLL circuit is to synchronize an output oscillator signal with a reference signal.
Then using VPBDIV register (VLSI Peripheral Bus Divider), it is divided by a factor of 4 to get to 15 MHz frequency which will be the Peripheral Clock frequency. So PLL0CON (PLL Control Register) Register is used to enable and connect the PLL. PLL0CFG (PLL Configuration Register) contains the PLL Multiplier (MSEL) and PLL Divider (PSEL) values to bring the clock to 60 MHz.
PLL0FEED (PLL Feed Register) is given a sequence of values for the changes to take effect.

PLL0STAT reflects the information of Control and Configuration Register. The 10th bit is checked to see if the PLL is locked on to the desired frequency.


U0FCR (UART 0 FIFO Control Register), U0LCR (UART 0 Line Control Register), U0DLL (UART 0 Divisor Latch LSB Register), U0DLM (UART 0 Divisor Latch MSB Register) are the registers used to configure UART.
DLAB bit is a divisor latch access bit which enables U0DLM and U0DLL to be set correctly to provide appropriate baud rate. This is enabled in the Line Control Register.
Then there is a status register (U0LSR), which is used to check whether the buffer is empty or full to carry out Transmit and Receive operations. U0THR contains the data to be transmitted across and U0RBR contains data which is received.


//TO TRANSMIT DATA TO PC TERMINAL USING UART
#include<stdio.h>
#include<lpc214x.h>
#include"lcd.h"
void setClck()
{
PLL0CON=0x01;// ENABLE
PLL0CFG=0x24;// 60 MHZ
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(PLL0STAT & (1<<10)==0);
PLL0CON=0x03;// ENABLE AND CONNECT
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x00;// DIVIDE FREQ BY 4

}
void serial_init()
{
setClck();// SET AT 15 MHZ
U0FCR=0x07;// ENABLE AND CLEAR FIFO'S OF RX AND TX
U0LCR=0x83;// ENABLE DLAB BIT AND SET WORD AS 8 BIT
U0DLL=0x62;
U0DLM=0x00;
U0LCR=0x03;
}
void uart_tx(unsigned char a)
{

while(U0LSR & (1<<5)==0);// WAIT TILL TX BUFF BECOMES EMPTY
U0THR=a;

}
void uart_tx_str(unsigned char b[])
{
int i=0;
while(b[i]!='\0')
{
uart_tx(b[i]);
i++;
}
}


unsigned char uart_rx(void)
{
while((U0LSR & (0x01))==0);
return U0RBR;
}
int main()
{
unsigned char c;
PINSEL0=0x00000005;

serial_init();
lcd_init();
lcd_data('A');
delay(10);
lcd_cmd(0xC0);
while(1)
{
//uart_tx_str("Hello World");
//printf("%c",c);
c=uart_rx();
uart_tx(c);
lcd_data(c);
delay(10);
}
}


Simulation



No comments:

Post a Comment