This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC 2148: Fetching data from uart and displaying that on LCD

Hey,
I have a sensor which sends ASCII data.
I want to save that data in the RBR register of UART and then display it on the LCD
I am here posting the code for the same but i am not getting any display on LCD.
Kindly help me out in the same.

#include<stdio.h>
#include<lpc214x.h>
#include<string.h>
#define TEMT (1<<6)
#define LINE_FEED 0xA
#define CARRIAGE_RET 0xD
typedef unsigned char uchar ;
typedef unsigned int  uint ;
typedef unsigned long ulong;
#define DATA_PORT() IO0SET=(1<<16)                 //Function to select data port on LCD
#define EN_HI() IO0SET=(1<<18)                     //Function to Enable LCD


#define COMMAND_PORT() IO0CLR=(1<<16)       //Function to select command port on LCD
#define WRITE_DATA() IO0CLR=(1<<17)                 //Function to select write operation on LCD
#define EN_LOW() IO0CLR=(1<<18)                     //Function to disable LCD


/*************** System Initialization ***************/
void Initialize()
{
/* Initialize Pin Select Block for Tx and Rx */
PINSEL0=0x00050005;
/* Enable FIFO's and reset them */
U0FCR=0x7;
/* Set DLAB and word length set to 8bits */
U0LCR=0x83;
/* Baud rate set to 9600 */
U0FDR=0x00000075;
U0DLL=0x39;
U0DLM=0x0;
/* Clear DLAB */
U0LCR=0x3;
/* Enable FIFO's and reset them */
U1FCR=0x7;
/* Set DLAB and word length set to 8bits */
U1LCR=0x83;
/* Baud rate set to 9600 */
U1FDR=0x00000075;
U1DLL=0x39;
U1DLM=0x0;
/* Clear DLAB */
U1LCR=0x3;
 }


 // Recieve data from UART1(sensor)
char data[16];
int LSR;

    char Recieve(void )
{
        LSR = U1LSR;       //* Read LSR(Line Status Register) Register *
                while ( !(U1LSR & 0x01) );  //* Check Whether Data is Recieved *
                                    //* i.e. Check RDR(Read Data Ready) interrupt.*
                                                  //* If Yes then get data From RBR(Recive Buffer Register).*
                data[16] = U1RBR; //Data Recieved and saved in RBR
                //MsDelay( 50 );
                return( 0 );
 }


 void Delay(unsigned char j)    // Delay
{
 unsigned int  i;
 for(;j>0;j--)
 {
  for(i=0; i<60000; i++);
 }
}



void LCD_Command(unsigned int data)                       //This function is used to send LCD commands
{
 unsigned int temp=0;
 EN_LOW();
 COMMAND_PORT();
 WRITE_DATA();

 temp=data;
 IO0PIN&=0xFF87FFFF;
 IO0PIN|=(temp & 0xF0) << 15;

 EN_HI();
 EN_LOW();

 temp=data & 0x0F;
 IO0PIN&=0xFF87FFFF;
 IO0PIN|=(temp) << 19;

 EN_HI();
 EN_LOW();
 Delay(10);
}


void LCD_Data(unsigned int data)                   //This function is used to send data to LCD
{
 unsigned int temp=0;
 EN_LOW();
 DATA_PORT();
 WRITE_DATA();

 temp=data;
 IO0PIN&=0xFF87FFFF;
 IO0PIN|=(temp & 0xF0) << 15;

 EN_HI();
 EN_LOW();

 temp=data & 0x0F;

 IO0PIN&=0xFF87FFFF;
 IO0PIN|=(temp) << 19;

 EN_HI();
 EN_LOW();
 Delay(5);
}

void LCD_Init()
{
 LCD_Command(0x20);
 LCD_Command(0x28);
 LCD_Command(0x0C);
 LCD_Command(0x06);
}


void LCD_String(unsigned char *data)
{
 while(*data)
 {
  LCD_Data(*data);
  data++;
 }
}



          void main(void)

  {
    while(!(U1LSR & 0x01));
        Initialize();
    Recieve();


 PINSEL0 = 0x00000000;          // Enable GPIO on all pins
 PINSEL1 = 0x00000000;
 PINSEL2 = 0x00000000;

 Delay(20);
 IO0DIR = (1<<22) | (1<<21) | (1<<20) | (1<<19) | (1<<18) | (1<<17) | (1<<16);                // Set P0.16, P0.17, P0.18, P0.19, P0.20, P0.21, P0.22 as Output


        LCD_Init();
        LCD_Command(0x01);              //Clear LCD
    Delay(20);

    LCD_Command(0x80);     // Position Line 1
    LCD_String(&data[16]);
        while(1)

 {
}
}

0