- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rahul,
I am glad to know your application works properly, anyway I would like to recommend the following document:
Driving 16x2 LCD using KSDK drivers
The application uses the FRDM-KL25, but I assume you can use the same principle in your application.
I hope this material will be useful for you.
Have a great day.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you post the entire project? I am trying to get an example of a 16x2 lcd display with no success. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All,
The code worked . Issue were in the delay call.
I have used _time_delay() instead of the one used earlier.
Thank you.
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rahul,
I am glad to know your application works properly, anyway I would like to recommend the following document:
Driving 16x2 LCD using KSDK drivers
The application uses the FRDM-KL25, but I assume you can use the same principle in your application.
I hope this material will be useful for you.
Have a great day.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello David,
Thanks for the document.This is a needed document for LCD driver implementation .
Thanks
Rahul