LCD 16×2 driven by Arduino with 4 wires via shift register

The model of LCD I am using does not have IC2 inputs. So this is a way to drive the LCD via a serial interface.

A 74LS595 8 bit shift register is used to drive the 8 datelines of the LCD.

The setup is shown below:

Two control wires go the the shift register: Clock (CLK) and Serial Data (SER), and two control lines go to the LCD: Register Select (RSL) and Enable (EBL).

Some defaults:

The storage register is tied to the data line clock. The output of the latch of the shift register is enabled (GND).

The LCD R/W is ties to GND (write mode).

The code used is shown below. I did not used the available LCD library since I wanted to understand the details.

The display needs to be initialised with a series of bytes send to the instruction register (RSL set low).

The display is set to a 2-line function using 0x38.

Note that the potentiometer settings may needs to be adjusted (to show the two lines cf with a 1-line mode).

#define CLK 02
#define SER 03

#define RSL 04
#define EBL 05

// the setup function runs once when you press reset or power the board
void setup() {

  char message1[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(CLK, OUTPUT); pinMode(SER, OUTPUT);
  pinMode(RSL, OUTPUT); pinMode(EBL, OUTPUT);
  
  digitalWrite(EBL, LOW);
  digitalWrite(RSL, LOW);
  delay(10);

  //lcdWrite(LOW, 0x30);lcdWrite(LOW, 0x30); lcdWrite(LOW, 0x30);
  lcdWrite(LOW, 0x38); // function set
  lcdWrite(LOW, 0x0E); // display and cursor on
  lcdWrite(LOW, 0x01); // clear display
  lcdWrite(LOW, 0x06);
  
  for (byte i = 0; i < sizeof(message1) - 1; i++) {
      lcdWrite(HIGH, message1[i]);
  }
}

void lcdWrite(boolean rsl, byte outChar) {
  digitalWrite(RSL, rsl);
  shiftOut(SER, CLK, MSBFIRST, outChar);
  digitalWrite(CLK, HIGH); delay(2); digitalWrite(CLK, LOW);
  delay(1);digitalWrite(EBL, HIGH);delay(1);digitalWrite(EBL, LOW);
}

// the loop function runs over and over again forever
void loop() {  
}

The resulting output on the display is shown below:

Notice how the message wraps around with characters ‘falling off’ on the lines. This is expected behaviour, with 40 character positions.

from http://hades.mech.northwestern.edu/images/f/f7/LCD16x2_HJ1602A.pdf

Next I would like to try to run this off the Attiny and still have room for pins for a IC2 interface.

Leave a comment