Author Topic: Code example: NHD-C0220BiZ-FSW-FBW-3V3M with TI MSP432P401R launchpad  (Read 412 times)

Nzoka

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
    • View Profile
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);


}
« Last Edit: August 02, 2017, 09:45:43 AM by Nzoka »

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 363
  • Karma: 10
    • View Profile
Re: Code example: NHD-C0220BiZ-FSW-FBW-3V3M with TI MSP432P401R launchpad
« Reply #1 on: August 02, 2017, 08:19:37 AM »
Hello,

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

 

NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM capacitor on pin 7&8

Started by Ticoti0xFFBoard Character LCDs

Replies: 1
Views: 2868
Last post April 09, 2014, 10:17:30 AM
by Michael_L
NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM Potting

Started by SebKisterBoard Character LCDs

Replies: 1
Views: 1885
Last post June 22, 2016, 04:51:17 PM
by Saurabh_B
Blank Display on NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM

Started by SteveCBoard Character LCDs

Replies: 3
Views: 4706
Last post May 13, 2014, 12:04:36 AM
by SteveC
NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM - Cable for LED Backlights

Started by wadehBoard Character LCDs

Replies: 2
Views: 928
Last post December 02, 2016, 06:02:27 PM
by wadeh
Using Linux i2cdetect with NHD‐C0220BiZ‐FSW‐FBW on Raspberry Pi

Started by russkBoard Character LCDs

Replies: 9
Views: 5491
Last post August 21, 2017, 02:11:20 PM
by Saurabh_B