Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: Nzoka on August 01, 2017, 12:54:05 PM

Title: Code example: NHD-C0220BiZ-FSW-FBW-3V3M with TI MSP432P401R launchpad
Post by: Nzoka on August 01, 2017, 12:54:05 PM
Posting this to help others trying to use this LCD.

This was my setup as per page 4 of the LCD Data sheet,
I have C = 1uF, 16V. 
R (The pullups) on SDA and SCL are 10kohms each.
I have a 1kohm pullup on RST and a 1kohm resistor from the Anode of the backlight to the 3.19V power supply.
I have a 0.1uF bypass capacitor across Vdd and Vss.

SDA is connected to P6.4 of the Launchpad
SCL is connected to P6.5 of the Launchpad
I set up my board to run at 48Mhz
After setting up EUSCI_B1_BASE,
the following can be used:
*********************************
// I2C LCD Slave address
#define SLAVE_ADDRESS   0x3C    // 0x3C = (0x78<<1) since i2c sends 7 bit address

#define LCDCOMMANDMODE   0x00
#define LCDDATAMODE      0x40

#define LINEONE         0x00
#define LINETWO         0xC0

unsigned char text1[]={"NEWHAVEN DisplayXXXX"};
unsigned char text2[]={"2x20 LCD Module XXXX"};


void LCDinit();
void LCDsendLinenum(unsigned char linenum);
void LCDsendData( unsigned int bufferlength, unsigned char *buffer);
void LCDsendCommand( unsigned int bufferlength, unsigned char *buffer);

void my48Mdelayms(unsigned int x); // Crude millisecond delay function based on MCLK of 48Mhz

void LCDinit()
{
        my48Mdelayms(40);   // Delay for 40ms upon power up or reset
        MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, 0x00); // Send start, address and Command mode byte (0x40)
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x38);  //Function set - 8 bit, 2 line display 5x8, inst table 0
        my48Mdelayms(10);
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x39);   //Function set - 8 bit, 2 line display 5x8, inst table 1
        my48Mdelayms(10);
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x14);  // Set bias - 1/5
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x78);  // Set contrast low
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x5E);  // ICON disp on, Contrast high byte
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x6D);  // Follower circuit (internal), amp ratio (6)
        my48Mdelayms(300);
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x0E);  // Display on, cursor on 0x0C
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x01);  // Clear display
        my48Mdelayms(2);
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x06);  // Entry mode set - increment
        my48Mdelayms(2);
        MAP_I2C_masterSendMultiByteStop(EUSCI_B1_BASE);  // End Transmission


}

void LCDsendCommand( unsigned int bufferlength, unsigned char *buffer)
{
    unsigned int i;
    MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, LCDCOMMANDMODE); // Send start, address and Command mode byte
    for(i = 0 ; i < bufferlength; i++)
    {
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, buffer);
    }
    MAP_I2C_masterSendMultiByteStop(EUSCI_B1_BASE);  // End Transmission

}

void LCDsendData( unsigned int bufferlength, unsigned char *buffer)
{
    unsigned int i;
    MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, LCDDATAMODE); // Send start, address and Data mode byte
    for(i = 0 ; i < bufferlength; i++)
    {
        MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, buffer);
    }
    MAP_I2C_masterSendMultiByteStop(EUSCI_B1_BASE);  // End Transmission

}



void LCDsendLinenum(unsigned char linenum)
{
    unsigned char buff[1];
    buff[0] = linenum;

    LCDsendCommand(1, buff);

}




void my48Mdelayms(unsigned int x)
{
    unsigned int i;

    for (i = 0; i< x; i++)
    {
        __delay_cycles(48000) ;
    }

}


main()
{
-- Initialize launchpad
-- Initialize IC2 and enable it for transmit mode.

    LCDinit();  // I2C LCD initialization

    LCDsendLinenum(LINEONE);    // Start displaying at line 1
    LCDsendData( 20, text1);

    LCDsendLinenum(LINETWO);    // Start displaying at line 2
    LCDsendData( 20, text2);


}
Title: Re: Code example: NHD-C0220BiZ-FSW-FBW-3V3M with TI MSP432P401R launchpad
Post by: Saurabh_B on August 02, 2017, 08:19:37 AM
Hello,

Glad to see you have the display working, and thanks for uploading your code.