It's the Simple Things

Using HD44780

The HD4480 board is a small LCD screen with most of the time 2 lines and 16 columns. It takes 4 (4 bits mode) or 8 pins (8 bits mode) to write data, plus 2 others pins to control the command, and one more if you want to check if the controller is ready for the next command (otherwise you have to wait a certain amount of time) or read data from it. I will focus in this article on the 4 bits mode as it's really hard to find 10 pins available on an esp8266.

How works a HD44780

Pins

RS: Register selection (DDRAM or CGRAM) RW: Mode read or write (optional, can be wired to the ground) Enable: Validate values to read. D4,D5,D6,D7: Write bits. As we use the 4 bits mode, we will send first the 4 Most Significant Bits then the four others.

Wiring (on an ESP8266 but works on Atmega also)

Pin HD44780

Pin ESP8266

4

D1 (GPIO5)

6

D2 (GPIO4)

11

D3 (GPIO0)

12

D4 (GPIO2)

13

D5 (GPIO14)

14

D6 (GPIO12)

HD44780 pin 3 may be plugged to a potentiometer. HD44780 pin 15 must be plugged to Vcc using a 10kOhm resistor.

Commands in writing mode

CLEAR_DISPLAY ( >1.64ms)

Enable

RS

RW

D7

D6

D5

D4

0

0

0

0

0

0

Pulse High

0

0

0

0

0

1

Pulse High

RETURN_HOME ( >1.64ms)

Enable

RS

RW

D7

D6

D5

D4

0

0

0

0

0

0

Pulse High

0

0

0

0

1

0

Pulse High

ENTRY_MODE_SET ( >40µs)

Enable

RS

RW

D7

D6

D5

D4

0

0

0

0

0

0

Pulse High

0

0

0

1

A

B

Pulse High

A = 1 : cursor increment one on the right
A = 0 : cursor increment one on the left
B = 1 : Scrolling (addresses are incremented)
B = 0 : No addresses increments no scrolling.

DDRAM

DDRAM is the addresse of the cursor. It starts at 0x00, the first position. In our case we have a two lines HD44780. We have only 16 columns per lines but we have 28 slot per lines for scrolling purpose. The second line starts at the 0x40 address.

first line

0x00

0x01

...

0x26

0x27

second line

0x40

0x41

...

0x66

0x67

So to write a char at the first position, you have to set the cursor to the address 0x00 with the SET_DDRAM_ADDRESS command , and then write you char with the WRITE_DATA command. Here is the table of the char you can print (coming from the datasheet): The 8 first bits are reserved for CGRAM chars which are the chars that you can provide yourself. For example if you want to write 7 at the third place in the board here it what you have to send:

Enable

RS

RW

D7

D6

D5

D4

0

0

1

0

0

0

Pulse High

0

0

0

0

1

1

Pulse High

Wait 40 us

1

0

0

0

1

1

Pulse High

1

0

0

1

1

1

Wait 43 us

CGRAM

HD44780 has room for 4 or 8 of you own characters. 4 For matrice 5*11, 8 for a 5*8 matrix. In our case we have the 8 spaces. The address in DDRAM are the CGRAM column (see table above). To configure your own char you can send the matrix that represents it . For my matrice (5*8), you can send 7 lines as the last one is for the cursor, and 5 columns (the 5 first bit of the byte). For example, here is a matrix which represents my own creation : uint8_t matrix[] = { 0b00000010 ->first line , 0b00000100 , 0b00001110 , 0b00010001 , 0b00011111 , 0b00010000 , 0b00001110 , 0b00000000 -> cursor line}; The char will have this form on the board: To send it I need to first set the CGRAM address to the location where you want to save the char (here 0 ). But the first 3 (0,1,2) bits are used to indicate in which line in the matrix we gonna start, so here to the first one so 0. Then the bits 3,4,5 are used for the char address in CGRAM, so from 0 to 7. Then you can use the WRITE_DATA commands and send the matrix. So you have to send this to save your char:

Enable

RS

RW

D7

D6

D5

D4

0

0

0

1

0

0

Pulse High

0

0

0

0

0

0

Pulse High

Wait 40 us

1

0

0

0

0

0

Pulse High

1

0

0

0

1

0

Wait 43 us

1

0

0

0

0

0

Pulse High

1

0

0

1

0

0

Pulse High

Wait 43 us

...

You can now display it by calling address 0x0 from the DDRAM (see above).

Setup

To setup the board you have to respect the HD44780 setup process:

wait 15ms after Vcc rises to 4.5V

Send FUNCTION_SET for 4 bits mode, 2 lines, 5*8 matrix

Enable

RS

RW

D7

D6

D5

D4

0

0

0

0

1

0

Pulse High

0

0

1

0

0

0

Pulse High

Wait more than 4.1ms

Resend FUNCTION_SET for 4 bits mode, 2 lines, 5*8 matrix

Wait more than 100 µs

Resend FUNCTION_SET for 4 bits mode, 2 lines, 5*8 matrix

Set your display (Visible display,visible cursor ,blink)

Enable

RS

RW

D7

D6

D5

D4

0

0

0

0

0

0

Pulse High

0

0

1

1

1

1

Pulse High

You are good to starts sending datas.

Shift display

You can use the option to shift the display. This option will shift the address on the screen. For example if you shift one on the left , the first visible address will not be 0x0 anymore but 0x01 on the top left of the board. If you shift on the right, the 0x0 will become again the first address on the top left of the board. This can be useful if you want to implement a scrolling function, when you reach the address 15, you can start shifting to show the addresses from 0x16 to 0x27.