16×2 LCD Library

This library supports communication between the MSP430G2553 and the MIDIS 16×2 LCD display using the I2C interface.

The MIDIS LCD datasheet is available here. The code written in C++ makes use of the Energia Wire library that has been ported from Arduino Wire for the I2C interface.

The I2C interface is a serial bus that allows for synchronous transmission of data in a serial fashion. It requires two lines one for the clock and one for the data. A ground connection is also required. The SDA and SCL lines require external pull-up resistors, typically 4-10k. These are required as the devices attached to the bus only pull the data line low to indicate a zero and a one is indicated by letting the line float (open drain). The MSP430G2553 uses pins P1.7 for the Serial Data (SDA) and P1.6 for the Serial Clock (SCL).

The I2C interface uses

 MSP4302553|         |LCD

                     |Pin 1 Boost Capacitor 1
                     |Pin 2 Capacitor 2 N
                     |Pin 3 Capacitor 2 P
Vcc (3.5V) |---------|Pin 4 Vdd (Boost Capacitor 1)
       Gnd |---------|Pin 5 Gnd
       P1.7|---------|Pin 6 (SDA)
       P1.6|---------|Pin 7 (SCL)
       P2.5|---------|Pin 8 (RST)
       P2.4|---------| A (Backlight Anode)
       Gnd |---------| K (Backlight Cathode)

4.7kohm pullups are used on pins 6, 7, 8. Two 1uF capacitors are required
between pins 1 and 4 and between 2 and 3 when using a 3V supply.

To install this library within Energia download and extract the LCD library folder into your libraries sub-directory of your Energia sketchbook directory.

When you restart Energia if you open the Sketch > Import Library menu, you should see LCD inside.

The LCD example code below should now also appear in File > Sketchbook > Examples

 Example code demonstrating the use of the LCD library for writing characters to
 the MIDIS 16x2 LCD display. This code initailises the LCD display an then writes
 characters that are received on the serial port to the LCD display.
 Use a any terminal program to send characters the the launchpad over the USB interface.

#include <LCD.h>

LCD mylcd(0x3E); //Create LCD object

char data;

void setup()
 mylcd.writeString("Ready to Rx now");

void loop()
 if (Serial.available()) {
 while (Serial.available() > 0) {
 //Write each character to mylcd
 data = Serial.read();
 switch (data){
 case 8: //Backspace
 case 13:
 case 10: //Carriage return
 case 0x1C: //Back Arrow
 case 0x1D: //Forward Arrow
 case 0x1E: //Up Arrow
 case 0x1F: //Down Arrow
 mylcd.writeString(data); //Write character

3 thoughts on “16×2 LCD Library

  1. This is exactly what I’m looking for, but the example doesn’t compile. I’m getting an error like this: C:\Users\………\Documents\Energia\libraries\LCD\LCD.cpp:66:3: error: ‘P2SEL2’ was not declared in this scope

    Any ideas?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s