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

LPC2148 UART Programs Only

The document contains two programs for transmitting messages using the UART of LPC2148 microcontroller, one using interrupts and the other without. The first program initializes the serial interface, sets up an interrupt for transmitting characters, and sends a predefined message. The second program allows for receiving a password from the user and compares it to a predefined value, sending a corresponding message based on the comparison result.
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)
20 views3 pages

LPC2148 UART Programs Only

The document contains two programs for transmitting messages using the UART of LPC2148 microcontroller, one using interrupts and the other without. The first program initializes the serial interface, sets up an interrupt for transmitting characters, and sends a predefined message. The second program allows for receiving a password from the user and compares it to a predefined value, sending a corresponding message based on the comparison result.
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 to transmit the message using UART of LPC2148 (With interrupt)

#include <lpc214x.h>
int i;
unsigned char y;
unsigned char n[10]={'S','A','S','T','R','A'};

void threint(void) __irq { /* Interrupt routine*/


y=n[i];
U0THR = y;//n[i];
i++;
VICVectAddr=0;
}
void init_serial (void) { /* Initialize Serial Interface */
PINSEL0 = 1; /* Enable TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
int main()
{
init_serial();
U0IER=0X00000002; // THRE interrupt enabled
VICVectAddr2=(unsigned long)threint; // THRE interrupt service routine called
VICVectCntl2=0x00000026; // IRQ Slot reserved for THRE interrupt & slot enabled
VICIntEnable=1<<6; // Global THRE interrupt enabled for THRE interrupt
U0THR =n[0]; // First character placed in THR
i=1;
while(i<5); // Wait for transmitting all characters
U0IER=0X00000000; // THRE interrupt disabled
while(1);
return 0;
}
Program to receive / transmit the message using UART of LPC2148
(Without interrupt)
#include <lpc214x.h>
int i,RD0,f;
unsigned char x;
unsigned char n[10]={'S','A','S','T','R','A'},m[10]={'d','e','n','i','e','d'},a[5]={'1','2','3','4'},b[10];

int putkey(int TD) /* Send the character to UART */


{
while(!(U0LSR & 0x20)); //wait for Transmitter empty
return (U0THR = TD); //transmit
}

int getkey() /* Receive the character from UART */


{
int RD;
while(!(U0LSR & 0x01)); //wait for Receiver data
return (RD = U0RBR); //receive
}

void init_serial (void) { /* Initialize Serial Interface */


PINSEL0 = 5 ; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
int main()
{
init_serial();
for(i=0;i<4;i++)
{
b[i] = getkey(); //4 digit password received from user
putkey(b[i]);
if(b[i]==a[i])
{f++;}
}
i=0;
putkey('\n');
if (f==4)
{
while(i<6)
{
x=n[i];
putkey(x); // Carriage Return(CR),home
i++;
}
}
else
{
while(i<6)
{
x=m[i];
putkey(x); // Carriage Return(CR),home
i++;
}
}
return 0;
}

You might also like