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.

Not getting data visible on LCD 16X2 when interfaced with MSP430G2553

Other Parts Discussed in Thread: MSP430G2553

#include <msp430g2553.h>

#define RS_HIGH     P2OUT |= BIT0        // define RS high  RS = 1 —–> Data Register
#define RS_LOW      P2OUT &= ~BIT0       // define RS low   RS = 0 —–> Command Code Register

#define READ        P2OUT |= BIT1        // define Read signal R/W = 1 for reading
#define WRITE       P2OUT &= ~BIT1       // define Write signal R/W = 0 for writing

#define ENABLE_HIGH P2OUT |=  BIT2       // define Enable high signal
#define ENABLE_LOW  P2OUT &= ~BIT2       // define Enable Low signal P2.2

unsigned int i;
unsigned int j;

///P2.0 = RS     ,P2.1 = R/W    ,P2.2 = enable , P1.7 = Busy flag

void check_busy(void)
{
    P1DIR &= ~(BIT7);                              // make P1.7 as input
    ENABLE_LOW;                                         // P2OUT &= ~BIT2
    __delay_cycles(1000);
    ENABLE_HIGH;                                        //P2OUT |=  BIT2
    while((P1IN & BIT7)==0x80);					   // Busy flag
    P1DIR |= BIT7;                                 // make P1.7 as output
}

void send_command(unsigned char cmd)
{

	WRITE;                                               //for writing command  P2OUT &= ~BIT1
	RS_LOW;												//for sending command   P2OUT &= ~BIT0
	ENABLE_HIGH;                                        //P2OUT |=  BIT2
	check_busy();
	P1OUT |= (cmd);
	__delay_cycles(1000);
	ENABLE_LOW;
}

void send_data(unsigned char data)
{

     WRITE;                                         //for writing data  P2OUT &= ~BIT1
     RS_HIGH;                                        // P2OUT |= BIT0
     ENABLE_HIGH;                                        //P2OUT |=  BIT2
     check_busy();
     P1OUT |= (data);
     __delay_cycles(1000);
     ENABLE_LOW;
}

void send_string(char *s)
{
    while(*s)
    {
        send_data(*s);
        s++;
    }
}

void lcd_init(void)
{
	 				 //wait till 1.5ms after providing vcc to go upto 4.5v
     P2DIR |= 0xFF;
     P1DIR |= 0xFF;
     P2OUT &= ~0x00;
     P1OUT &= ~0x00;

     __delay_cycles(15000);
     send_command(0x38);					 // 8 bit mode  //function set reg
     //check_busy();
     send_command(0x0E); 				     // display on cursor blinking
     send_command(0x01); 				     // clear the screen
     send_command(0x06);					 // increment cursor
     send_command(0x80);					 // force cursor to blink in first line
}



void main(void)
{
	WDTCTL = WDTPW + WDTHOLD;				// stop watchdog timer
    lcd_init();
    send_string("vikas Hurgat");
    send_command(0xC0);                    //forcing cursor to begin to second line
    send_string("Embin");
    while(1){}
}

kindly help me in sorting the issue involved.

Replies are appreciated!!

Thank You

  • Hello Vikas,

    One glaring mistake that I do notice is P1OUT |= (data); in the send_data function should be P1OUT = (data); otherwise you will not be resetting any bits. The same applies for cmd and the send_command function, which is probably what's causing you to not be able to see any data output onto the screen. Make sure to triple-check your wiring as well.

    Regards,
    Ryan
  • Hi,

    still it is not working,not viewind any data on screen.

    I changed my code by adding delay(pls have a look over delay) kindly look my code.

    I am using JHD 162A  LCD.

    #include<msp430g2553.h>
    #define RS    BIT0
    #define RW    BIT1
    #define EN    BIT2
    #define line1 lcd_command(0x80)
    #define line2 lcd_command(0xc0)
    
    void lcd_command(unsigned char cmnd)
    {
    
    	P2OUT &= ~(RS);
    	P2OUT &= ~(RW);
    	P1OUT = cmnd;
    	P2OUT |= (EN);
    	_delay_cycles(1);                  //1us
    	P2OUT &= ~(EN);
    	_delay_cycles(100);               //100us
    }
    
    void lcd_data(unsigned char data)
    {
    
    	P2OUT |= (RS);
    	P2OUT &= ~(RW);
    	P1OUT = data;
    	P2OUT |= (EN);
    	_delay_cycles(1);      										    //1us
    	P2OUT &= ~(EN);
    	__delay_cycles(100);											//100us
    	return;
    }
    
    void lcd_string(char *str)
    {
    	unsigned char i=0;
    	while(str[i]!=0)
    	{
    		lcd_data(str[i]);
    		i++;
    	}
    }
    
    
    void lcd_init(void)
    {
    	P1DIR |= 0xFF;
    	P2DIR |= 0xFF;
    
    	P2OUT &= ~(EN);
    	__delay_cycles(15000);                                   //15ms
    	lcd_command(0x38);                                       //function set
    	lcd_command(0x0E);                                       //display on cursor blinking
    	lcd_command(0x01);										 //clear display screen
    	lcd_command(0x02);										 // return home
    	__delay_cycles(2000);									//2ms
    	lcd_command(0x06);                                      //increment cursor
    }
    
    void main(void)
    {
    	WDTCTL = WDTHOLD + WDTPW;								//stop WDT
    	lcd_init();
    
    	line1;
    	__delay_cycles(100);
    	lcd_string("vikas");
    	//__delay_cycles(100);                                  // 100us
    
    	line2;
    	__delay_cycles(100);
    	lcd_string("Embin");
    	//__delay_cycles(100);								   //100us
    
    	while(1);
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  • Vikas,

    You will need to refer to the JHD 16A datasheet and ensure that you are following the connection and write mode diagrams exactly as instructed. A logic analyzer or oscilloscope would also help for looking at your communication lines. Can you get the commands to work, like get a blinking cursor on the second line? This will determine if the issue is isolated to the data write function.

    Regards,
    Ryan
  • hi,

    will the issue of logic levels of LCD and MSP430G2553 gonna occur???

  • >will the issue of logic levels of LCD and MSP430G2553 gonna occur???

    You don't specify how you are powering the MSP430, nor how you have everything wired. Necessary information to answer that question, otherwise we would just be guessing.

    According to one datasheet that I found, Vih-min is 2.2 Volts, so the MSP outputs need to be higher voltage than that (Voh-min spec) to be compatible (on writing).

    Have you tried single stepping your program in the debugger and checking the LCD connections to make sure the pins are toggling as you expect them?
  • Vikas,

    please have a second look into the datasheet of the HD44780 controller. Your initialization is not according to the datasheet - it says that function set has to be sent three times with different delays in between. I have seen a lot of source codes from different people where the timing was not correct. Not sure if this solves your problem, but it could be an issue.

    Dennis

  • hi,

    Thanku all for the suggestions.

    My Problem is SOLVED.I checked the LCD Working or not and i found it faulty.Please i suggest to check the LCD first.

    >>connect :  Vcc Vss LED+ to 5v vcc and LED-  gnd to ground.

    >> if the first line comes with all the pixcels on then its working LCD.

    Thanku

  • Hi Vikas

    Can you share the code which is working for JHD 162A LCD display ?
  • #include <msp430g2553.h>
    
    #define DR          P2OUT = P2OUT | BIT0        // define RS high
    #define CWR         P2OUT = P2OUT & (~BIT0) // define RS low
    #define READ        P2OUT = P2OUT | BIT1    // define Read signal R/W = 1 for reading
    #define WRITE       P2OUT = P2OUT & (~BIT1)     // define Write signal R/W = 0 for writing
    #define ENABLE_HIGH P2OUT = P2OUT | BIT2        // define Enable high signal
    #define ENABLE_LOW  P2OUT = P2OUT & (~BIT2)     // define Enable Low signal
    
    void delay(unsigned int k)
    {
    	unsigned int i;
    	unsigned int j;
        for(j=0;j<=k;j++)
        {
            for(i=0;i<100;i++);
    
        }
    
    }
    void data_write(void)
    {
        ENABLE_HIGH;
        __delay_cycles(1);
        ENABLE_LOW;
    }
    
    void data_read(void)
    {
        ENABLE_LOW;
        __delay_cycles(5);             //1msec
        ENABLE_HIGH;
    }
    /*
    void check_busy(void)//busy flag will remain high(BF=1) until the initialization ends
    {
        P1DIR &= ~(BIT7); // make P1.7 as input//reading input from the LCD//The busy state lasts for 10 ms after VCC rises to 4.5 V.
        while((P1IN&BIT7)==1)
        {
            data_read();
        }
        P1DIR |= BIT7;  // make P1.7 as output
    }*/
    
    void check_busy(void)
    {
    	         unsigned char i,j;
    	         for(i=0;i<50;i++)        //A simple for loop for delay
    	            for(j=0;j<255;j++);
    }
    
    void send_command(unsigned char cmd)
    {
    	P1OUT = (cmd);
    	CWR;
    	WRITE;
    	data_write();
    	check_busy();
    }
    
    void send_data(unsigned char data)
    {
    	P1OUT = (data);
    	DR;
    	WRITE;
    	data_write();
    	check_busy();
    }
    
    void send_string(char *s)
    {
        while(*s)
        {
            send_data(*s);
            s++;
        }
    }
    
    void lcd_init(void)
    {
    
        P2DIR = 0xFF;
        P1DIR = 0xFF;
        P2OUT = 0x00;
        P1OUT = 0x00;
    
    
        __delay_cycles(25000);										//delay for 25msec is perfect
        send_command(0x38);												//  3C 0F 06 01 80   works fine
        send_command(0x0E);										//set display on ,cursor off,blink on off
        send_command(0x06);										// set entry mode	//0x04 reverse string
        send_command(0x1C);										// right shift
        send_command(0x01);										//  clear the screen
        //send_command(0x80);										//Set Display Buffer RAM address
    
    }
    
    
    void main(void)
    {
    	WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
    	lcd_init();
    
    
    	send_command(0x86);
    	__delay_cycles(5);													//5msec
    	send_string("VIKAS");
    
    	delay(5);
    	send_command(0xC0);
    	__delay_cycles(5);
    	send_string("HURGAT");
    	while(1){}
    
    
    }
    

**Attention** This is a public forum