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.

Interfacing MSP430F5529 to a 16*2 LCD

Other Parts Discussed in Thread: MSP430F5529, MSP430G2553

hi Caleb Overbay,

ok fine ill put the while loop.

Today i tried interfacing 16*2 lcd on msp430f5529 here is my program.

/*port pin details*/

/*P1.2=RS

P1.3=RW

P1.3=EN

P2.4=D4   //sending data using 4-bit 

P2.5=D5

P2.6=D6

P2.7=D7*/

#include <msp430.h>
#include <in430.h>
#include <math.h>
/*
* main.c
*/

unsigned int cnt,j,dat;
void init_lcd();
void cmd_wr(unsigned char ch);
void data_wr();
void delay(unsigned int i);
void enable();

int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = 0x1c;
P2DIR = 0xF0;

init_lcd();
cmd_wr(0x85);
dat = 'A';
data_wr();
while(1);

}

void init_lcd()
{
delay(5);
delay(5);
delay(5);
cmd_wr(0x03);
delay(5);
cmd_wr(0x03);
delay(5);
cmd_wr(0x03);
delay(5);

cmd_wr(0x02);
delay(5);
cmd_wr(0x28);
delay(5);
cmd_wr(0x0e);
delay(5);
cmd_wr(0x01);
delay(5);
}


void cmd_wr(unsigned char ch)
{
P1OUT=0x00;    //RS=0 ,RW=0
P2OUT=(ch & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(ch<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}

void data_wr()
{
P1OUT=0x40; // RS=1,RS=0
P2OUT=(dat & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(dat<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}


void enable()
{
P1OUT=0x10;      //enable=1   
_nop();
_nop();
_nop();
_nop();
_nop();
P1OUT=0x00;    //enable=0
}

/*void delay(unsigned int i)
{
for(cnt=0;cnt<=i;cnt++)
{
for(j=0;j<=120;j++)
{
}
}
}*/


void delay(unsigned int delay_time)
{
unsigned int count;
for(count = 0;count < delay_time;count++)
{

}
}

The program is not working can u plz guide me.

Regards,

Neha.

  • Hi Neha, 

    I split this into a new thread because it's regarding a separate topic. I'll take a look at your code and get back to you soon.

    Best regards, 
    Caleb Overbay

  • Hi Neha,

    I took a closer look at your code and here are my comments:

    First, the MSP430F5529 does not have an LCD controller, so you would have to be controlling the LCD with some other device and the LCD is just receiving data from the MSP430.

    Second, the code you've posted above is very dependent on hardware. That is how the LCD is connected to the MSP, the commands the LCD is expecting, and the timing it takes to receive those commands/data.

    I can't really provide any constructive feedback of the code above without seeing all the details (ie schematics, LCD your interfacing too, etc.)

    Best regards,
    Caleb Overbay
  • Hi Neha,

    Do you still need assistance with this topic?

    Best regards,
    Caleb Overbay
  • hello
    i need assistance regarding my code for msp430f5529 can you please guide
  • Hi Neetee,

    If you need help with the MSP430F5529 please create a new post with a detailed description of the issue you're experiencing and I can help you there.

    Best regards,
    Caleb Overbay
  • Hi Neha!

    Although your initial post is a little bit older already...

    Did you check if this

    NEHA SONAWDEKAR said:
    P2OUT=(dat & 0xf0 | P2OUT & 0x0f);

    has the effect you want?

    When a HD44780 display does not work as expected you should always check the timing. I can see a delay loop in your code - is this called during the debugging? Such delay loops are often optimized away. The display definitely needs the given wait times between commands.

    I just built something with a HD44780 myself, also in 4-bit mode, but 4x20. I can give you some working routines for the initialization and for writing data to the display, maybe you can get some useful information from it. My MSP430G2553 processor only ran at 1MHz, so the timing wasn't that critical. I only added some delay in the initialization. And I used this timer delay variable for other things in my program already.

    #FreeSampleCode

    #define HD44780_ENABLE_HIGH                    (P1OUT |=  0x80)
    #define HD44780_ENABLE_LOW                     (P1OUT &= ~0x80)
    #define HD44780_DATA                           (P1OUT |=  0x40)
    #define HD44780_COMMAND                        (P1OUT &= ~0x40)
    #define HD44780_NIBBLE_MASK                    (0x10 | 0x20 | 0x40 | 0x80)
    #define DATA                                   0
    #define COMMAND                                1
    
    
    void hd44780_initialization( void );
    void hd44780_send_string( char * string );
    void hd44780_send_byte( uint8_t byte, uint8_t command_data );
    void hd44780_set_cursor( uint8_t row, uint8_t column );
    
    
    volatile uint16_t timer_10ms_down_counter = 0;
    
    
    void main( void )
    {
      ...
    
      TA0CCR1  = 10000;
      TA0CCTL1 = CCIE;
      TA0CTL   = (TASSEL_2 | ID_0 | MC_2 | TACLR);
    
      ...
    
      hd44780_initialization();
    
      hd44780_set_cursor( 1, 1 );
      hd44780_send_string( "Test" );
    
      hd44780_set_cursor( 2, 1 );
      hd44780_send_byte( 'T', DATA )
      hd44780_send_byte( 'e', DATA )
      hd44780_send_byte( 's', DATA )
      hd44780_send_byte( 't', DATA )
    
      ...
    }
    
    
    void hd44780_initialization( void )
    {
      uint8_t counter;
    
      //                       Interface   Function set   Display control   Display clear   Entry mode
      uint8_t config_bytes[9] = {0x20,      0x20, 0x80,     0x00, 0xC0,      0x00, 0x10,    0x00, 0x60};
    
      HD44780_COMMAND;
    
      for( counter = 0; counter < 12; counter++ )
      {
        HD44780_ENABLE_HIGH;
        P2OUT &= ~HD44780_NIBBLE_MASK;
    
        if( counter < 3 )
        {
          P2OUT |= 0x30;
        }
        else
        {
          P2OUT |= config_bytes[(counter - 3)];
        }
    
        HD44780_ENABLE_LOW;
        timer_10ms_down_counter = 5;
        while( timer_10ms_down_counter );
      }
    }
    
    
    void hd44780_send_string( char * string )
    {
      while( *string )
      {
        hd44780_send_byte( *string, DATA );
        string++;
      }
    }
    
    
    void hd44780_send_byte( uint8_t byte, uint8_t command_data )
    {
      if( command_data == DATA )
      {
        HD44780_DATA;
      }
      else
      {
        HD44780_COMMAND;
      }
    
      HD44780_ENABLE_HIGH;
      P2OUT &= ~HD44780_NIBBLE_MASK;
      P2OUT |= (byte & 0xF0);
      HD44780_ENABLE_LOW;
      HD44780_ENABLE_HIGH;
      P2OUT &= ~HD44780_NIBBLE_MASK;
      P2OUT |= ((byte << 4) & 0xF0);
      HD44780_ENABLE_LOW;
    }
    
    
    void hd44780_set_cursor( uint8_t row, uint8_t column )
    {
      uint8_t row_start_address[4] = { 0x00, 0x40, 0x14, 0x54 };
      uint8_t command_byte;
    
      if( (row >= 1) && (row <= 4) )
      {
        if( (column >= 1) && (column <= 20) )
        {
          command_byte = ((row_start_address[(row - 1)] + (column - 1)) | 0x80);
          hd44780_send_byte( command_byte, COMMAND );
        }
      }
    }
    
    
    #pragma vector = TIMER0_A1_VECTOR
    __interrupt void timer0_a1_isr( void )
    {
      switch( TA0IV )
      {
        case TA0IV_TACCR1:
        {
          TA0CCR1 += 10000;
    
          if( timer_10ms_down_counter )
          {
            timer_10ms_down_counter--;
          }
        }
      }
    }

    Dennis

**Attention** This is a public forum