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

problem when i interface the lcd with LPC2148

Hi when i tryed to interface the 16*2 lcd with lpc1248
i am facing problem i.e when i send 'A' to lcd it shows O in lcd display
i attached my code beloe
//////////////////////////////////////////////////////

// note my LCD data-line is P1.16 =D0 to P1.23 =D7 and
control line is P0.11 =rs P0.12=rw and P0.13=e

#include<LPC214x.h>

void init_PLL(void);

void init_GPIO(void);

void lcd_data(unsigned char);

void lcd_cmd(unsigned char);

void lcd_init(void);

unsigned int adjust_portbit(unsigned char);

void delay(unsigned int);

#define E 0x00002000;

#define RW 0x00001000;

#define RS 0x00000800;

int main(void)

{

init_PLL();

init_GPIO();

lcd_init();

while(1)

{

lcd_data('A');

lcd_data('B');

lcd_data('c');

lcd_data('d');

delay(0xffffff);

}

}

void init_PLL(void)

{

PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK

PLL0CON=0x00000001;

PLL0FEED=0x000000AA;//UPDATE THE PLL REGISTER

PLL0FEED=0x00000055;

while(!(PLL0STAT & 0x00000400)); // CHECK
WHETHRT THE CCLK IS GENERATED EXAXT VALUE,

PLL0CON=0x00000003; // CONNECT PLL

PLL0FEED=0x000000AA; //UPDATE THE PLL REGISTER

PLL0FEED=0x00000055;

VPBDIV=0x00000002; //PCLK=1/2*CCLK

}

void init_GPIO( void)

{

//PINSEL0=0x00000000;

//PINSEL1=0x00000000;

IODIR0=0x0000FF00;

IODIR1=0x00FF0000;

}

void lcd_init(void)

{

lcd_cmd(0x30);

delay(0xffff);

lcd_cmd(0x30);

delay(0xffff);

lcd_cmd(0x30);

delay(0xffff);

lcd_cmd(0x38);

delay(0xffffff);

lcd_cmd(0x0e);

delay(0xffff);

lcd_cmd(0x01);

delay(0xffffff);

lcd_cmd(0x06);

delay(0xffffff);

}

//this routine is to tack the charecter and

move thet charecter to 16 to 23 bit position of port

because i am using 16 to 23 bit of port1 as a data

line in lcd ie p1.16 to d0 and p1.23 to d7 (8

bit lcd mode)

unsigned int adjust_portbit(unsigned char c)

{

unsigned char j;

unsigned int result;

result=c;

for(j=0;j<16;j++)

{

result=result<<1;

}

return result;

}

void lcd_data(unsigned char ldata)

{

unsigned int temp,z;

temp=adjust_portbit(ldata);

//init_GPIO();

z=~temp;

IOCLR1=z;

IOSET1=temp;

delay(0xffff);

IOCLR0=RW;

IOSET0=RS;

IOSET0=E;

delay(0xffffff);

IOCLR0=E;

}

void lcd_cmd(unsigned char lcmd)

{

unsigned int temp,z;

temp=adjust_portbit(lcmd);

//init_GPIO();

z=~temp;

IOCLR1=z;

IOSET1=temp;

delay(0xffff);

IOCLR0=RW;

IOCLR0=RS;

IOSET0=E;

delay(0xffffff);

IOCLR0=E;

}

void delay(unsigned int value)

{

unsigned int i;

for(i=0;i<value;i++);

{

// for(j=0;j<0xffff;j++);

}

}

Parents
  • sorry for my mistake
    note my LCD data-line is P1.16 =D0 to P1.23   =D7 and control line is P0.11 =rs P0.12=rw and  P0.13=e
    #include<LPC214x.h>
    void init_PLL(void);
    void init_GPIO(void);
    void lcd_data(unsigned char);
    void lcd_cmd(unsigned char);
    void lcd_init(void);
    unsigned int adjust_portbit(unsigned char);
    void delay(unsigned int);
    //unsigned int    E=0x00002000;
    //unsigned int   RW=0x00001000;
    //unsigned int    RS=0x00000800;
     #define E 0x00002000
    #define RW 0x00001000
    #define RS 0x00000800
    
    int main(void)
    {
    //unsigned int temp;
    //unsigned int i;
    init_PLL();
    init_GPIO();
    lcd_init();
    while(1)
    {
    lcd_data('A');
    lcd_data('B');
    lcd_data('c');
    lcd_data('d');
     delay(0xffffff);
      }
    }
    void init_PLL(void)
    {
     PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
     PLL0CON=0x00000001;
     PLL0FEED=0x000000AA;//UPDATE THE PLL REGISTER
     PLL0FEED=0x00000055;
     while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK IS GENERATED EXAXT VALUE
     PLL0CON=0x00000003;  //  CONNECT PLL
     PLL0FEED=0x000000AA; //UPDATE THE PLL REGISTER
     PLL0FEED=0x00000055;
     VPBDIV=0x00000002;      //PCLK=1/2*CCLK
    }
    void init_GPIO( void)
    {
    //PINSEL0=0x00000000;
    //PINSEL1=0x00000000;
    IODIR0=0x0000FF00;
    IODIR1=0x00FF0000;
    }
    void lcd_init(void)
    {
      lcd_cmd(0x30);
    delay(0xffff);
      lcd_cmd(0x30);
    delay(0xffff);
      lcd_cmd(0x30);
    delay(0xffff);
    lcd_cmd(0x38);
    delay(0xffffff);
    lcd_cmd(0x0e);
    delay(0xffff);
    lcd_cmd(0x01);
    delay(0xffffff);
    lcd_cmd(0x06);
    delay(0xffffff);
    }
    unsigned int adjust_portbit(unsigned char c)
    {
    unsigned char j;
    unsigned int result;
    result=c;
    for(j=0;j<16;j++)
    {
    result=result<<1;
    }
    return result;
    }
    void lcd_data(unsigned char ldata)
    {
      unsigned int temp,z;
     temp=adjust_portbit(ldata);
        //init_GPIO();
       z=~temp;
       IOCLR1=z;
      IOSET1=temp;
      delay(0xffff);
      IOCLR0=RW;
     IOSET0=RS;
     IOSET0=E;
     delay(0xffffff);
     IOCLR0=E;
     }
      void lcd_cmd(unsigned char lcmd)
      {
    
        unsigned int temp,z;
     temp=adjust_portbit(lcmd);
        //init_GPIO();
            z=~temp;
       IOCLR1=z;
      IOSET1=temp;
      delay(0xffff);
      IOCLR0=RW;
     IOCLR0=RS;
     IOSET0=E;
     delay(0xffffff);
     IOCLR0=E;
    
      }
      void delay(unsigned int value)
      {
      unsigned int i;
      for(i=0;i<value;i++);
      {
     // for(j=0;j<0xffff;j++);
      }
      }
    
    
    

Reply
  • sorry for my mistake
    note my LCD data-line is P1.16 =D0 to P1.23   =D7 and control line is P0.11 =rs P0.12=rw and  P0.13=e
    #include<LPC214x.h>
    void init_PLL(void);
    void init_GPIO(void);
    void lcd_data(unsigned char);
    void lcd_cmd(unsigned char);
    void lcd_init(void);
    unsigned int adjust_portbit(unsigned char);
    void delay(unsigned int);
    //unsigned int    E=0x00002000;
    //unsigned int   RW=0x00001000;
    //unsigned int    RS=0x00000800;
     #define E 0x00002000
    #define RW 0x00001000
    #define RS 0x00000800
    
    int main(void)
    {
    //unsigned int temp;
    //unsigned int i;
    init_PLL();
    init_GPIO();
    lcd_init();
    while(1)
    {
    lcd_data('A');
    lcd_data('B');
    lcd_data('c');
    lcd_data('d');
     delay(0xffffff);
      }
    }
    void init_PLL(void)
    {
     PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
     PLL0CON=0x00000001;
     PLL0FEED=0x000000AA;//UPDATE THE PLL REGISTER
     PLL0FEED=0x00000055;
     while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK IS GENERATED EXAXT VALUE
     PLL0CON=0x00000003;  //  CONNECT PLL
     PLL0FEED=0x000000AA; //UPDATE THE PLL REGISTER
     PLL0FEED=0x00000055;
     VPBDIV=0x00000002;      //PCLK=1/2*CCLK
    }
    void init_GPIO( void)
    {
    //PINSEL0=0x00000000;
    //PINSEL1=0x00000000;
    IODIR0=0x0000FF00;
    IODIR1=0x00FF0000;
    }
    void lcd_init(void)
    {
      lcd_cmd(0x30);
    delay(0xffff);
      lcd_cmd(0x30);
    delay(0xffff);
      lcd_cmd(0x30);
    delay(0xffff);
    lcd_cmd(0x38);
    delay(0xffffff);
    lcd_cmd(0x0e);
    delay(0xffff);
    lcd_cmd(0x01);
    delay(0xffffff);
    lcd_cmd(0x06);
    delay(0xffffff);
    }
    unsigned int adjust_portbit(unsigned char c)
    {
    unsigned char j;
    unsigned int result;
    result=c;
    for(j=0;j<16;j++)
    {
    result=result<<1;
    }
    return result;
    }
    void lcd_data(unsigned char ldata)
    {
      unsigned int temp,z;
     temp=adjust_portbit(ldata);
        //init_GPIO();
       z=~temp;
       IOCLR1=z;
      IOSET1=temp;
      delay(0xffff);
      IOCLR0=RW;
     IOSET0=RS;
     IOSET0=E;
     delay(0xffffff);
     IOCLR0=E;
     }
      void lcd_cmd(unsigned char lcmd)
      {
    
        unsigned int temp,z;
     temp=adjust_portbit(lcmd);
        //init_GPIO();
            z=~temp;
       IOCLR1=z;
      IOSET1=temp;
      delay(0xffff);
      IOCLR0=RW;
     IOCLR0=RS;
     IOSET0=E;
     delay(0xffffff);
     IOCLR0=E;
    
      }
      void delay(unsigned int value)
      {
      unsigned int i;
      for(i=0;i<value;i++);
      {
     // for(j=0;j<0xffff;j++);
      }
      }
    
    
    

Children