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: Interfacing with HD44780 LCD WITHOUT Library

Part Number: EK-TM4C123GXL

So this is probably a long shot, but I figured i'd give it a shot.

Basically im trying to manually get 1 character even printing on a generic 20x4 LCD screen (purchased this specifically: https://www.adafruit.com/product/198)

So my code is SUPER basic, because im basically trying to replicate their "example" on page 42 with 4 bit mode: https://cdn-shop.adafruit.com/datasheets/HD44780.pdf

here is my code:

#include "tm4c123gh6pm.h"
#define PORTB                  (*((volatile unsigned long *)0x400050FC))
#define GPIO_PORTB_OUT          (*((volatile unsigned long *)0x400050FC)) // bits 5-0
#define GPIO_PORTB_DIR_R        (*((volatile unsigned long *)0x40005400))
#define GPIO_PORTB_AFSEL_R      (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_DEN_R        (*((volatile unsigned long *)0x4000551C))
#define GPIO_PORTB_AMSEL_R      (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_PCTL_R       (*((volatile unsigned long *)0x4000552C))
#define GPIO_PORTE_IN           (*((volatile unsigned long *)0x4002400C)) // bits 1-0
#define SENSOR                  (*((volatile unsigned long *)0x4002400C))

#define GPIO_PORTE_DIR_R        (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R      (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_DEN_R        (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_AMSEL_R      (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R       (*((volatile unsigned long *)0x4002452C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOE      0x00000010  // port E Clock Gating Control
#define SYSCTL_RCGC2_GPIOB      0x00000002  // port B Clock Gating Control


// This assumes that the hookups PB3-PB0 = D7-D4
// RS = PB4
// EN = PB5

// Inputs: Number of msec to delayMS
// Outputs: None
void delayMS(unsigned long msec){ 
  unsigned long count;
  while(msec > 0 ) {  // repeat while there are still delayMS
    count = 16000;    // about 1ms
    while (count > 0) { 
      count--;
    } // This while loop takes approximately 3 cycles
    msec--;
  }
}




int main(void){
    volatile unsigned long delay;
    SYSCTL_RCGC2_R |= 0x12;      // 1) B E
  delay = SYSCTL_RCGC2_R;      // 2) no need to unlock
  GPIO_PORTB_AMSEL_R &= ~0x3F; // 3) disable analog function on PB5-0
  GPIO_PORTB_PCTL_R &= ~0x00FFFFFF; // 4) enable regular GPIO
  GPIO_PORTB_DIR_R |= 0x3F;    // 5) outputs on PB5-0
  GPIO_PORTB_AFSEL_R &= ~0x3F; // 6) regular function on PB5-0
  GPIO_PORTB_DEN_R |= 0x3F;    // 7) enable digital on PB5-0

    while(1){

        PORTB = 0x02;
        delayMS(5);
        PORTB = 0x12; //enable on 
        delayMS(5);
        PORTB = 0x02; //enable off

        PORTB = 0x02;
        delayMS(5);
        PORTB = 0x12; //enable on 
        delayMS(5);
        PORTB = 0x02; //enable off

        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x00; //enable off

        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x00; //enable off

        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x2E; 
        delayMS(5);
        PORTB = 0x00; //enable off

        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x26; 
        delayMS(5);
        PORTB = 0x00; //enable off


        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x34; 
        delayMS(5);
        PORTB = 0x00; //enable off

        PORTB = 0x10; //enable on
        delayMS(5);
        PORTB = 0x38; 
        delayMS(5);
        PORTB = 0x00; //enable off


        PORTB = 0x00;
        delayMS(5);
        PORTB |= 0x00;
        delayMS(5);
        PORTB |= 0x00;



    }


}

It's pretty basic, because im pretty new to using the TIVA board. I can do basic GPIO stuff but nothing fancy. I also realize HAL libraries exist..but I was just trying to follow this "example" code in the debugger sending the exact commands. I don't have R/Whooked up , it's tied to ground. Enable is PB5, and RS is PB4 with DB7-DB4 being PB3-0

I am certain it is hooked up on the breadboard fine. But im sure im just missing something obvious. I read over the datasheet, and from my understanding, I need to bring enable high--->do command---->turn enable off? So im trying to use small delays.

Any ideas? This may not be the proper forum but I figured i'd give it a shot.

  • All such character LCDs (and those graphic) have (demanding) "Initialization Code Routines." Should you employ the Forum's Search Box (atop the forum page) and enter "HD44780" you should find several postings I've made - which display the required initialization code.

    I find your code "uncommented as to intent!" (the repeated "cut/paste" of "enable on/enable off" fails to describe "what" each call aims to achieve.)

    Much of your code is "Direct Register" - which bypasses the "extreme value provided by vendor's API" - adding time, effort to your job - and discouraging response from (potential) "helpers" here.

    You "must" provide a proper voltage to "Display pin "Vo" (usually pin 3) which enables display contrast. This is properly adjusted - after initialization - such that the "pixel field" (w/ all pixels off) is "barely visible."

    While "4-bit mode" saves 4 I/O - it multiplies your time/effort - and is far less robust than the more standard "8-bit mode." (a single glitch upon "E" will disrupt all following transactions to the Lcd - when under 4-bit mode - and proves (very) difficult for one to detect...
  • Firm/I are "in process" of moving our (external) warehouse - this must be fast.

    I urge you to add the 4 port pins (yielding the far easier, more robust, 8-bit Bus) - in a "one to one configuration" (i.e. (MCU) Px7 <-> DB7 (Lcd), (MCU) Px0 <-> DB0 (Lcd) as example.) Both RS & E may arrive from a 2nd port, your tying R/W to Gnd is ok.

    As I recall - the simpler "8 bit initialization code" is: 0x38, 0x38, 0x06, 0x0E, 0x01 - all sent with "LONG" delays (mS) between each. (Your consult of the HD44780 spec - which I've cut/pasted here - outlines the compliance demanded.)

    Note that ALL "Initialization" occurs w/"RS = 0" - followed by a proper width "E" positive pulse. All Display Commands also employ RS=0 - Character/Data Writes (alone) set RS=1.

    Butchered "initialization", "floating the Vo pin" and (especially) the "devil" 4-bit mode" are the major cause of "issues" as you report...
  • I am providing voltage to v0 via a trimpot. And yes my code is super uncommented because im just trying to get the most basic functionality working without any libraries for learning. I think i mistook the datasheet and saw the example code. But that maybe didn't include the actual initialization code since i thought the example code on pg 41 included that too.

  • As stated - and ESPECIALLY DEMANDED when in, "Devil/4-bit Mode" - you MUST get the initialization RIGHT! (I don't believe the code you've provided proves adequate in that regard.)

    While its "tempting" to simply, "Grab existing code" - should it "NOT work" - then what? You (now) know where to go should you seek to progress beyond (simple) "cut/paste!"

    May I note that (any) "super-uncommented code" (as you mention) is rarely famed as, "super-working/performing!"

  • Yup im gonna retry it with the actual init code this time just to make sure. Since this is technically a 5v LCD which may/may not work anyways. (Im waiting on an actual 3.3v lcd screen to ship).
  • Matt Smith29 said:
    this is technically a 5v LCD which may/may not work anyways.

    Review of the HD44780 spec (or the actual device spec - as used on your module) will clarify if 3V3 signal levels are "seen" as "high" by the Lcd Controller.

    The 4x20 module enables you to create "2x and 4x" height characters (via strategic SW) and proves far more useful than (more used) 2x16.    Note too that there are (more visually exciting) "VFDs" and "OLEDs" - also in 4x20 format - although those are as costly as a "128x64 Graphic Lcd."