16*2 lcd display not working with LPC1769

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

16*2 lcd display not working with LPC1769

2,103 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Irappa on Wed Sep 04 23:28:23 MST 2013
i have tried many times to interface 16*2 lcd display with lpc1769 but it was not displaying anything.
if you have any source code plese send it to iru1688@gmail.com.

This is my code:

/*
===============================================================================
Name        : main.c
Author      :
Version     :
Copyright   : Copyright (C)
Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#include "type.h"
#endif

#include "lcd.h"


/**
**************************************************************************

****1111
  Function Name : delay()

  Description :This function suspends the tasks for specified ticks.

  Input :  ticks:no of ticks in multiple of 1 usec
            task: task to be suspended

  Output : void

  Note :
*******************************************************************************
*/
void delay(int count)
{
  int j=0,i=0;

  for(j=0;j<count;j++)
  {
    /* At 60Mhz, the below loop introduces
    delay of 10 us */
    for(i=0;i<35;i++);
  }
}

/**
********************************************************************************************
  Function Name :wait_lcd()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void wait_lcd( void )
{
  LCD_DATA_DIR &= ~LCD_DATA_MASK;
  LCD_CTRL_CLR |=  LCDRS;
  LCD_CTRL_SET |=  LCDRW |LCDEN;
  while(LPC_GPIO0->FIOPIN & LCD_BUSY_FLAG);/* wait for busy flag to become low */

  LCD_CTRL_CLR |= LCDEN | LCDRW;
  LCD_DATA_DIR |= LCD_DATA_MASK;

  delay(100);
}
/**
********************************************************************************************
  Function Name :lcd_command_write()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
#define DATA_POS 19
#define DELAY_COUNT 100
void lcd_command_write( unsigned char command )
{
  unsigned char temp=0;
  unsigned int temp1=0;

  temp=command;
  temp=(temp>>4)&0x0F;
  temp1=(temp<<DATA_POS)&LCD_DATA_MASK;

  LCD_CTRL_CLR = LCDRS;
  LCD_CTRL_SET = LCDEN;
  LCD_DATA_CLR = LCD_DATA_MASK;
  LCD_DATA_SET = temp1;
  //delay(DELAY_COUNT);
  LCD_CTRL_CLR = LCDEN;

  temp=command;
  temp&=0x0F;
  temp1=(temp<<DATA_POS)&LCD_DATA_MASK;
  delay(DELAY_COUNT);

  LCD_CTRL_CLR |= LCDRS;
  LCD_CTRL_SET |= LCDEN;
  LCD_DATA_CLR = LCD_DATA_MASK;
  LCD_DATA_SET = temp1;
  //delay(DELAY_COUNT);
  LCD_CTRL_CLR |= LCDEN;
  wait_lcd();
}
/**
********************************************************************************************
  Function Name :set_lcd_port_output()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void set_lcd_port_output( void )
{
  LCD_CTRL_DIR |= ( LCDEN | LCDRS | LCDRW | LCD_BACKLIGHT );
  LCD_CTRL_CLR |= ( LCDEN | LCDRS | LCDRW | LCD_BACKLIGHT );
  LCD_DATA_DIR |= LCD_DATA_MASK;
}
/* *
********************************************************************************************
  Function Name :lcd_clear()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void lcd_clear( void)
{
  lcd_command_write( 0x01 );
}
/**
********************************************************************************************
  Function Name :lcd_gotoxy()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
int lcd_gotoxy( unsigned int x, unsigned int y)
{
  int retval = 0;

  if( (x > 1) && (y > 15) )
  {
    retval = -1;
  } else {
  if( x == 0 )
  {
    lcd_command_write( 0x80 + y );/* command - position cursor at 0x00 (0x80 + 0x00 ) */
  } else if( x==1 ){
    lcd_command_write( 0xC0 + y );/* command - position cursor at 0x40 (0x80 + 0x00 ) */
    }
   }
   return retval;
}

/**
********************************************************************************************
  Function Name :lcd_data_write()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void lcd_data_write( unsigned char data )
{
  unsigned char temp=0;
  unsigned int temp1=0;

  temp=data;
  temp=(temp>>4)&0x0F;
  temp1=(temp<<DATA_POS)&LCD_DATA_MASK;

  LCD_CTRL_SET |= LCDEN|LCDRS;
  LCD_DATA_CLR = LCD_DATA_MASK;
  LCD_DATA_SET = temp1;
  LCD_CTRL_CLR |= LCDEN;

  temp=data;
  temp&=0x0F;
  temp1=(temp<<DATA_POS)&LCD_DATA_MASK;

  LCD_CTRL_SET |= LCDEN|LCDRS;
  LCD_DATA_CLR = LCD_DATA_MASK;
  LCD_DATA_SET = temp1;
  LCD_CTRL_CLR |= LCDEN;
  wait_lcd();
}
/**
********************************************************************************************
  Function Name :lcd_putchar()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void lcd_putchar( int c )
{
  lcd_data_write( c );
}

/**
********************************************************************************************
  Function Name :lcd_putstring()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void lcd_putstring( unsigned char line, char *string )
{
  unsigned char len = MAX_CHAR_IN_ONE_LINE;

  lcd_gotoxy( line, 0 );
  while(*string != '\0' && len--)
  {
    lcd_putchar( *string );
    string++;
  }
}

/**
********************************************************************************************
  Function Name :lcd_backlight_on()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void lcd_backlight_on()
{
  LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT;
  LCD_BACK_LIGHT_SET |= LCD_BACKLIGHT;
}

/**
********************************************************************************************
Function Name : turn_off_lcd_back_light()

Description   :

Input         :

Output        : Void

Note          :
********************************************************************************************
*/
void lcd_backlight_off(void)
{
   LCD_BACK_LIGHT_DIR |= LCD_BACKLIGHT;
   LCD_BACK_LIGHT_CLR |= LCD_BACKLIGHT;
}

/**
********************************************************************************************
  Function Name :init_lcd()

  Description   :

  Input         :

  Output        :Void

  Note          :
********************************************************************************************
*/
void init_lcd( void )
{
  set_lcd_port_output();
  lcd_command_write(0x28);     /*   4-bit interface, two line, 5X7 dots.        */
//  lcd_clear() ;                /*   LCD clear                                   */
  lcd_command_write(0x02);     /*   cursor home                                 */
  lcd_command_write(0x06);     /*   cursor move direction                       */
  lcd_command_write(0x0C) ;    /*   display on      */
  lcd_gotoxy(0, 0);
  lcd_clear();
}


Please help me.
Labels (1)
0 Kudos
Reply
8 Replies

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Irappa on Mon Sep 15 21:56:09 MST 2014
I tried with 8-bit mode, its working fine on 16*2 lcd display. But i need some help for 4 bit mode. if anyone got the output please share the source code.
Please find the attached files for 4 bit mode.
0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dbyrnes on Wed Feb 12 21:35:01 MST 2014
Could you share what you did to get it working?
0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tmoerkerken on Mon Feb 03 03:31:38 MST 2014
Can you share what you've changed in order to get thing working?
0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Irappa on Mon Sep 23 04:04:45 MST 2013
Hi,

Thank you for your reply, now its working fine.

0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by studyembedded on Wed Sep 11 09:16:24 MST 2013
Check www.zembedded.com there is a good tutorial for LCD interface with different controllers....thanks!
0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Sep 10 07:43:17 MST 2013
That looks more like it - thanks.

What kind of LCD controller are you using?

Are you sure about the levels of LCDEN and LCDWR.
You code assumes that the LCDEN is active high, the LCD I use has an active low enable pin.
And the R/W line ? You are setting LCDWR high to read and low to write (seems OK to me but you never know)

Same goes for LCDRS: 0 = Control register and 1 = Data register ???

The lcd_data_write and lcd_command_write look strange.
You first set LCDEN, then set the data, then clear LCDEN, then set LCDEN again, set the data and clear LCDEN.
After this you call wait_lcd().

Make sure the data and LCDRS are set to the correct values before triggering LCDEN.

as an optimization: combine lcd_command_write() and lcd_data_write(), they are the same (they should be) except for the value of LCDRS.
0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Irappa on Tue Sep 10 05:39:30 MST 2013
Please check this code i have attached for same and help me as soon as possible

0 Kudos
Reply

2,019 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Sun Sep 08 04:27:41 MST 2013
I'm sorry but your code is absolutely bogus.

The delay function does not delay the given number of ticks and includes some weird assignments.
lcd_command_write is defined as a void function but returns a value, it uses two variables x and y that are not defined anywhere and assigns values to temp and temp1 that are not used at all.
I have not even looked at lcd_data_write since that function is incomplete but I'm guessing ...

Are you sure you know what you are doing ???

You need to connect the display in some way to the lpc1769 (I2C, SPI, parallel or ??? interface), initialize the I/O, initialize the LCD controller (which LCD controller type are you using ?) and only then you might be able to show any data on the LCD itself.

0 Kudos
Reply