This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

16X2 lcd interfacing help

Other Parts Discussed in Thread: MSP430G2553

code compiles wihtout error but no output on lcd please help

/* Hitachi hd44780 lcd display using msp430g2553 launchpad */
// RS { 0, select command register
// RS { 1, select data register
// RW { 0, write
// RW { 1, read
// EN { enable (1)
// 8 bit {DB0 to DB7}
// 4 bit {DB4 to DB7}
#include<msp430g2553.h>
#define RS BIT0
#define EN BIT2
#define DC P1OUT
#define line1 lcdcmd(0x80)
#define line2 lcdcmd(0xc0)

void lcdcmd(unsigned char value)
{
DC=(value & 0xf0)|(value & 0x0f);
P1OUT&=~RS;
P1OUT|=EN;
_delay_cycles(40);
P1OUT&=~EN;
return;
}
void lcddata(unsigned char value)
{
DC=(value & 0xf0)|(value & 0x0f);
P1OUT|=RS;
P1OUT|=EN;
_delay_cycles(40);
P1OUT&=~EN;
return;
}
void string(char *p)
{
while(*p)lcddata(*p++);

}
void clear(void)
{
lcdcmd(0x01);
_delay_cycles(3000);
}
void main(void)
{
WDTCTL = WDTHOLD + WDTPW;
P1OUT=0;
P1DIR=0xFF;
lcdcmd(0x30); // initialise with 8 bit
lcdcmd(0x28); // enter 4 bit command mode
lcdcmd(0x0c); // make cursor invisible
clear();
lcdcmd(0x6); // auto increment cursor
line1;
string(" welcome to ");
line2;
string("msp430 launchpad");
while(1);
}

  • Hi Gagan,

    It looks like you're trying to switch to 4-bit mode, but the lcdcmd and lcddata functions are set up for 8-bit mode.

    Do you have pins D0-D7 on the LCD controller connected to P1.0-P1.7? If so it's probably best to start off using 8-bit mode until you're sure the LCD display actually works!

    Also, as an initial test it's probably best to keep things as simple as possible. Just initialise the LCD controller and tell it to flash the cursor (use lcdcmd(0x0f) instead of lcdcmd(0x0c)).

    Hope that helps,

    Rob


    EDIT: Just looked again at the defines at the top - I think you're connecting P1.4-P1.7 to D4-D7, P1.0 to RS, P1.1 to RW (always low in this program) and P1.2 to EN. Is that correct?

  • i have changed to 8 bit mode..still i dont see any output not even cursor movement ..

    /* Hitachi hd44780 lcd display using msp430g2553 launchpad */
    // RS { 0, select command register
    // RS { 1, select data register
    // RW { 0, write
    // RW { 1, read
    // EN { enable (1)
    // 8 bit {DB0 to DB7}
    // 4 bit {DB4 to DB7}
    #include<msp430g2553.h>
    #define RS BIT0
    #define EN BIT1
    #define DC P2OUT
    #define line1 lcdcmd(0x80)
    #define line2 lcdcmd(0xc0)

    void lcdcmd(unsigned char value)
    {
    DC=value;
    P1OUT&=~RS;
    P1OUT|=EN;
    _delay_cycles(40);
    P1OUT&=~EN;
    return;
    }
    void lcddata(unsigned char value)
    {
    DC=value;
    P1OUT|=RS;
    P1OUT|=EN;
    _delay_cycles(40);
    P1OUT&=~EN;
    return;
    }
    void string(char *p)
    {
    while(*p)lcddata(*p++);

    }
    void clear(void)
    {
    lcdcmd(0x01);
    _delay_cycles(3000);
    }
    void main(void)
    {
    WDTCTL = WDTHOLD + WDTPW;
    P1OUT=0;
    P2OUT=0;
    P2DIR=0xff;
    P1DIR=0xFF;
    lcdcmd(0x30); // initialise with 8 bit
    lcdcmd(0x0e);
    clear();
    lcdcmd(0x6); // auto increment cursor
    line1;
    string(" welcome to ");
    line2;
    string("msp430 launchpad");
    while(1);
    }

  • I'll take a more detailed look at your updated code later, but did spot one thing that might be causing problems. You're now using Port 2 to send 8-bit data to the LCD. P2SEL defaults to 0xC0 after power-up clear, which configures P2.6 and P2.7 as XIN and XOUT instead of GPIO. Try adding the line P2SEL = 0 to your port initialisation code.

    EDIT: A few more comments...

    1. lcdcmd(0x30) should be replaced with lcdcmd(0x38) to set the mode to 8-bit with two lines of display.
    2. The 44780 will read D0-D7 on the falling edge of E, so I think the lcdcmd/lcddata function should be written in this order:
      P1OUT &= ~RS; // or P1OUT |= RS; for the lcddata function
      P1OUT |= EN;
      DC = value;
      P1OUT &= ~EN;
      _delay_cycles(40);
    3. MCLK defaults to ~1.1MHz on startup, so those delay_cycles(40) calls take slightly less than 37us, which is the internal operation time specified in the 44780 datasheet. The extra cycles consumed by the surrounding code will probably cover this, but if nothing else works it's worth trying with much longer delays. 

    EDIT 2: Swapped the lines setting EN and clearing RS - the 44780 datasheet suggests that RS needs to be set at least 60ns before E goes high (address setup time).

  • tried both ur suggestions..still no output..

    /* Hitachi hd44780 lcd display using msp430g2553 launchpad */
    // RS { 0, select command register
    // RS { 1, select data register
    // RW { 0, write
    // RW { 1, read
    // EN { enable (1)
    // 8 bit {DB0 to DB7}
    // 4 bit {DB4 to DB7}
    #include<msp430g2553.h>
    #define RS BIT0
    #define EN BIT1
    #define DC P2OUT
    #define line1 lcdcmd(0x80)
    #define line2 lcdcmd(0xc0)

    void lcdcmd(unsigned char value)
    {


    P1OUT|=EN;
    P1OUT&=~RS;
    DC=value;
    _delay_cycles(60);
    P1OUT&=~EN;
    return;
    }
    void lcddata(unsigned char value)
    {


    P1OUT|=EN;
    P1OUT|=RS;
    DC=value;
    _delay_cycles(60);
    P1OUT&=~EN;
    return;
    }
    void string(char *p)
    {
    while(*p)lcddata(*p++);

    }
    void clear(void)
    {
    lcdcmd(0x01);
    _delay_cycles(3000);
    }
    void main(void)
    {
    WDTCTL = WDTHOLD + WDTPW;
    P1OUT=0;
    P2OUT=0;
    P2SEL=0;
    P2DIR=0xff;
    P1DIR=0xFF;
    lcdcmd(0x30); // initialise with 8 bit // test if lcd works with basic led blink
    lcdcmd(0x0f);
    //clear();
    //lcdcmd(0x6); // auto increment cursor
    //line1;
    //string(" welcome to ");
    //line2;
    //string("msp430 launchpad");
    while(1);
    }

  • Perhaps time now to:

    a) monitor the data bus - insure that your code delivers your data intent.  Then insure that RS toggles as appropriate.  RW tied to ground.  Monitor @ the Lcd pins - not @ your MCU.  (signals must "get thru/arrive")

    b) when in doubt - as other advises - add 10 - 100x delay.  Later - once working - you can fine-tune.  Critical during init phase!

    c) safest E "hi" width is 450nS.  (accommodates older lcd modules)  later you can reduce - after image appears

    d) no mention of Vo pin (Lcd contrast) that I note.  Normally ~ 0.5V above ground will work - most modern Lcds.  It is possible that this ALONE - has caused your plight!   Pixel field should be just visible after initialization

    e) avoid any attempt to "unroll" a string.  Instead - send single bytes only during this beginning state.  (i.e. lcddata = 0x41;  // "A")  Any mistake in your code may hold the display "hostage" - pointless to optimize/ease @ early stage.   KISS - always...

  • Hi Gagan,

    Did you get your problem solved?

**Attention** This is a public forum