AnsweredAssumed Answered

LCD Implementation in FRDM K64F

Question asked by Rahul PS on Nov 5, 2015
Latest reply on Nov 12, 2015 by Rahul PS

Hi,

 

I am using frdm k64f board and KDS IDE for my project.

I need to implement LCD on it.  Either in 8 bit or 4 bit mode.

 

I cannot see any driver for lcd in KDS or KSDK.

So i wrote my own driver for lcd.

But its not working .( Displayed the string 2,3 times but not consistent, as its not displaying always after reprogramming )

 

LCD Driver code is shown below.............................

 

 

void delay( int msec)

{

  int i,j;

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

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

}

 

 

void lcd_cmd( char DData) // Function to send command on LCD

{

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 0);

 

  if((DData & 0x01) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD0, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD0, 1);

  }

  if((DData & 0x02) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD1, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD1, 1);

  }

  if((DData & 0x04) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD2, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD2, 1);

  }

  if((DData & 0x08) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD3, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD3, 1);

  }

  if((DData & 0x10) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD4, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD4, 1);

  }

  if((DData & 0x20) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD5, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD5, 1);

  }

  if((DData & 0x40) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD6, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD6, 1);

  }

  if((DData & 0x80) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD7, 0);

  else

  {

  GPIO_DRV_WritePinOutput(kGpioLCDD7, 1);

  }

 

  GPIO_DRV_WritePinOutput(kGpioLCDRS, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDRW, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 1);

  delay(8);

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 0);

  delay(1);

}

 

 

 

 

void lcd_data(char DData) // Function to display character on LCD

{

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 0);

 

if((DData & 0x01) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD0, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD0, 1);

 

  if((DData & 0x02) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD1, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD1, 1);

 

  if((DData & 0x04) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD2, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD2, 1);

 

  if((DData & 0x08) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD3, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD3, 1);

 

  if((DData & 0x10) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD4, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD4, 1);

 

  if((DData & 0x20) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD5, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD5, 1);

 

  if((DData & 0x40) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD6, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD6, 1);

 

  if((DData & 0x80) ==0)

  GPIO_DRV_WritePinOutput(kGpioLCDD7, 0);

  else

  GPIO_DRV_WritePinOutput(kGpioLCDD7, 1);

 

  GPIO_DRV_WritePinOutput(kGpioLCDRS, 1);

  GPIO_DRV_WritePinOutput(kGpioLCDRW, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 1);

  delay(8);

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 0);

  delay(1);

}

 

 

void lcd_data_string( char *lcd_str)

{

  int i=0;

  while(lcd_str[i]!='\0')

  {

  lcd_data(lcd_str[i]);

  i++;

  delay(1);

  }

}

 

 

void goto_xy(int x,int y)

{

   if(x==0||x==1)

    lcd_cmd(0X80+y);

   if(x==2)

    lcd_cmd(0XC0+y);

  }

 

 

void init_lcd()

{

  GPIO_DRV_WritePinOutput(kGpioLCDRS, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDRW, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDEN, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD0, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD1, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD2, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD3, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD4, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD5, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD6, 0);

  GPIO_DRV_WritePinOutput(kGpioLCDD7, 0);

 

  lcd_cmd(0X38);   // For using 8-bit 2 row LCD

  delay(1);

  lcd_cmd(0X01); // For clear LCD screen

  delay(1);

  lcd_cmd(0X0C); // For display on cursor off

  delay(1);

  lcd_cmd(0X80);

  delay(10);

 

  lcd_data_string("CHECK LCD");

}

 

.............................

 

All pins are configured as output pin and connected  successfully.

 

I cant findout the mistake in this as all commands and datas given through the above code is getting to the lcd pins.(Verified through multimeter)

Replaced the lcd module  and the problem still exists.

 

How this problem could be solved?? ?? I am blocked with this and delayed in our development activity.

Hoping for a solution asap.

 

 

 

 

 

 

Thanks,

Rahul

 

TRIVANDRUM

Outcomes