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: I there any example to interface the LCD to the controller?

Part Number: EK-TM4C123GXL

I'm working on the TM4C123GXL trying to interface the 40x2  "NHD-0240AZ-FL-YBW" LCD. For that I was searching for the lcd interfacing example in the software development kit but  I haven't find any. How can I find the same so that interfacing will become easy for me.

Regards,

Omkar Dixit

  • I don't have any examples for that LCD, but I do have examples for interfacing the EK-TM4C123GXL to a Kentec QVGA boosterpack. The examples are in TivaWare,  C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl-boostxl-kentec-s1

  • Hi

    Bob

    Thanks for the reply I hope I will get opportunity to interface TFT Display in future and if I get I will definitely go through the example you shared.

    Regards,

    Omkar Dixit

  • This code worked for me

    /*************************************************************lcd.c*********************************************************/
    #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "lcdinit.h"
    #include "stdio.h"
    #include "TM4C123.h"                    // Device header
    #include "arm_math.h"                   // ARM::CMSIS:DSP
    
    void DelayMilis(unsigned long ulMilliSeconds)
    {
    	unsigned long i = 0, j = 0;
    	
    	for(i = 0;i < ulMilliSeconds;i++)
    	{
    		for(j = 0;j < 2000;j++);
    	}
    }
    
    void 
    LCDCommand(unsigned char cmd)
    {
    
      unsigned char lcmd1,lcmd2;
      lcmd1=((cmd&0xF0)>>4);
      RS_LO;
      DATA_PORT(lcmd1);
      EN_HI;
      EN_LO;
      lcmd2=((cmd&0x0F));
      
      DATA_PORT(lcmd2);
      RS_LO;
      EN_HI;
      EN_LO;
      
    }
    
    void 
    LCDPutChar(unsigned char dat)
    {
        unsigned char ld1,ld2;
        ld1=((dat&0xF0)>>4);
        RS_HI;
        
        DATA_PORT(ld1);
        EN_HI;
        EN_LO;
        ld2=((dat&0x0F));
        RS_HI;
        
        DATA_PORT(ld2);
        EN_HI;
        EN_LO;
        
    }
    
    void 
    LCDInit(void)
    {   
        LCDCommand (0x02);
           DelayMilis(5);
        LCDCommand (0x28);
           DelayMilis(5);
        LCDCommand (0x0E);
           DelayMilis(5);
        LCDCommand (0x01);
           DelayMilis(5);
    //    LCDCommand (0x06);
            DelayMilis(5);
        LCDCommand (DISPLAY);  
           DelayMilis(5);
        LCDCommand (CURSOR_ON_OFF);
           DelayMilis(5);
    //    LCDCommand(CURSOR_BLINK);
    	  DelayMilis(5);
    //	  LCDCommand(BLOCK_CURSOR_BLINK);	
    	  DelayMilis(5);
        LCDCommand (CLEAR_DISPLAY);
           DelayMilis(5);
        LCDCommand(INCR_ADDRESS_SHIFT_CURSOR_WITH_EACHCHARACTER_RIGHT); 
           DelayMilis(5);
    } 
    
    void LCDWriteString(unsigned char *string)
    {
      while(*string)
      {
    
        LCDPutChar(*string++);
        DelayMilis(3);
      }
    }
    
    void LCDWriteString1(unsigned char *string, unsigned char ucLineNumber, unsigned char ucPosition)
    {
    	LCDCommand(ucLineNumber+ucPosition);
    	DelayMilis(5);
    	while(*string)
      {
    
        LCDPutChar(*string++);
        DelayMilis(1);
      }
    }
    
    void LCDRst(void)
    {   
        LCDCommand(CURSOR_AT_LINE_2 );
        DelayMilis(50);
    }
    
    /*************************************************************lcd.h*********************************************************/
    #ifndef _LCD_H
      #define _LCD_H
      #define SLAVE_ADDRESS         0x68
      #define CURSOR_AT_LINE_1      0x80
      #define CURSOR_AT_LINE_2      0xC0
      #define CURSOR_AT_LINE_3      0x94   // To be used only
      #define CURSOR_AT_LINE_4      0xd4   // for a four line LCD
      #define DISPLAY               0x28
      #define LCDINITWITHSMALLCHARS 0x20 
      #define CURSOR_OFF            0x08
      #define BLOCK_CURSOR_BLINK    0x0F
      #define CURSOR_BLINK          0x0E
      #define CURSOR_ON_OFF         0x0C
      #define CURSOR_SHIFT_LEFT     0x10
      #define CURSOR_SHIFT_RIGHT    0x14
      #define CLEAR_DISPLAY         0x01
      #define CURSOR_AT_HOME        0x02
      #define INCR_ADDRESS_SHIFT_CURSOR_WITH_EACHCHARACTER_RIGHT    0x06
     
     
     	#define DelayTime_LCD_CMD 0X00001FFF
    	#define DelayTime_LCD_INFO_L 0x00FFFFFF
    	#define DelayTime_LCD_INFO_M 0x007FFFFF	
    	#define DelayTime_LCD_INFO_S 0x003FFFFF
    
      #define EN_HI                 GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5)
      #define EN_LO                 GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0x00)
      #define RS_HI                 GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4)
      #define RS_LO                 GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0x00)
      #define DATA_PORT(data)				GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0, data);						 
    
      extern void LCDCommand(unsigned char cmd);
      extern void LCDPutChar(unsigned char dat);
      extern void LCDInit(void);
      extern void LCDWriteString(unsigned char *string);
    	extern void LCDWriteString1(unsigned char *string, unsigned char ucLineNumber, unsigned char ucPosition);
      extern void DelayMilis(unsigned long);
      
      
    #endif