LCD interfacing using lpc 2148

Discussion in 'The Projects Forum' started by mahesh446, Jan 27, 2016.

  1. mahesh446

    Thread Starter New Member

    Jan 27, 2016
    2
    0
    Hi!
    i am newbie to the ARM coding. I did not understand the code i have verified the code so many times but i did not found any mistake in the code. But the code is not running in the board can any please help me.
    MC : LPC 2148
    4 bit LCD interfacing
    P0.16 RS
    P0.17 RW
    P0.18 EN
    P0.19 D4
    P0.20 D5
    P0.21 D6
    P0.22 D7

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

    #define DATA_PORT() IO0SET=(1<<16) //Function to select data port on LCD
    #define READ_DATA() IO0SET=(1<<17) //Function to select read operation 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

    unsigned char String1[]={"LCD TEST"};
    unsigned char String2[]={" 15:34:58 "};

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

    void Delay_Small(unsigned char j)
    {
    unsigned int i;
    for(;j>0;j--)
    {
    for(i=0; i<1000; i++);
    }
    }


    unsigned char Busy_Wait() //This function checks the busy status of LCD
    {
    unsigned int temp=0;
    EN_LOW();
    COMMAND_PORT();
    READ_DATA();

    IO0PIN&=0xFF87FFFF;
    IO0DIR&=0xFF87FFFF;
    IO0PIN|=0x00400000;

    do{
    EN_HI();
    EN_LOW();
    EN_HI();
    EN_LOW();
    temp=IO0PIN;
    }
    while((temp & 0x00400000)==0x00400000);
    EN_LOW();
    WRITE_DATA();
    IO0DIR&=0xFF80FFFF;
    IO0DIR|=0x007F0000;
    return (0);
    }


    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();
    //while(Busy_Wait());
    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_Small(1);
    }

    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++;
    }
    }


    int main(void)
    {
    PINSEL0 = 0x00000000; // Enable GPIO on all pins
    PINSEL1 = 0x00000000;
    PINSEL2 = 0x00000000;

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

    LCD_Init();
    LCD_Command(0x01);

    Delay(20);

    LCD_Command(0x80);
    LCD_String(&String1[0]);
    LCD_Command(0xC0);
    LCD_String(&String2[0]);
    while(1)
    {

    }

    }
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,810
    834
    What are the symptoms of the code not running? I wonder if you get an error message.

    Please put you code between code tags. Like this (ignore the internal space):

    [ code]
    Your code
    [ /code]

    It will look like this:
    Code (Text):
    1.  
    2. Your code
    3.  
     
  3. mahesh446

    Thread Starter New Member

    Jan 27, 2016
    2
    0
    Thanks for you reply.
    In the keil IDE it is not showing any errors or wrongs.
    So i dump the code into my board.
    Even after successful burn, the LCD is not displaying the given string.
    I am unable find out the mistake.
    I think the error is in the initiation of GPIO pins.
    P0.16 RS
    P0.17 RW
    P0.18 EN
    P0.19 D4
    P0.20 D5
    P0.21 D6
    P0.22 D7
    Please verify the code for above GPIO pins.
    Your Help is appreciated.
    Thank you in advance.
     
Loading...