Uart

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Program

#include "lpc214x.h"

#include <stdio.h>

void UartInit(unsigned int ); //setting the baud rate for 9600 baud

unsigned char UART_GetChar(void);

int UART_PutChar(unsigned char);

/*================================================================================
===*/

int main(void)

UartInit(9600); // initialise the UART0

printf("\r\nThis is a Demonstration for \r\nUART peripheral for LPC2148\r\nDone on


SBC_ARM7 Board \r\n");

printf("\r\nHit any Key on your PC Keyboard to see result\r\n");

while(1)

UART_PutChar(UART_GetChar()+1); //Echo

void UartInit(unsigned int baudrate) //setting the baud rate for 115200 baud

unsigned int FDiv;

PINSEL0 = PINSEL0 & 0xFFFFFFF0; // modify the value

PINSEL0 = PINSEL0 | 0x00000005; // set the functionality of the TxD and Rxd Pin :01
//set the baud rate

U0LCR = 0x83; // Line control register :DLAB=1 ; 8 bits ; 1 stop bit ; no


parity

FDiv = (15000000 / 16 ) / baudrate ; //

U0DLM = FDiv /256; //0x00;

U0DLL = FDiv %256; //0x97;

U0LCR = 0x03; // Line control register :DLAB=0 ; 8 bits ; 1 stop bit ; no


parity

U0TER = 0x80;

unsigned char UART_GetChar(void)

while(!(U0LSR & 0x1));

return(U0RBR);

int UART_PutChar(unsigned char Ch)

while(!(U0LSR & 0x20));

return( U0THR = Ch);

int fputc(int ch, FILE *f)

return (UART_PutChar(ch));

struct __FILE { int handle; };

FILE __stdout;
OUTPUTS :

You might also like