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.

MSP430FR5739: 16x2 LCD Interfacing Problem

Part Number: MSP430FR5739

Hardware:- (MP430FR5739) (LCD :- 1602a)

Software :-  CCS 7.1

 

Problem :-

one (some time both lines) line of LCD display shows black boxes – I was struggling with this one.

 

I checked my wiring Diagram many time It's 100% same to below diagram

P1.0 => P1.7   (D0 to D7 Data line)

P2.2 => Enable

P2.1=> RS

V0 => pot middle  (10K )

Vss and  K => ground

Vdd and  A = > +5v

 

also i tried to use external power supply but result was same.

But is my simulation it's work fine.

Here is my code


#include  "stdio.h"
#include  "string.h"
#include "stdlib.h"
#define delay_value 500
 
void send_cmd(unsigned char command)
{
 
 P1OUT &= 0X00;
 P2OUT &= 0X00;
 P1OUT = command;
 P2OUT &= 0X00;
    P2OUT &= ~BIT1;                        // RS = 0 for command, P1.6 0x40
    //RW is grounded
    P2OUT &= ~BIT2;                        //EN = 0, P1.7, 0x80
    __delay_cycles(delay_value);
    P2OUT |= BIT2;                        // EN = 1, P1.7, 0x80
    __delay_cycles(delay_value);
    P2OUT &= ~BIT2;                        //EN = 0, P1.7, 0x80
    __delay_cycles(delay_value);
 
}

void send_char(unsigned char character)
{
 P1OUT &= 0X00;
 P2OUT &= 0X00;
 P1OUT = character;
  // P1OUT &= 0x00;
     P2OUT |= BIT1;                        // RS = 0 for command, P1.6
   //  RW is grounded
     P2OUT &= ~BIT2;                        //EN = 0, P1.7
     __delay_cycles(delay_value);
     P2OUT |= BIT2;                        // EN = 1, P1.7
     __delay_cycles(delay_value);
     P2OUT &= ~BIT2;                        //EN = 0, P1.7
     __delay_cycles(delay_value);
}

void send_string(char *String)
{
unsigned char i=0;
 
 while(String[i]!='\0')
 {
 
  P1OUT &= 0X00;
  P2OUT &= 0X00;
  P1OUT = String[i];
  P2OUT |= BIT1;                        // RS = 0 for command, P1.6
     //  RW is grounded
  P2OUT &= ~BIT2;                        //EN = 0, P1.7
  __delay_cycles(delay_value);
  P2OUT |= BIT2;                        // EN = 1, P1.7
  __delay_cycles(delay_value);
  P2OUT &= ~BIT2;                        //EN = 0, P1.7
  __delay_cycles(delay_value);
  if(i>=16)   // If the number of characters in the string > 16, then the below command automatically
  send_cmd(0x18);  // Shift the display right side
  __delay_cycles(40000);   // 100 millisec delay
  i++;
 }
 
}
 
void LCD_Init(void)
{
 send_cmd(0x38);   // configure LCD as 2 lined 5x7 matrix
 __delay_cycles(delay_value);
 send_cmd(0x0E);   //display on, cursor blink
 __delay_cycles(delay_value);
 send_cmd(0x06);  // auto increment of cursor
 __delay_cycles(delay_value);
 send_cmd(0x01);  // clear display
 __delay_cycles(delay_value);
 
}
 
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;
  BCSCTL2 &= ~(DIVS_3); //This line of code ensures that the SMCLK divider is 0,
   // so we have SMCLK=DCO=1MHz (in fact if we are to have a /8 divider, it should be BCSCTL2 |= DIVS_3;).
 
 
  P1DIR = 0xFF; // make P1 as output
  P2DIR = 0xFF; // make P2 as output
 

  P1SEL = 0;  // These two are "Function Select Registers PxSEL and PxSEL2",
  P1SEL = 0; // If both are zero's means simple I/O function is selected.
  //P2SEL2 = 0; // If both are zero's means simple I/O function is selected.
 
 
 
  P2DIR |= 0x01;                            // Set P1.0 to output direction
  P2REN |= 0x01;
 
 
   __delay_cycles(1500); // wait for more than 15ms after supply rises to 4.5V
   send_cmd(0x30);
   __delay_cycles(400);  // wait more than 4.1ms
   send_cmd(0x30);
   __delay_cycles(100);  // wait more than 100us, but __delay_cycles(1) will provide 1ms
   send_cmd(0x30);
   __delay_cycles(100);
   send_cmd(0x02); // return to home
   __delay_cycles(100);
 
 
  LCD_Init(); // LCD initialization
 
        
   while(1)
   {
 
   send_cmd(0x01);  // clear display
       __delay_cycles(delay_value);
       send_cmd(0x81);  // clear display
       __delay_cycles(delay_value);
       send_string("Hello  World");
       __delay_cycles(delay_value);
   send_cmd(0xC0);  // clear display
       __delay_cycles(delay_value);
       send_string("      MSP430");
       __delay_cycles(1000000);
   }
 
}

Also i tried with some other codes. but the result was same.

please help me if you can.

Thank you.

Have a nice day.

 

  • P1.4 is connected to the NTC circuitry and this could be affecting your parallel port commands/writes. Black boxes indicate that the LCD is failing to be initialized or that the contrast is too high. The 5V rail should be connected to pin 2 (Vdd) and 15 (BLA). You should make sure that all of your timing follows the LCD module specifications and use logic analyzer/oscilloscope screenshots to further debug your issue.

    Regards,
    Ryan
  • It appears as though this is a timing problem and that you haven't read the data sheet.

    Your delays when writing a character are wildly excessive. The minimum cycle time is 1us and with your chosen 1MHz clock you cannot go faster so those delay_cycles() calls just waste time for no purpose.

    On the other hand the delays in LCD_init() aren't enough. You must wait at least 15ms after power is applied, then send the function set command, wait at least 4.1ms, send it again, wait 100us, send it again.

    You are only sending the function set command once and you only wait 500us before sending the next command.

    In addition, while a comment in the code says that the RW pin of the display is grounded, you have not included that pin in your listed connections.

**Attention** This is a public forum