How to Interface a LCD Display with TIVA C Series TM4C123G LaunchPad from Texas Instruments

Published  August 12, 2019   1
Interfacing 16x2 LCD Display with TIVA C Series TM4C123G LaunchPad from Texas Instruments

In the previous tutorial, we started with learning about TIVA TM4C Launchpad and how to control its Digital Input and Output pins using Energia IDE. Now, in this tutorial, we will learn about the interfacing of 16×2 Dot matrix LCD display with this board to display useful information and sensor data.

16x2 LCD Display is the most of us would have come across this either through public PCOs or have used it in other electronics projects. 16x2 LCD is the low cost display module which is very handy for any electronics applications to display data or other debugging information. So here we are Interfacing 16x2 LCD Display with TIVA C Series TM4C123G LaunchPad. Here we will show the ADC values and voltage levels on LCD display. A potentiometer is attached to vary the ADC values. Learn more about 16x2 LCD Display and its pins here.

 

Materials Required

  1. TIVA TM4C LaunchPad from Texas Instruments
  2. 16×2 Dot matrix LCD display
  3. Connecting wires 

 

Brief Intro to 16×2 Dot matrix LCD display

As told earlier the Energia IDE provides a beautiful library which makes the interfacing a piece of cake and hence it’s not mandatory to know anything about the display module. But, would didn’t it be interesting to show what we are using!! 

The name 16×2 implies that the display has 16 Columns and 2 Rows, which together (16*2) forms 32 boxes. One single box would look something like this in the picture below

LCD-Module-Pixels

A single box has 40 pixels (dots) with a matrix order of 5 Rows and 8 columns, these 40 pixels together forms one character. Similarly, 32 characters can be displayed using all the boxes. Now lets take a look at the pinouts.

16x2-LCD-Module-Pinouts

The LCD has a total of 16 Pins, as shown above, they can be categorized into four groups like as follows

Source Pins (1, 2 and 3):  These pins source the power and contrast level for the display

Control Pins (4, 5 and 6): These pins sets/controls the registers in the LCD interfacing IC (more this can be found in link below)

 Data/Command Pins (7 to 14): These pins provide the data of what information should be displayed on the LCD.

LED pins (15 and 16): These pins are used to glow the backlight of LCD if needed (optional).

 

Out of all these 16 pins, only 10 pins are to be used mandatory for the proper working of the LCD if you want to know more about these LCD display jump to this LCD article.

Also check interfacing of 16x2 LCD display with many other microcontrollers

 

ADC in TIVA Launchpad

Potentiometer provides analog output so it cant be connected to the digital pins of the Launchpad. So Analog or ADC pins of the MCU are used to interface any sensor whose output is analog in nature. TIVA TM4C has 2 ADC channels with 12-bit output this means that the analog values, from the sensor or potentiometer, can be mapped between 0 to 2^12 (4096) in order to convert them into digital values. To learn more about Analog to Digital conversion in Microcontroller, follow the link.

There are 12 analog input pins (A0-A11) in TIVA Launchpad as shown in the image below.

Tiva C Series TM4C123G LaunchPad Front Pinout

 

Circuit Diagram and Connections

The complete circuit diagram to interface a 16×2 Dot matrix LCD display with TIVA Launchpad TM4C is shown below.

Circuit Diagram for Interfacing 16x2 LCD Display with TIVA C Series

 

One major constraint while interfacing these LCD is its operating voltages. The LCD display has an operating voltage of +5V while the TM4C operates only with 3.6V. Lucky for us the data pin of LCD interface IC (HD44780U) has a wide operating voltage of 2.7V to 5.5V. So we have to only worry about the Vdd (pin 2) of the LCD while the data pins can work even with 3.6V.

The TIVA board by default does not has a +5V pin, so an external power supply should be used to make the LCD work. Either use power supply from Arduino board or use 7805 voltage regulator. Make sure to connect the ground of power supply with the ground of the TIVA board.

Below is the table showing the connections between LCD and TIVA Launchpad

LCD pin name TIVA Launchpad
Vss Ground
Vdd +5V power supply
Rs Pin PC_6 of TIVA
R/W Ground
Enable Pin PB_7 of TIVA
D4 Pin PA_2 of TIVA
D5 Pin PA_3 of TIVA
D6 Pin PA_4 of TIVA
D7 Pin PB_6 of TIVA

 

To display the potentiometer values on LCD, connect Pot output to any analog pin (PE2).

 

Programming TIVA TM4C Launchpad for LCD using Energia IDE

Before proceeding with the explanation, make a note of the pins that are used in this project. Take a look at the circuit diagram and the TIVA pin-out diagram given above. Complete code with a working video is attached at the end of this tutorial.

Energia IDE, by default, comes with Library for 16x2 LCD (LiquidCrystal). If its not present then download it from this github link and paste it in libraries folder of Energia IDE.

Then start the program by including the library for LCD and defining the pins for it

#include <LiquidCrystal.h>
#define RS PC_6
#define EN PB_7
#define D4 PA_2
#define D5 PA_3
#define D6 PA_4
#define D7 PB_6
#define sensorPin PE_2

 

The next step is to mention the pins to which the LCD is connected to, as we have already named it using the #define we can now simply mention the names of the LCD pins. Make sure the same order is followed.

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

 

There are so many types of LCD displays varying in size and nature, so in void setup() function, first specify the type of LCD you are using in the project. Here we have used 16x2 LCD display.

lcd.begin(16, 2);

 

To print something on the LCD, mention two things in the program. One is the position of the text which can be mentioned using the line lcd.setCursor() and other is the content to print which can be mentioned by lcd.print(). Here we are setting the cursor to 1st row and 1st column. 

lcd.setCursor (0,0);

 

Similarly, we can also do

lcd.setCursor(0, 1);   // to set the cursor to 1st column 2nd row

 

Just like erasing a whiteboard after writing on it, an LCD should also be erased once something is written on it. This can be done by using the below line

lcd.clear();

 

In void loop() function, take the pot value using analogRead() function and store this value in another variable and then display this value.

sensorValue = analogRead(sensorPin); 
lcd.setCursor(0, 0);
lcd.print("ADC value:");
lcd.setCursor(10, 0);
lcd.print(sensorValue); 

 

Now, convert this ADC value to voltage just by multiplying it with 3.3 because it is the highest voltage that can accepted by TIVA boards pins. Then divide the multiplied value with 4096.

lcd.setCursor(0, 1);
lcd.print("Voltages:");
voltages=(sensorValue*3.3)/4096;
lcd.setCursor(10, 1);
lcd.print(voltages);

 

Complete program can be found at the end.

 

16x2 LCD Display with TIVA Launchpad

Once the hardware and code is ready, simply connect the TIVA board to the computer and upload the code into the board. Follow the previous tutorial to learn how to upload the code in TIVA Launchpad.

Once the code is uploaded you should see the display showing the following.

Interfacing 16x2 LCD Display with TIVA C Series TM4C123G LaunchPad from Texas Instruments

 

Now, just rotate the potentiometer to vary the ADC value and you will see that the corresponding voltage value will also vary, as shown in the below picture.

Circuit Hardware for Interfacing 16x2 LCD Display with TIVA C Series

 

The complete code and the detailed video can be found below. Go ahead and try changing the text being displayed on the LCD display.  

Code

#include <LiquidCrystal.h>
#define RS PC_6
#define EN PB_7
#define D4 PA_2
#define D5 PA_3
#define D6 PA_4
#define D7 PB_6
#define sensorPin PE_2

int sensorValue ;
float voltages;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
void setup() {
   lcd.begin(16, 2);
   lcd.setCursor(0, 0);
  lcd.print("CircuitDigest");
  delay(2000);
}

void loop() {
  sensorValue = analogRead(sensorPin); 
  lcd.setCursor(0, 0);
  lcd.print("ADC value:");
  lcd.setCursor(10, 0);
  lcd.print(sensorValue); 
  lcd.setCursor(0, 1);
  lcd.print("Voltages:");
  voltages=(sensorValue*3.3)/4096;
  lcd.setCursor(10, 1);
  lcd.print(voltages);
delay(1000);
}

Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Hi Sir,

I am ali , i am a student of electronics technolgy i am seeking the project regarding TIVA , i want to generate PWM with 5KHz frequency , can you help me out in this regards,

Thanks

Ali Raza