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.

EK-TM4C123GXL: TM4C123GXL

Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM

I have been trying to interface 16x2 LCD with  TM4C123GH6PM  for three days but it didnt work .. the lcd pins VSS VDD VO   A     K   are driven from an outside source (5V) 

Here is my Code .. 

Thanks in advance .

//*****************************************************************************
#include <stdint.h>

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

#ifdef DEBUG

void
__error__(char *pcFilename, uint32_t ui32Line)
{
while(1);
}
#endif

void LCD_init(void);                                  // LCD_init Prototype

void LCD_Command(uint8_t cmd);          // LCD_Command Prototype
void LCD_Data(uint8_t data);                   // LCD_Data Prototype

int
main(void)
{
volatile uint32_t ui32Loop;


SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
{
}
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
{
}

GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);

GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2);

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

GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);


GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);


LCD_init();
LCD_Data('A');


while(1)
{

}

}

void LCD_init(void)
{

uint32_t ui32Loop1;
for(ui32Loop1 = 0; ui32Loop1 < 50000; ui32Loop1++) // 50ms
{
}
LCD_Command(0x3C);
for(ui32Loop1 = 0; ui32Loop1 < 1000; ui32Loop1++) //1 ms
{
}
LCD_Command(0x0F);
for(ui32Loop1 = 0; ui32Loop1 < 1000; ui32Loop1++) //1 ms
{
}
LCD_Command(0x01);
for(ui32Loop1 = 0; ui32Loop1 < 2000; ui32Loop1++) //2ms
{
}
LCD_Command(0x06);

}

void LCD_Command(uint8_t cmd)
{
uint32_t ui32Loop1;
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0x0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x0);

(*((volatile uint32_t*)(0x400053FC))) = cmd;// write cmd to DATA register in PORT B

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 , GPIO_PIN_2 );
for(ui32Loop1 = 0; ui32Loop1 < 2000; ui32Loop1++)
{
}
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 , 0x0);


}

void LCD_Data(uint8_t data)
{
uint32_t ui32Loop1;
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 , GPIO_PIN_0 ); // rs
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x0); // rw

(*((volatile uint32_t*)(0x400053FC))) = data; // write data to DATA register in PORT B

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 , GPIO_PIN_2); // en
for(ui32Loop1 = 0; ui32Loop1 < 2000; ui32Loop1++)
{
}
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 , 0x0);

}

  • What is the part number of the LCD display you are using?

  • I do not believe that the specific LCD Model proves critical as (almost) all such devices employ the  'HD44780' (or clone) LCD Control IC.

    Ahmed Elgizawy said:
    but it didn't work

    Somehow - 'Didn't Work' fails to provide necessary 'Diagnostic Detail.'     (and is offered up here (still) at alarming rates - a forum weakness many believe.)

    Follows a  quick, 'LCD Checklist' - which has a (very) high, 'Rate of Success:'

    • You note (5) Lcd pins as being driven by an external 5V source.   LCD's 'Vo' pin (usually) must be adjusted to (near) Ground Voltage levels - for the LCD's dot matrix pattern to properly reveal.    If set to 5V - it is guaranteed that, 'No pixels will be viewable.'
    • Outside of the signal delays/timing - your 'LCD_Data & LCD_Command' functions appear proper.    (you may 'check' the timing via the link provided & your 'O-Scope measurements')
    • Your 'LCD_Init' is 'Outside Hitachi's HD44780/clone LCD Specification.   Note particularly that your 'opening '0x3x' MUST be repeated (at least twice)   Again the link I've provided reveals the 'essence' of the HD44780 spec.   (which is multiple pages in length)

    It is always advisable to confirm Signal Level & Signal Timing - when interfacing any MCU to a specialized device.    The MCU must 'bend to the will' of the device - for a proper 'partnership.'    HD44780 spec (and one of my past posts) are found towards the bottom of the thread - linked, below...

    e2e.ti.com/.../2334563

  • I have not heard back from you so I assume CB1's comments have helped you resolve this issue. If not, please respond to this thread, or ask a related question.