Interfacing LCD display with GPIOs


#1

Hi,

I am trying to interface LCD display using the GPIOs at output. I am using LCD in 4-bit mode. The code for interfacing is below. Inspite of getting all the desired high and low states on the LCD pins, the characters are not displayed on the LCD screen. Is there something additional required to be configured when using a LCD display with the modem. Any kind of help would be highly appreciated.

Code:

#define GPIO_COUNT6 6
#define LCD_clear() LCD_command(0x01) /* Clear display LCD /
#define LCD_origin() LCD_command(0x02) /
Set to origin LCD /
#define LCD_row1() LCD_command(0x80) /
Begin at Line 1 /
#define LCD_row2() LCD_command(0xC0) /
Begin at Line 2 */

// Gpio Handles
s32 MyGpioHandle1;
s32 ret_value;
u8 delay_counter;

adl_ioDefs_t MyGpioConfig2 [ GPIO_COUNT6 ] =
{ ADL_IO_GPIO | 28 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW,//Output 1
ADL_IO_GPIO | 29 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW,//Output 2
ADL_IO_GPIO | 30 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW,//Output 3
ADL_IO_GPIO | 31 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW,//Output 4
ADL_IO_GPIO | 32 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW,//Output 5
ADL_IO_GPIO | 33 | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW};//Output 6 used as RS for LCD
//Output 5 used as enable for LCD and Rw is grounded permanently since using only for writing to LCD

void LCD_delay(u8 total_delay)
{
for (delay_counter=0; delay_counter<total_delay; delay_counter++)
{
adl_ctxSleep(1);
// resume from here after sleep of 1 TICK
// 1 TICK will give approx 18.5 milli sec delay.
}
}

void write_nibble(u8 op_data)
{

if(op_data & 0x01)
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[0], TRUE);
else
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[0], FALSE);

if(op_data & 0x02)
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[1], TRUE);
else
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[1], FALSE);

if(op_data & 0x04)
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[2], TRUE);
else
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[2], FALSE);

if(op_data & 0x08)
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[3], TRUE);
else
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[3], FALSE);

if(ret_value != OK)
adl_atSendResponse(ADL_AT_RSP,"\r\n ERROR in writing nibble \r\n");

}

void LCD_enable()
{
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[4], TRUE); /* set bit LCD_en */

LCD_delay(1);

ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[4], FALSE); /* clear bit  LCD_en */  

LCD_delay(1);            

}

void LCD_command(u8 command)
{
LCD_delay(1);
// clear bit LCD_rs to send command
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[5], FALSE);

write_nibble(command>>4);  // write higher nibble first
LCD_enable();
LCD_delay(1);
write_nibble(command);	 // write lower nibble first
LCD_enable();
LCD_delay(1);

}

void LCD_putc(u8 ascii)
{
LCD_delay(1);
// set bit LCD_rs to send data
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[5], TRUE);
LCD_delay(1);
write_nibble(ascii>>4); // write higher nibble first
LCD_enable();
write_nibble(ascii); // write lower nibble first
LCD_enable();
LCD_delay(1);
}

void LCD_puts(u8 *lcd_string)
{

while (*lcd_string) 
{
	LCD_putc(*lcd_string++);
}

}

void LCD_init()
{

ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[4], FALSE); /* Clear bit  LCD_en */
ret_value = adl_ioWriteSingle(MyGpioHandle1, &MyGpioConfig2[5], FALSE); /* Clear bit  LCD_rs */	


LCD_delay(1);

LCD_command(0x33);
LCD_delay(2);
LCD_command(0x32);
LCD_delay(2);
LCD_command(0x28);
LCD_command(0x0C);
LCD_command(0x06);
LCD_command(0x01); /* Clear */

LCD_delay(20);

}

void adl_main ( adl_InitType_e InitType )
{
s8 returnCode=0;

adl_atSendResponse(ADL_AT_RSP,"\r\n LCD PROGRAM \r\n");

MyGpioHandle1 = adl_ioSubscribe ( GPIO_COUNT6, MyGpioConfig2, 0, 0, 0 );	

  LCD_init();
	
 LCD_row1();	
 LCD_puts("ABCD");

adl_atSendResponse(ADL_AT_RSP,"\r\n LCD PROGRAM Completed \r\n");

}


#2

Is that true :question:

See: viewtopic.php?f=3&t=3749