Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Lpc2148 uart interrupt

Status
Not open for further replies.

rngarun

Newbie level 2
Newbie level 2
Joined
Apr 12, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,308
Hello All

I am using LPC2148 and I am struggling to find an example code for Interrupt driver UART. There are some samples which are not working. Can anyone send me a small example using Interrupt driven uart0 for keil compiler please.

Thanks
 

This code working in keil compiler .. for UART0 using BAUD RATE 9600

You can able to check in Hyper Terminal

Code:
#include  <lpc214x.h>		 //Includes LPC2148 register definitions

 
#define Fosc            12000000                    
#define Fcclk           (Fosc * 5)                  
#define Fcco            (Fcclk * 2)                 
#define Fpclk           (Fcclk / 4) * 1             

#define  UART_BPS	9600	 //Set Baud Rate here

const unsigned char SEND_STRING[] = "UART TEST";
const unsigned char SEND_STRING1[] = "Test Passed\n";

unsigned char received_data;
void  Delay_Ticks(unsigned int Delay)  //Function to generate finite delay
{  
   unsigned int i;
   for(; Delay>0; Delay--) 
   for(i=0; i<50000; i++);
}


void  Init_UART0(void)					//This function setups UART0
{  
   unsigned int Baud16;
   U0LCR = 0x83;		            // DLAB = 1
   Baud16 = (Fpclk / 16) / UART_BPS;  
   U0DLM = Baud16 / 256;							
   U0DLL = Baud16 % 256;						
   U0LCR = 0x03;
}
				

void  UART0_SendByte(unsigned char data)	   //A function to send a byte on UART0
{  
   U0THR = data;				    
   while( (U0LSR&0x40)==0 );	    
}


void  UART0_SendStr(const unsigned char *str)	 //A function to send a string on UART0
{  
   while(1)
   {  
      if( *str == '\0' ) break;
      UART0_SendByte(*str++);	    
   }
}


int  main(void)
{  
   PINSEL0 = 0x00000005;		    // Enable UART0 Rx and Tx pins
   PINSEL1 = 0x00000000;
   PINSEL2 = 0x00000000;

   Init_UART0();
   while(1)
   {
   UART0_SendStr(SEND_STRING);
   while((U0LSR&0x01)==0);
   received_data = U0RBR;
   UART0_SendByte(received_data);
   while((U0LSR&0x01)==0);
   received_data = U0RBR;
   UART0_SendByte(received_data);

   }
   return(0);
}


I Hope its helps you..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top