0% found this document useful (0 votes)
29 views3 pages

Uart

The document contains code for initializing UART communication on an ARM microcontroller at 9600 baud and functions for sending and receiving characters via UART. The main function initializes UART, prints a message, and enters a loop that echoes received characters back.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Uart

The document contains code for initializing UART communication on an ARM microcontroller at 9600 baud and functions for sending and receiving characters via UART. The main function initializes UART, prints a message, and enters a loop that echoes received characters back.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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