Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

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.

CCS/MSP432P401R: Interface with LCD using other person's code who has successfully used this code

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi, Guys

I found this code in E2E and seems this person has successfully used this code to interface with his LCD screen. However I downloaded his code and compiled into my Launchpad and it does not seems to work. Could really use some help with this. I have attached the code. Although I could interface LCD through Energia, but I really wants to use code composer studio. 

7028.main.c
/*****************************************************************/
/*********                                               *********/
/********* AUTOR:    ANTONIO ARMANDO BIZA FERREIRA       *********/
/********* PROJECTO: ECG                                 *********/
/********* DATA:     01-02-2017                          *********/
/********* IDE:      CODE COMPOSER STUDIO V6.2           *********/
/********* MCU:      MSP432                             *********/
/*********                                               *********/
/********* FILE:     MAIN.C                              *********/
/*********                                               *********/
/*****************************************************************/

#include <msp432.h>
#include "main.h"
#include "lcd.h"

void main(void)
{
    volatile uint32_t i;

    WatchDogHold();
    LCD_PortConfig();
    LCD_Initialize();
    APP_Initialize();
    while(1){

    }


}

void APP_Initialize(void){
     LCD_SetText("TESTING",3 ,0);
}

void WatchDogHold(void){
     WDTCTL = WDTPW | WDTHOLD; /*STOP WATCHDOG TIMMER*/
}
2438.lcd.c
/*****************************************************************/
/*********                                               *********/
/********* AUTOR:    ANTONIO ARMANDO BIZA FERREIRA       *********/
/********* PROJECTO: ECG                                 *********/
/********* DATA:     01-02-2017                          *********/
/********* IDE:      CODE COMPOSER STUDIO V5             *********/
/********* MCU:      MSP432                              *********/
/*********                                               *********/
/********* FILE:     LCD.H                               *********/
/*********                                               *********/
/*****************************************************************/


/*****************************************************************/
/********* INCLUDE                                       *********/
/*****************************************************************/
#include "lcd.h"

/*****************************************************************/
/********* DEFINES                                       *********/
/*****************************************************************/

#define EN                      (PORT2 + BIT3)
#define RS                      (PORT6 + BIT7)

#define D4                      (PORT2 + BIT6)
#define D5                      (PORT2 + BIT4)
#define D6                      (PORT5 + BIT6)
#define D7                      (PORT6 + BIT6)

/*COMMAND*/
#define CLEAR                   0x01

/*****************************************************************/
/********* LOCAL FUNCTIONS                               *********/
/*****************************************************************/

/*LCD PIN OUT DIRECTION*/
void lcdDirPinOut(unsigned int pin){

    if((pin & 0xFF00) == PORT2){

        P2DIR |= (pin & 0x00FF);

    }else if((pin & 0xFF00) == PORT5){

        P5DIR |= (pin & 0x00FF);

    }else{

        P6DIR |= (pin & 0x00FF);

    }

}

/*LCD PIN OUT SET*/
void lcdSetPinOut(unsigned int pin){

    if((pin & 0xFF00) == PORT2){

        P2OUT |= (pin & 0x00FF);

    }else if((pin & 0xFF00) == PORT5){

        P5OUT |= (pin & 0x00FF);

    }else{

        P6OUT |= (pin & 0x00FF);

    }

}


/*LCD PIN OUT CLR*/
void lcdClrPinOut(unsigned int pin){

    if((pin & 0xFF00) == PORT2){

        P2OUT &= ~(pin & 0x00FF);

    }else if((pin & 0xFF00) == PORT5){

        P5OUT &= ~(pin & 0x00FF);

    }else{

        P6OUT &= ~(pin & 0x00FF);

    }

}

void lcdSetValue(unsigned char value){

     if(value & 0x08){
            lcdSetPinOut(D7);
        }else{
            lcdClrPinOut(D7);
        }

        if(value & 0x04){
            lcdSetPinOut(D6);
        }else{
            lcdClrPinOut(D6);
        }

        if(value & 0x02){
            lcdSetPinOut(D5);
        }else{
            lcdClrPinOut(D5);
        }

        if(value & 0x01){
            lcdSetPinOut(D4);
        }else{
            lcdClrPinOut(D4);
        }
        delay_us(5);
}

void lcdTriggerEN(){

    lcdSetPinOut(EN);
    delay_us(5);
    lcdClrPinOut(EN);
  // delay_us(5);
}

void lcdWriteData(unsigned char data){
    lcdSetPinOut(RS);           // Set RS to Data
    lcdSetValue(data >> 4);     // Upper nibble
    lcdTriggerEN();
    lcdSetValue(data);          // Lower nibble
    lcdTriggerEN();
    delay_us(30);               // Delay > 50 us
}

void lcdWriteCmd(unsigned char cmd){
    lcdClrPinOut(RS);           // Set RS to Cmd
    lcdSetValue(cmd >> 4);      // Upper nibble
    lcdTriggerEN();
    lcdSetValue(cmd);           // Lower nibble
    lcdTriggerEN();
    delay_ms(2);                // Delay > 5ms
}




/*****************************************************************/
/********* GLOBAL FUNCTIONS                              *********/
/*****************************************************************/

/*
 *
 */
void LCD_PortConfig(void)
{
    // Direction
    lcdDirPinOut(D4);
    lcdDirPinOut(D5);
    lcdDirPinOut(D6);
    lcdDirPinOut(D7);
    lcdDirPinOut(EN);
    lcdDirPinOut(RS);
}


/*
 *
 */
void LCD_Initialize(void)
{

   /* delay_us(80);
    lcdWriteCmd(0x28); // 4-bit, 2 line, 5x8
    P2OUT = 0x03;      // Start LCD (send 0x03)
    lcdTriggerEN();    // Send 0x03 3 times at 5ms then 100 us
    delay_ms(2);
    lcdTriggerEN();
    delay_ms(2);
    lcdTriggerEN();
    delay_ms(2);

    lcdWriteCmd(0x28); // 4-bit, 2 line, 5x8
    P2OUT = 0x02;      // Switch to 4-bit mode
    lcdTriggerEN();
    delay_ms(2);*/


    lcdWriteCmd(0x28); // 4-bit, 2 line, 5x8
    lcdWriteCmd(0x08); // Instruction Flow
    lcdWriteCmd(0x01); // Clear LCD
    lcdWriteCmd(0x06); // Auto-Increment
    lcdWriteCmd(0x0C); // Display On, No blink
}


void LCD_SetText(char* text, int x, int y){
    unsigned int i;

    if (x < 16) {
        x |= 0x80;      // Set LCD for first line write
        switch (y){
        case 1:
            x |= 0x40;  // Set LCD for second line write
            break;
        case 2:
            x |= 0x60;  // Set LCD for first line write reverse
            break;
        case 3:
            x |= 0x20;  // Set LCD for second line write reverse
            break;
        }
        lcdWriteCmd(x);
    }

    i = 0;
    while (text[i] != '\0') {
        lcdWriteData(text[i]);
        i++;
    }
}

void LCD_SetInt(int val, int x, int y)
{
    char number_string[16];

    sprintf(number_string, "%d", val); // Convert the integer to character string
    LCD_SetText(number_string, x, y);
}

void LCD_Clear()
{
    lcdWriteCmd(CLEAR);
}

void LCD_LoadSymbols(void)
{
    int j;
    static char empty[]   = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    static char heart[]   = {0x00, 0x0A, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00};
    static char bat_100[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F};
    static char bat_75[]  = {0x0E, 0x1F, 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F};
    static char bat_50[]  = {0x0E, 0x1F, 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x1F};
    static char bat_25[]  = {0x0E, 0x1F, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F};
    static char bat_0[]   = {0x0E, 0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F};

    lcdWriteCmd(0x40);


    for(j=0;j!=8;j++){
        lcdWriteData(empty[j]);
    }

    for(j=0;j!=8;j++){
        lcdWriteData(heart[j]);
    }

    for(j=0;j!=8;j++){
        lcdWriteData(bat_100[j]);
    }

    for(j=0;j!=8;j++){
        lcdWriteData(bat_75[j]);
    }
    for(j=0;j!=8;j++){
        lcdWriteData(bat_50[j]);
    }
    for(j=0;j!=8;j++){
        lcdWriteData(bat_25[j]);
    }
    for(j=0;j!=8;j++){
        lcdWriteData(bat_0[j]);
    }

    lcdWriteCmd(CMD_END);
}

void LCD_SetSymbol(unsigned char symbol, unsigned char offset, unsigned char line)
{
    lcdWriteCmd(line+offset);
    lcdWriteData(symbol);
}
5518.main.h8233.lcd.h

  • Jeffrey,
    Could you provide some more information so I can help you? Namely, I'd need the following:
    1. a link to the post you referenced would be really helpful.
    2. Which LCD are you using? If your LCD is different, then the code from another user isn't likely to work.
    3. Confirm you are using MSP432P401 Red LaunchPad

    Regards,
    Bob L.
  • Hi, Bob
    Thank you for offering help. I could really use some help on these. Here are the answer for you questions. Please let me know if you require some more information that I could provide. When I tested his code on Red Launchpad , I used exact the same pin as he was used, but the LCD screen shows nothing.

    1. e2e.ti.com/.../577139
    2. I have two different LCD here, one is a general <1602 16x2 parallal character arduino LCD>
    My final goal is use 20x4 LCD here is the link for 20 x 4
    www.onlinecomponents.com/.../nhd0420e2znswbbw.aspx
    I have tried both of them and none of those two LCDs shows words.
    3. Not really, I'm using the Launchpad to test the code, but I have my own project just to use MSP432P401R chip. I thought if the code works in Red Launchpad then it would work on the project.
  • Jeffrey,
    The LCD you mention, NHD0420e2znswbbw, is a 5V device and can generate outputs that are above the MSP432 device Max input voltage, which can result in damage to the device. Also, the required input voltages for this LCD (controller) are 0.7 x Vdd = 3.15v min at Vdd=4.5v. Given the nominal 3.3v Vdd for the LaunchPad, it's possible that the LaunchPad isn't geneating a voltage high enough to be interpreted as a "1" by the LCD controller.

    Looking at the LCD controller datasheet referenced inside the NHD0420e2znswbbw (LCD module) datasheet, the Vcc voltage range and inputs are different (a bit lower- 2.7-4.5v), so it's not clear which is correct since the 2 datasheets conflict. If the controller Vcc is "legal " but on the high end, then you may still have problems (or, sometimes, it may work).

    Can you verify the voltage ranges of the input/outputs to/from the LCD?


    Regards,
    Bob L.
  • Hi Bob

    Thanks for the reply,
    Both of my LCDs are works fine if I use Energia LCD library and it will display anything I want it. however, when I use code composer and this guys code it will not display anything. so could you help with code and to see if there anything was config wrong or something. Thank you.
  • I would recommend focusing on number 2 and determine how the Energia and User code you refer to configure the LCD.

    Regards,
    Chris
  • Hi Mr. Jeffrey,

    Try to add this to your Energia Library and build it inside CCS.

    LiquidCrystal.zip

    This LCD library can use the I2C I/O Expander PCF8574.

    The connection details and command usage is detailed on the link below.

    This I/O Expander can run on both 3.3V to 5V DC.

    I have included as well the P82B96 datasheet for you to see how the 5Volts 2x16 LCD and 5 Volts PCF8574 will translate to 3.3 volts DC

    I already simulated and migrated it successfully from Arduino to Energia Version.

    P82B96 I2C Bus Expander.pdf

    Thanks and Good Day,

    Leo

**Attention** This is a public forum