This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C123GH6PZ: Interfacing LCD 16x2 with TM4c123

Part Number: TM4C123GH6PZ

Tool/software: TI C/C++ Compiler

Hi,

I am trying to interface a 16X2 LCD with Tiva,Here I am trying to send strings on the Lcd,I have used lcd in 4 bit mode.In my hardware only 4 bit provisions are there,so I am unable to use 8 bit mode. Please help me to solve this 4 bit mode issue. I am getting the dots in LCD screen but not displaying any cursor/string.I was using systick interrupt to provide proper time delay.I was checked the Enable pin triggering with oscilloscope and it is triggering correctly. I red many forum regarding the LCD display and still I am unable to solve the issues. I am new to tiva ,I am hoping someone in this forum can help me.

VSS is connected to ground

VDD is connected to a pot

VEE is connected to +5V

RS is connected to portG pin 4

RW is grounded...

Enable pin is connected to portG pin 5

D0 to D4 are connected to portG pin0 to pin 4 respectively

Back light pins are also connected to +5V and ground...

Given below is my code I was used for interfacing

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/systick.h"
#include "inc/hw_nvic.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"

volatile uint32_t msTicks = 0;
/*****************************************************************************************************************
LCD is in 4-bit mode so it send data in 2 strocks in first First the higher four nibbles of a character

*******************************************************************************************************************/

/******************************************************************************************************************

Systick interrupt function

******************************************************************************************************************/

void SysTick_Handler(void)
{
//
// Update the Systick interrupt counter.
//
/* Increment counter necessary in Delay()*/
msTicks++;
}


void Delay(uint32_t dlyTicks)
{

uint32_t curTicks;

curTicks = msTicks;
while ((msTicks - curTicks )< dlyTicks) ;

}

/*****************************************************************************************************************************

End of systick interrupt

******************************************************************************************************************************/

void Lcd_command(unsigned char cmd)
{

GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cmd);//LCD data
Delay(1000);
//GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,com);//LCD mode
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x00);//Make RS=0GPIO pin-4,E=0 GPIO pin 5
Delay(1000);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x20);//make RS=0,E=1 enabling lcd by high to low pulse
Delay(1000);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x00);//Make RS=0,E=0
Delay(1000);
}

void Lcd_data(unsigned char data)
{

GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, data);//LCD data
Delay(1000);
//GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,com);//LCD mode
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x10);//Make RS=1GPIO pin-4,E=0 GPIO pin 5
Delay(1000);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x30);//make RS=1,E=1 enabling lcd by high to low pulse
Delay(1000);
GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_4|GPIO_PIN_5,0x10);//Make RS=1,E=0
Delay(1000);
}

void Lcd_Init()
{

Lcd_command(0x28); //4-bit mode lcd having 2 lines and character shape between 5x7 matrix.
Delay(500); //provide 500ms delay
Lcd_command(0x06); //Display ON, cursor OFF / entry mode it tells the lcd that we are going to use.
Delay(500); //provide 500ms delay
Lcd_command(0x0E); //displays cursor on and dispaly on.
Delay(500); //provide 500ms delay
Lcd_command(0x0F); //displays cursor on and dispaly on.
Delay(500); //provide 500ms delay
Lcd_command(0x01); //Clear screen
Delay(500); //provide 500ms delay
}

void Lcd_String_Display(unsigned char *str)
{
while(*str!='\0')
{
Lcd_data(*str);
str++;
}
}

/*******************************************************************************************************************************************

Main starts here

*******************************************************************************************************************************************/

int main(void)
{

SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC |SYSCTL_XTAL_8MHZ|SYSCTL_OSC_MAIN);//8MHz crystall oscilator

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOG));

GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
IntMasterEnable();// Enable interrupts to the processor.
SysTickPeriodSet(7997); // Set up the period for the SysTick timer of 1ms.
SysTickIntEnable(); // Enable the SysTick Interrupt.
SysTickEnable();// Enable SysTick. SysTickEnable();// Enable SysTick.
//GPIOPinTypeLCD(GPIO_PORTG_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);

Lcd_Init();

while (1)
{
Lcd_String_Display("Welcome....");
}
}

/*************************************************************************************************************************************************

End of main

*************************************************************************************************************************************************/

Looking forward for a quick replay...

Regards,

Alphy

  • Hello Alphy,

    This is more of an LCD issue than a TM4C issue, so I don't have a whole lot I can offer in terms of knowledge, but one thing I noticed is this:

    You are using this command:

    Lcd_command(0x28); //4-bit mode lcd having 2 lines and character shape between 5x7 matrix.

    So 0x28 is a full byte of data, and a data byte is 8 bits. In other words, that command is 00101000b in binary.

    But in your LCD command function you do the following:
    GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cmd);//LCD data

    So you are only sending out 4 of the 8 bits, the lower half, which 1000b. The other 4 bits, the upper half, is lost.

    So I suspect your issue is that with the 4 bit interface, you need to look up on your LCD screen how to split and send bytes, and then update your LCD command function to do that.

    See if that helps get you moving forward, good luck!
  • Hi sir,

    Thank you so much for sharing your knowledge. It help me to think about 4 bit  , and help me to solve my issue. The issue was related to 4 bit data transfer and delay.

    I changed the delay and change data transfer in two half first half sending higher nibble and make Enable pin high and low and the second half sent the lower nibble and again enable and disable the Enable pin.These changes made my code as working.  

    once again thank you so much for your help.

    Regards,

    Alphy