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.

character lcd interfacing with tiva

Other Parts Discussed in Thread: TM4C123GH6PM

Hai,

I wrote a code to interface LCD with Tiva launchpad, but there is nothing displayed on the LCD and i cant find whats wrong in my code ,please help me to correct my code..

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

void Lcd_Dislay(unsigned char data,unsigned int com)
{

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, data);//LCD data
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,com);//LCD mode
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,1);//enabling lcd by high to low pulse
SysCtlDelay(4);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,0);
}

void Lcd_Init()
{
Lcd_Dislay(0x38,0);
SysCtlDelay(4167);
Lcd_Dislay(0x0c,0);
SysCtlDelay(4167);
Lcd_Dislay(0x01,0);
SysCtlDelay(4167);
}

void Lcd_String_Display(unsigned char *str)
{
while(*str)
{
Lcd_Dislay(*str,1);
str++;
}
}


int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_16|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1);

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);

Lcd_Init();

Lcd_String_Display("hai how are you....");

}

  • Hello sivaprasad,

    What character LCD Panel, which TM4C device (seems to be TM4C123). Just a code that toggles GPIO is not sufficient for us to help you. Also did you look at the data sheet of the Character Panel. These panels do need some amount of initialization and the data to be displayed some processing.

    Regards

    Amit

  • sorry for the insufficient details, iam using TM4C123GH6PM (TIVA Launchpad), lcd is an ordinary 16*2 (5*7 matrix)character lcd panel, i already done the required initialization, iam successfully interfaced it with some other 8 bit controller,s now i tried to interface it with my most favorite device TivaC Launchpad. i followed the same procedure,however there is something wrong, please help me to find whether its due to my code...

  • Hello Sivaprasad,

    So what are the connections from the TM4C123GH6PM to the Panel. Do you have a connection diagram? Also if you can attach the specification for the panel it would be useful for me to check the connections and how the code is going to interact with the panel.

    I do not have the panel so for me information is important.

    Regards

    Amit

  • Hai Amit,

    Thank you for your quick response, here iam attaching the datasheet of panel.

    2677.ADM1602K-NSW-FBS-3.3v.pdf   

    i connected the 8 bits of data to B0-B7, RS to D0 ,EN to D1, and grounded the R/W, and provide the required VCC and GND. thats all the connection details...

    Thank you

    siva

  • Where to begin - code listed will NOT run any character display!  (I should know - having designed/produced/sold over 250K such modules)

    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,1);//enabling lcd by high to low pulse

    Above fails - 3rd parameter sets GPIO_PIN_0 high - not GPIO_PIN_1!  You do need to invest (some) time learning this vendor's powerful APIs. (that parameter must be "2" to set pin_1 high)

    Your (uniquely) named function, "LcdDislay" (some attention to detail required) is insufficient as you employ it BOTH for Lcd Commands and Screen Writes.  Now we note that you (hope) to properly "set/clear" variable COM - is this not entirely too risky?  Would not separate functions - one for command - other for display writes - better manage this? RS=0 for commands, RS=1 for screen writes.  Your function very likely toggles RS & E too quickly - violates all Lcd timing diagrams.

    The (proper) scheme to operate (99.9%) of such character modules involves:

    a) present known good data to display's bus

    b) insure E starts from low level - then drive RS to proper level (0 for com'd, 1 for display write)

    c) observe set-up time of RS - only then drive E high

    d) observe minimum hold-time for E high - then drive E low  (it's this action which latches the data into the lcd)  Your SysCtlDelay value of 4 is extremely unlikely to reach the 40uS (or thereabout) usually required by E.

    e) your initialization sequence appears to well disregard the "long" time delays between these first commands - some attention to lcd's data sheet will guide...

    And - you're silent as to (critical) Vo (contrast) pin.  Usually that must be connected to (near) ground.  This is best done w/a potentiometer - easing your adjustment. 

    Bring your code into conformance w/Lcd spec - tweak the contrast pot - your display should then be, "On the Air."

     

  • Thank you cb1_mobile,

    i done a lot of mistakes...and i correct it as per your advise...however still the LCD remains as previous...kindly check my new code...i think there is problem with delay.....

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

    void Lcd_command(unsigned char data)
    {
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);

    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, data);//LCD data
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);
    SysCtlDelay(1000);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x02);//enabling lcd by high to low pulse
    SysCtlDelay(3000);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);
    }

    void Lcd_data(unsigned char data)
    {
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);

    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, data);//LCD data
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x01);
    SysCtlDelay(1000);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x02);//enabling lcd by high to low pulse
    SysCtlDelay(3000);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x03);
    }

    void Lcd_Init()
    {
    Lcd_command(0x38);
    SysCtlDelay(4167);
    Lcd_command(0x0c);
    SysCtlDelay(4167);
    Lcd_command(0x01);
    SysCtlDelay(4167);
    }

    void Lcd_String_Display(unsigned char *str)
    {
    while(*str)
    {
    Lcd_data(*str);
    str++;
    }
    }


    int main(void)
    {
    SysCtlClockSet(SYSCTL_SYSDIV_16|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1);

    //GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1,0x00);

    Lcd_Init();
    Lcd_String_Display("hai how are you....");

    }

  • Suggest that you (further) simplify - KISS - one small step at a time most always works best.

    Have you access to an oscilloscope?  If not you must find & install an Led so that we can "rough gauge" delay timing.

    Always best to get the initialization right - most will fail if that's incorrect or incomplete.  If you search this forum - under cb1 and/or cb1_mobile identity - you'll find an extract of HD44780 datasheet.  There appears the critical data timings.

    I don't like your initialization - we use: 0x38, 0x38, 0x06, 0x0E, 0x01.  For your testing - I'd use a ONE Second delay between each.  (yes it's too long - but of no consequence now.  If too short - we spin our wheels!)  That first 0x38 must not start until 1 second after the display is powered up.

    Send each of those initialization codes with RS=0, E=0 - and then toggle E from high to low.  (keeping E high for 1 second)

    If the initialization succeeds - the display's cursor will be visible - top row - left-most character.  You (normally) will be able to view the entire pixel dot field - tweak the contrast pot so that the (background) pixels are barely visible.  If you don't see the cursor @ home pos'n - the initialization has failed.

    Should it fail - ohm out each/every connection from MCU to the display.  Short between pins or single open will prevent operation - as will routing to the wrong MCU pin. 

    Via use of an Led you can tweak your delay loop so that the 1 second delay may be confirmed. 

    You must insert this 1 second delay between EVERY Lcd transaction during this initialization testing.  (later - with some positive results - we'll dial it down)

    Allez!

  • Thank you Dear cb1,

    For the last few days i engaged in the LCD interfacing with TivaC launch pad,i tried a lot and failed, but when I started to work with your guidance,i learned how to solve the problem and finally i succeed...

    I happened to find an error with GPIO output voltage while testing the RS and EN (connected to D0 and D1)with LED as per your wise advice.when i toggle the LEDs (RS and EN)in a while loop both are blinked at same intensity, but when i call the LCD initialization and message display function the intensity of the LED corresponding to RS is high compared to EN,and does not become completely off (remains a dimness)during low pulse(when GPIO output is 0), i failed to find its reason at last i changed the pins to A6 and A7,then everything is ok...

    once again Thank you very much....

    sivaprasad

  • Dear Sivaprasad,

    In the (now immortal) words of vendor's (past) Ms. Cozart, "You Sir, are too kind."

    You received some (slight) guidance - followed a systematic tack - and victory was yours.  Well done - well earned!

    Armed w/your text Lcd you may replace (all) of those UART debug calls - instead write far faster to the Lcd.  As yours (iirc) is 2x16 - you have an 80 character Lcd ram - thus almost 50 bytes of "free data space" remains for your use.  (You must scroll the display to reveal those "usually hidden" display locations.  In so doing - the original data will be removed from view - yet still linger in display ram {i.e. you may scroll back to view it})

    As you state - the simple Led may serve well as "low cost" diagnostic tool.  Best of all - as you've proved - is the human mind following systematic, thoughtful (i.e. unrushed) path...  Bon chance, mon ami...