Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

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.

LCD 16x2 interface failed?

Other Parts Discussed in Thread: TM4C123GH6PM

I tried to send a character to LCD 16x2 but it failed. Nothing was displayed. With this code I can interface with LCD by PIC and 8051 microcontroller. I changed a little bit to suit to Tiva C Launchpad but it didn't work. 
I used pin B0-B7 to transfer data. A5-A6 are RS and E, RW to ground. This is my code:

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"

#define P0 GPIO_PIN_0
#define P1 GPIO_PIN_1
#define P2 GPIO_PIN_2
#define P3 GPIO_PIN_3
#define P4 GPIO_PIN_4
#define P5 GPIO_PIN_5
#define P6 GPIO_PIN_6
#define P7 GPIO_PIN_7

void Delay_ms(int t)
{
SysCtlDelay(SysCtlClockGet()/(3000/t));
}

void LCD_cmd(char cmd)
{
GPIOPinWrite(GPIO_PORTA_BASE,P5,0);
GPIOPinWrite(GPIO_PORTA_BASE,P6,1<<6);
GPIOPinWrite(GPIO_PORTB_BASE,P0|P1|P2|P3|P4|P5|P6|P7,cmd);
Delay_ms(10);
GPIOPinWrite(GPIO_PORTA_BASE,P6,0);
Delay_ms(20);
}

void LCD_data(char data)
{
GPIOPinWrite(GPIO_PORTA_BASE,P5,1<<5);
GPIOPinWrite(GPIO_PORTA_BASE,P6,1<<6);
GPIOPinWrite(GPIO_PORTB_BASE,P0|P1|P2|P3|P4|P5|P6|P7,data);
Delay_ms(10);
GPIOPinWrite(GPIO_PORTA_BASE,P6,0);
Delay_ms(20);
}

void LCD_WrStr(char *str)
{
while(*str)
{
LCD_data(*str);
str++;
}
}

void SetCursor_LCD(unsigned char m,unsigned char n) //Chinh vi tri con tro
{
if (m==1)
{
LCD_cmd(0x80+n);
Delay_ms(10);
}
else
{
LCD_cmd(0xC0+n);
Delay_ms(10);
}
}


void LCD_init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,P0|P1|P2|P3|P4|P5|P6|P7);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,P5|P6);
GPIOPinWrite(GPIO_PORTA_BASE,P5,0);
GPIOPinWrite(GPIO_PORTA_BASE,P6,0);
GPIOPinWrite(GPIO_PORTB_BASE,P0|P1|P2|P3|P4|P5|P6|P7,0);
// Delay_ms(200);
// LCD_cmd(0x30);
// Delay_ms(500);
// LCD_cmd(0x30);
// Delay_ms(110);
// LCD_cmd(0x30);
// Delay_ms(1000);
LCD_cmd(0x38);
Delay_ms(1000);
LCD_cmd(0x0C);
Delay_ms(1000);
LCD_cmd(0x06);
Delay_ms(1000);
LCD_cmd(0x01);
Delay_ms(1000);
}

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
LCD_init();
SetCursor_LCD(1,0);
Delay_ms(100);
LCD_data('H');
}

  • Can you see clock signal output on your E and RS pins?
    Are you using a MCU that is compatible with SysCtlClockGet? Note that this function is compatible with only TM4C123 chips. Besides, it would be a good idea to calculate your delay for one ms just once, instead of verifying the system clock on every delay you call.
  • Not all 2x16 Char LCD Modules will (directly) accept 3V3 as a logic high input. (in fact - there are such modules which are "designed" for 3V3 inputs)
    This may (alone) - or may not - explain your failure.     Were not the 8051 &  (older) PICs 5V output level devices?

    Do you see the display's "dot field?" What voltage have you applied to Vo? (and cannot you duplicate the "past" successful settings & components? We're not told of that.)

    As always - are ALL of your connections - measured between the LCD's edge connector and MCU - test/verified? (i.e. ohm'ed out)

    Lastly - you don't mention your MCU - or board - that would prove helpful - would it not?

    If a TM4C123 LPad - might there be (delightful) 0Ω resistors - which (likely) impede 2 pins of Port B?    (which is the "very" port you've chosen for Lcd data!)

    Note that descriptions such as "Failed and/or Don't Work" provide little (i.e. NO) value when trying to assist. (Some) detail is required.

  • I'm using tm4c123gh6pm. I knew the sysctldelay function takes 3 cycle so I wrote the Delay_ms function for my own. I think I'll try using a led checking E and RS pins like you said.
  • i'm using tm4cgh6pm. I can see the dot field on LCD, i'm using VBUS pin connect to LCD, i know the lcd is working and I checked the connection many times. Is there any problem with port B that I need to fix?
  • Thank you - appreciated. You note an MCU - but NOT your board. If a Launchpad - resistors R9/10 tie to PD0/PD1. (they don't impact Port_B - as I earlier - had feared.

    By "viewing the dot field" we're assured that Lcd's "Vo" pin is properly handled - issue then most likely falls to interconnect or timing.

    You should be able to write short code block which toggles your Port_B bus from, "0xAA to 0x55" at 2 second intervals - which enables you to monitor the (safe) arrival of those alternating 1s or 0s - at the Lcd header. You may do the same w/RS & E - choose code which toggles each @ 2Hz - slow enough for (even) a crude DVM to respond. (in case you've not got good access to better equipment - again - we're not told.)

    You don't mention your Lcd's spec - certain character modules will not "see" 3V3 as logic high. (as that level is under 70% of 5V!) Your Lcd spec is judge/jury of that - UNLESS your past (successful) PIC MCU (also) operated @ 3V3 levels. (again this question was asked - not answered)

    As always - in the beginning MORE/LONGER DELAYS cannot hurt. Later - once working - you can "fine tune" - too short a delay will cause the EXACT ISSUE you (now) note.

    From my quick review of your code - nothing jumps out.     

    As you report having moved this Lcd (this now is its THIRD HOME) how sure are you that ALL of the connections remain intact and solid?     How recently have you checked?    (clients so often tell us - everything has been checked - almost always - we (then) find that UNTRUE - and charge for our WASTED time/trip/frustration!)    "Simple things are too often - neglected!"