16x2 LCD With TIVa Manual
16x2 LCD With TIVa Manual
16x2 LCD With TIVa Manual
Tools Used
The tools we are going to use in this experiment are listed as below
1.Tiva C Launchpad
http://www.ti.com/tool/ek-tm4c123gxl
2. A 16x2 LCD
http://www.engineersgarage.com/electronic-components/16x2-lcd-module-datasheet
3. A 10k POT
4. 220Ohm resistor
Requirements
A user needs to have full access to the all required documents related to the tools used and other
software packages needed to support the programming part.
You can download the related documents from the following links
3. TM4C123GH6PM Datasheet
http://www.ti.com/lit/ds/spms376e/spms376e.pdf
4. TI_TivaWare
http://www.ti.com/tool/sw-tm4c#Technical Documents
1|Page
Interfacing a 16x2 LCD with TIVA TM4C123
The two extra pins in our Lcd are backlight+ and backlight- to control backlight of lcd.
8-Data pins carries 8-bit data or command from an external unit such as microcontroller.
RS(Register select)
2|Page
Interfacing a 16x2 LCD with TIVA TM4C123
EN (Enable signal)
When you select the register(Command and Data) and set RW(read - write) now it’s time to execute the
instruction. By instruction i mean the 8-bit data or 8-bit command present on Data lines of lcd.
This requires an extra voltage push to execute the instruction and EN (enable) signal is used for this
purpose. Usually we make it en=0 and when we want to execute the instruction we make it high en=1
for some milli seconds. After this we again make it ground en=0. Data which we send to our lcd can be
any alphabet (small or big) , digit or ASCII character.
NOTE: we can not send an integer, float, long, double type data to lcd because lcd is designed to display
a character only. The 8 data pins on lcd carries only ASCII 8-bit code of the character to lcd. However we
can convert our data in character type array and send one by one our data to lcd. Data can be sent
using lcd in 8-bit 0r 4-bit mode. If 4-bit mode is used, two nibbles of data (First high four bits and then
low four bits) are sent to complete a full eight-bit transfer. 8-bit mode is best used when speed is
required in an application and at least ten I/O pins are available. 4-bit mode requires a minimum of
seven bits. In 4-bit mode, only the top 4 data pins (4-7) are used.
3|Page
Interfacing a 16x2 LCD with TIVA TM4C123
Standard Lcd Commands with their functions are described with their
functionality below.
Command 0x30 means we are setting 8-bit mode lcd having 1 line and we are initializing it to be
5x7 character display. Now this 5x7 is something which everyone should know what it stands
for. Usually the characters are displayed on lcd in 5x8 matrices form. Where 5 is total number
of coulombs and 8 is number of rows.Thus the above 0x30 command initializes the lcd to
display character in 5 coulombs and 7 rows the last row we usually leave for our cursor to move or blink
etc.
4|Page
Interfacing a 16x2 LCD with TIVA TM4C123
The Character is displayed on lcd screen in 5x8 or 5x7 matrix. Where 5 represents number of
coulombs and 7 represent number of rows. Maximum size of the matrix is 5x8. You cannot display
character greater then 5x8 dimension matrix. To display character greater than this dimension you have
to switch to graphical lcd’s.
The command 0x38 means we are setting 8-bit mode lcd having two lines and character shape
between 5x7 matrix.
The command 0x20 means we are setting 4-bit mode lcd having 1 line and character shape
between 5x7 matrix.
The command 0x28 means we are setting 4-bit mode lcd having 2 lines and character shape
between 5x7 matrix.
The command 0x06 is entry mode it tells the lcd that we are going to use you.
The command 0x08 displays cursor off and display off but without clearing DDRAM contents
The command 0x0E displays cursor on and display on.
The command 0x0c display on cursor off(displays cursor off but the text will appear on lcd).
The command 0x0F display on cursor blink(text will appear on screen and cursor will blink).
The command 0x18 shift entire display left (shift whole off the text on the particular line to its
left).
The command 0x1C shift entire display right (shift whole off the text on the particular line to its
right).
The command 0x10 Moves cursor one step left or move cursor on step ahead to left when ever
new character is displayed on the screen.
The command 0x14 Moves cursor one step right or move cursor on step ahead to right when
ever new character is displayed on the screen.
The command 0x01 clear all the contents of the DDRAM and also clear the lcd removes all the
text from the screen.
The command 0x80 initialize the cursor to the first position means first line first matrix(start
point) now if we add 1 in 0x80+1=0x81 the cursor moves to second matrix.
16x1 lcd displays 16 characters only. The first will appear on 0x80 second 0x81 third 0x82 and so on until
last, the 16 once on address 0x8F.
5|Page
Interfacing a 16x2 LCD with TIVA TM4C123
NOTE: You can send commands in hexadecimal or decimal form which one do you like the result is same
because the microcontroller translates the command in 8-bit binary value and send it to the lcd. Before
you send commands and data to your lcd. Lcd must first be initialized. This initialization is very
important for lcd, If you don't initialize it properly you will see nothing on your lcd.
2. Write command 0x30 to LCD and wait 5 milli seconds for the instruction to complete.
3. Write command 0x30 to LCD and wait 160 micro seconds for instruction to complete.
4. Write command 0x30 AGAIN to LCD and wait 160 micro seconds or Poll the Busy Flag.
In 4-bit mode the high nibble is sent first before the low nibble and the EN pin is toggled each
2. Write command 0x03 to LCD and wait 5 msecs for the instruction to complete.
3. Write command 0x03 to LCD and wait 160 usecs for instruction to complete.
4. Write command 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag).
6|Page
Interfacing a 16x2 LCD with TIVA TM4C123
The LCD display will also require additional pins to be connected to Vcc or GND, including:
Power and ground for the LCD.
Power and ground for the LCD backlight (if applicable)
Ground connection of the R/W pin (to enable writing to the LCD).
A potentiometer between Vcc and GND to pin 5 for adjusting display contrast.
Here is the pinout used in my version of the LCD library for the TivaC Launchpad.
The Code
To upload the code on Tiva launchpad we need to create a new project and then select the
target as Tiva TM4C123GH6PM.Copy the following code in main.c file of the project and the
build and debug the code.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
7|Page
Interfacing a 16x2 LCD with TIVA TM4C123
{
GPIOPinWrite(GPIO_PORTD_BASE,PDMask,~(PDMask));//clearing data bits to 0
GPIOPinWrite(GPIO_PORTE_BASE,PEMask,~(PEMask));//clearing the bits EN and RS
//to 0
GPIOPinWrite(GPIO_PORTD_BASE,PDMask,(value&0xF0)>>4);
if(status==TRUE)
{
GPIOPinWrite(GPIO_PORTE_BASE,PIN_RS,HIGH);
}
else
{
GPIOPinWrite(GPIO_PORTE_BASE,PIN_RS,LOW);
}
Push();
GPIOPinWrite(GPIO_PORTD_BASE,PDMask,~(PDMask));//clearing the data bits to 0
GPIOPinWrite(GPIO_PORTE_BASE,PEMask,~(PEMask));
GPIOPinWrite(GPIO_PORTD_BASE,PDMask,value&0x0F);
if(status==TRUE)
{
GPIOPinWrite(GPIO_PORTE_BASE,PIN_RS,HIGH);
}
else
{
GPIOPinWrite(GPIO_PORTE_BASE,PIN_RS,LOW);
}
Push();
8|Page
Interfacing a 16x2 LCD with TIVA TM4C123
void LCD_init(void)
{
GPIOPinWrite(GPIO_PORTD_BASE,PDMask,~(PDMask));//LCD Initialization Steps
GPIOPinWrite(GPIO_PORTE_BASE,PEMask,~(PEMask));
SysCtlDelay(200000);
//4 bit mode
}
void LCD_clear()//clear Lcd statements
{
Send_data(0x01,FALSE);
Send_data(0x02,FALSE);
}
void LCD_print(char *data)//to print a character on lcd
{
while((*data!=0)&&(data!=0))
{
Send_data(*data,TRUE);//send data
data++;
}
}
int main(void)
{
GPIO_init();
LCD_init();
LCD_clear();
while(1)
{
LCD_clear();
SysCtlDelay(2000);
LCD_print("Have a nice Day");//
//send_data('T',TRUE);
}
After successfully implementing the above procedure, the lcd will display the characters mentioned in
the above C code.
9|Page