Difference: Lecture11:The2LineLCDDisplay (1 vs. 7)

Revision 72018-12-11 - IsaacArmahMensah

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

Line: 143 to 143
 

Using the library

Changed:
<
<
In addition to the prototypes, have a look at the doxygen documentation
>
>
In addition to the prototypes, have a look at the doxygen documentation
  and you should be able to program the display.

Revision 62018-12-10 - IsaacArmahMensah

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

Line: 143 to 143
 

Using the library

Changed:
<
<
In addition to the prototypes, have a look at the doxygen documentation
>
>
In addition to the prototypes, have a look at the doxygen documentation
  and you should be able to program the display.

Revision 52017-11-16 - uli

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

Line: 27 to 27
 

Interfacing the display

Changed:
<
<
pcf8574ifce.png
>
>
hd44780-pcf8574circuit.png
 

The PCF8574 I2C interface

Line: 53 to 53
 

Interfacing signals

Changed:
<
<
The display needs a large number of interface signals
to be able to work:

  • Min. 4 data lines
  • R/W line
  • register select
  • back light
  • back light power
  • power
  • gnd
>
>
The display needs a large number of interface signals
to be able to work:

  • Min. 4 data lines
  • R/W line
  • register select
  • back light
  • back light power
  • power
  • gnd
hd44780_conn.png
 

A data byte to be sent

Changed:
<
<
>
>
  We will therefore need a great deal of bit fiddling
Line: 237 to 237
 

Interfacing to the MPU

Changed:
<
<
The HD44780 can be controlled with 8 or with 4 data bits.

In 4 bit mode (this is what we use) with the lower 4 MPU bits
>
>
The HD44780 can be controlled with 8 or with 4 data bits.

In 4 bit mode (this is what we use) with the higher 4 MPU bits
 
Changed:
<
<
connected to d4-d7 while the upper 4 MPU bits are used to drive.
>
>
connected to d4-d7. The hd44780 data lines d0 – d3 are disabled

 
Changed:
<
<
The hd44780 data lines d0 – d3 are disabled

The upper four bits are used to drive

>
>
The lower four bits are used to drive
 
  • RS (register select)
  • RW (read / write)
  • Strobe (E=enable)
  • and back light
Changed:
<
<
In this case the four highest significant data bits are sent first.

>
>
In this case the four highest significant data bits are sent first.

 
Deleted:
<
<

 

Instruction Summary

instructions.png

Line: 271 to 268
 
  • Strobe the data into the controller
  • Repeat the same thing for the lower significant
    8 bits of the data we want to write
  • Keep the BL bit constant
Deleted:
<
<
 

Strobe function

Line: 350 to 345
 
META FILEATTACHMENT attachment="initProc1.png" attr="" comment="" date="1510496819" name="initProc1.png" path="initProc1.png" size="30639" user="uli" version="1"
META FILEATTACHMENT attachment="initProc2.png" attr="" comment="" date="1510496819" name="initProc2.png" path="initProc2.png" size="28344" user="uli" version="1"
META FILEATTACHMENT attachment="libFunctions.png" attr="" comment="" date="1509982394" name="libFunctions.png" path="libFunctions.png" size="29147" user="uli" version="1"
Deleted:
<
<
META FILEATTACHMENT attachment="pcf8574ifce.png" attr="" comment="" date="1510496843" name="pcf8574ifce.png" path="pcf8574ifce.png" size="65250" user="uli" version="1"
 
META FILEATTACHMENT attachment="strobe.png" attr="" comment="" date="1510497029" name="strobe.png" path="strobe.png" size="69961" user="uli" version="1"
META FILEATTACHMENT attachment="2linedisplay.png" attr="" comment="" date="1509982432" name="2linedisplay.png" path="2linedisplay.png" size="894036" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_pcf8574.png" attr="" comment="" date="1509982435" name="i2c_pcf8574.png" path="i2c_pcf8574.png" size="1038370" user="uli" version="1"
Line: 368 to 362
 
META FILEATTACHMENT attachment="ddram.png" attr="" comment="" date="1510497986" name="ddram.png" path="ddram.png" size="11274" user="uli" version="1"
META FILEATTACHMENT attachment="intfce2displ.png" attr="" comment="" date="1510498022" name="intfce2displ.png" path="intfce2displ.png" size="15238" user="uli" version="1"
META FILEATTACHMENT attachment="writeWmd.png" attr="" comment="" date="1510498874" name="writeWmd.png" path="writeWmd.png" size="74073" user="uli" version="1"
Added:
>
>
META FILEATTACHMENT attachment="hd44780-pcf8574circuit.png" attr="" comment="" date="1510854392" name="hd44780-pcf8574circuit.png" path="hd44780-pcf8574circuit.png" size="67950" user="uli" version="1"
META FILEATTACHMENT attachment="hd44780_conn.png" attr="" comment="" date="1510854859" name="hd44780_conn.png" path="hd44780_conn.png" size="33368" user="uli" version="1"
META FILEATTACHMENT attachment="lecture_11.odp" attr="" comment="" date="1510857118" name="lecture_11.odp" path="lecture_11.odp" size="2769469" user="uli" version="1"

Revision 42017-11-12 - uli

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

Line: 37 to 37
 i2c_pcf8574.png

Added:
>
>

How to program the display

We need to know:

How to program the PCF8574

Understand the HD44780 display controller

Understand the interface between the two

Since the display can be used for many different purposes,

writing a library is the thing to do!

 

Interfacing signals

The display needs a large number of interface signals
to be able to work:

  • Min. 4 data lines
  • R/W line
  • register select
  • back light
  • back light power
  • power
  • gnd

Added:
>
>

A data byte to be sent

We will therefore need a great deal of bit fiddling

to create this data byte and to modify it to

  • Set the back light on or off
  • To send a pulse on the E (strobe) line
Hope you remember the

  • bitwise or operator: |
  • bitwise and operator: &
  • bit inversion: ~

The I/O expander

As you can see from the block diagram, the central part of the device

is a shift register. It can actually do both:

  • serial to parallel conversion (write)

  • and parallel to serial conversion (read)
pcf8574blockDiag.png

From the data sheet

writepcf8574.png

This means that when reading, we will read back

what has been written before, if the signals are pure output signals.

Since the device will put all pins high with a low pull-up current,

external signals can easily pull the pins low

and thus you can read the state of these signals

 

Writing the to HD4780 controller via the PCF8574

pcf8574write.png

Line: 58 to 111
 After this instruction the 8 data bits of bVal lie at the input of the hd44780 controller.

Changed:
<
<

A data byte to be sent

>
>

The HD44780

 
Changed:
<
<
We will therefore need a great deal of bit fiddling to
>
>
The controller must generate the signals needed to driver the
 
Changed:
<
<
create this data byte and to modify it to

  • Set the back light on or off
  • To send a pulse on the E (strobe) line
Hope you remember the

  • bitwise or operator: |
  • bitwise and operator: &
  • bit inversion: ~
>
>
LCD display and it must provide instructions to
  • Reset the display
  • Clear it
  • Have cursor functions
    • Enable/disable the cursor
    • Move it, “Home” it ..
    • Make it blink.
  • Have character generators in ROM or
    provide RAM memory to download character matrices (or both)
  • Allow to send characters and convert the ASCII code to
    dot matrices understood by the display

  • Switch from one line to the next
 

Added:
>
>

HD44780 block diagram

hd4780blockDiag.png

 

The HD44780 library

As already explained several times, a library must supply:

Line: 120 to 178
 into the byte read before writing it back.

Added:
>
>

HD44780 registers

The HD44780 has a single register select pin (RS)

indicating that there must be writable 2 registers:

  • IR: the instruction register

  • DR: the data register
In addition the controller has a busy flag that can be read,

indicating that it performs an internal operation

and cannot take another command a this very moment.

Then there is an address counter which increments each time

the DR is written, thus pointing to the display data RAM (DDRAM)

location where the next character will be written.

The DDRAM

The Display Data RAM stores data in 8 bit character codes.

It has a size of 80 characters which in our case corresponds

to 2 lines of 40 chars (of which only 2*16 will be used.

ddram.png

2*16 character display

216displayDDRAM.png

Converting the 8bit code to a dot matrix

The hd44780 contains a character ROM which will convert the

8 bit character code (mainly ascii code) to

  • a 5*8 dot matrix with 208 predefined characters
    (this is what we will use)
  • a 5*10 dot matrix with 32 characters
There is also a Character Generator RAM where you can

create up to 8 5*8 dot matrices yourself

Character Generator

charGen.png

Dot matrix and the display

intfce2displ.png

Interfacing to the MPU

The HD44780 can be controlled with 8 or with 4 data bits.

In 4 bit mode (this is what we use) with the lower 4 MPU bits

connected to d4-d7 while the upper 4 MPU bits are used to drive.

The hd44780 data lines d0 – d3 are disabled

The upper four bits are used to drive

  • RS (register select)
  • RW (read / write)
  • Strobe (E=enable)
  • and back light
In this case the four highest significant data bits are sent first.

Instruction Summary

instructions.png

Instruction Summary (2)

instructions-2.png

Writing to the HD44780 in 4-bit mode

In order to write to the IR or DR of the HD44780 in 4-bit mode we must:

  • Prepare an 8 bit value and put the highest significant
  • 4 bits of the data to be written into its lower 4 bits
  • Set the R/W bit to low
  • Setup the RS bit (0 for IR, 1 for DR)
  • Strobe the data into the controller
  • Repeat the same thing for the lower significant
    8 bits of the data we want to write
  • Keep the BL bit constant

Strobe function

strobe.png

Writing a command and writing data

In my library I define 2 functions:

  • hd44780WriteCmd (unsigned char cmd)
  • hd44780PutC (char c)
As you would guess, the first command writes the IR register,

while the second one writes a single character to the DR

Of course these two calls use the strobe function explained before.

In these functions I hide all the details of the 4-bit interface

All subsequent functions will pass through these two basic functions.

hd44780WriteCmd

writeWmd.png

 

Timing diagrams 4 bit mode

4bitdataTransfer.png

Added:
>
>

The initialization procedure

initProc1.png

Initialization Procedure (2)

initProc2.png

Initialization procedure (code)

These are the instructions:

First we define the function set command

(0x20) with bit 4 set to zero (4 bit interface)

This is written as an 8 bit command (the lower 4 bits are not seen)

bits.png
functionSet.png



Now the controller switches to 4 bit format and

from now on we have to write twice for each

8 bit word sent to the controller.

We re-write the same command in 4 bit mode specifying

the font (5*8 dots) and the no of lines = 2 in addition

These bits were lost in the first (8 bit) transfer

 %SLIDESHOWEND%

-- Uli Raich - 2017-11-06

Line: 135 to 347
 
META FILEATTACHMENT attachment="4bitdataTransfer.png" attr="" comment="" date="1509982394" name="4bitdataTransfer.png" path="4bitdataTransfer.png" size="28652" user="uli" version="1"
META FILEATTACHMENT attachment="4bitTransfer.png" attr="" comment="" date="1509982394" name="4bitTransfer.png" path="4bitTransfer.png" size="24602" user="uli" version="1"
META FILEATTACHMENT attachment="displaySignals.png" attr="" comment="" date="1509982394" name="displaySignals.png" path="displaySignals.png" size="16398" user="uli" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="initProc1.png" attr="" comment="" date="1509982394" name="initProc1.png" path="initProc1.png" size="30639" user="uli" version="1"
META FILEATTACHMENT attachment="initProc2.png" attr="" comment="" date="1509982394" name="initProc2.png" path="initProc2.png" size="28344" user="uli" version="1"
>
>
META FILEATTACHMENT attachment="initProc1.png" attr="" comment="" date="1510496819" name="initProc1.png" path="initProc1.png" size="30639" user="uli" version="1"
META FILEATTACHMENT attachment="initProc2.png" attr="" comment="" date="1510496819" name="initProc2.png" path="initProc2.png" size="28344" user="uli" version="1"
 
META FILEATTACHMENT attachment="libFunctions.png" attr="" comment="" date="1509982394" name="libFunctions.png" path="libFunctions.png" size="29147" user="uli" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="pcf8574ifce.png" attr="" comment="" date="1509982394" name="pcf8574ifce.png" path="pcf8574ifce.png" size="65250" user="uli" version="1"
META FILEATTACHMENT attachment="strobe.png" attr="" comment="" date="1509982394" name="strobe.png" path="strobe.png" size="69961" user="uli" version="1"
>
>
META FILEATTACHMENT attachment="pcf8574ifce.png" attr="" comment="" date="1510496843" name="pcf8574ifce.png" path="pcf8574ifce.png" size="65250" user="uli" version="1"
META FILEATTACHMENT attachment="strobe.png" attr="" comment="" date="1510497029" name="strobe.png" path="strobe.png" size="69961" user="uli" version="1"
 
META FILEATTACHMENT attachment="2linedisplay.png" attr="" comment="" date="1509982432" name="2linedisplay.png" path="2linedisplay.png" size="894036" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_pcf8574.png" attr="" comment="" date="1509982435" name="i2c_pcf8574.png" path="i2c_pcf8574.png" size="1038370" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8574write.png" attr="" comment="" date="1509984483" name="pcf8574write.png" path="pcf8574write.png" size="34655" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_write_byte.png" attr="" comment="" date="1509984637" name="i2c_write_byte.png" path="i2c_write_byte.png" size="15228" user="uli" version="1"
Added:
>
>
META FILEATTACHMENT attachment="216displayDDRAM.png" attr="" comment="" date="1510496780" name="216displayDDRAM.png" path="216displayDDRAM.png" size="26196" user="uli" version="1"
META FILEATTACHMENT attachment="charGen.png" attr="" comment="" date="1510496780" name="charGen.png" path="charGen.png" size="86776" user="uli" version="1"
META FILEATTACHMENT attachment="hd4780blockDiag.png" attr="" comment="" date="1510496780" name="hd4780blockDiag.png" path="hd4780blockDiag.png" size="50322" user="uli" version="1"
META FILEATTACHMENT attachment="bits.png" attr="" comment="" date="1510496780" name="bits.png" path="bits.png" size="4373" user="uli" version="1"
META FILEATTACHMENT attachment="functionSet.png" attr="" comment="" date="1510496780" name="functionSet.png" path="functionSet.png" size="6328" user="uli" version="1"
META FILEATTACHMENT attachment="instructions.png" attr="" comment="" date="1510496820" name="instructions.png" path="instructions.png" size="45292" user="uli" version="1"
META FILEATTACHMENT attachment="instructions-2.png" attr="" comment="" date="1510496820" name="instructions-2.png" path="instructions-2.png" size="40947" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8574blockDiag.png" attr="" comment="" date="1510496843" name="pcf8574blockDiag.png" path="pcf8574blockDiag.png" size="23545" user="uli" version="1"
META FILEATTACHMENT attachment="writepcf8574.png" attr="" comment="" date="1510497029" name="writepcf8574.png" path="writepcf8574.png" size="54065" user="uli" version="1"
META FILEATTACHMENT attachment="ddram.png" attr="" comment="" date="1510497986" name="ddram.png" path="ddram.png" size="11274" user="uli" version="1"
META FILEATTACHMENT attachment="intfce2displ.png" attr="" comment="" date="1510498022" name="intfce2displ.png" path="intfce2displ.png" size="15238" user="uli" version="1"
META FILEATTACHMENT attachment="writeWmd.png" attr="" comment="" date="1510498874" name="writeWmd.png" path="writeWmd.png" size="74073" user="uli" version="1"

Revision 32017-11-12 - uli

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

Line: 85 to 85
 

Using the library

Changed:
<
<
In addition to the prototypes, have a look at the doxygen documentation
>
>
In addition to the prototypes, have a look at the doxygen documentation
  and you should be able to program the display.

Revision 22017-11-06 - uli

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

The 2 Line LCD Display and its HD44780 Controller

Uli Raich

UCC semester 2017/2018

Added:
>
>

Why a simple 2 line display?

Often embedded systems do not have a screen, keyboard and mouse associated with them.

Small devices in the field may nevertheless need to display some values to the user

Small and cheap LCD displays can take over this task

Our display can be used for many purposes (see the open day):

  • Name display
  • Weather station
  • Voltmeter
and there are many more applications

Our Display

2linedisplay.png

Interfacing the display

pcf8574ifce.png

The PCF8574 I2C interface

The PCF8574 I2C I/O expander allows to limit the number of connection wires to just four.
It is a kind of a shift register: serial in, parallel out

i2c_pcf8574.png

Interfacing signals

The display needs a large number of interface signals
to be able to work:

  • Min. 4 data lines
  • R/W line
  • register select
  • back light
  • back light power
  • power
  • gnd

Writing the to HD4780 controller via the PCF8574

pcf8574write.png

Writing to PCF8574 via pigpio

Even though it looks complicated at first sight,

writing a data byte to the hd44780 controller via the

pcf8574 I/O extender is actually pretty simple:

i2c_write_byte.png

After this instruction the 8 data bits of bVal lie at the input of the hd44780 controller.

A data byte to be sent

We will therefore need a great deal of bit fiddling to

create this data byte and to modify it to

  • Set the back light on or off
  • To send a pulse on the E (strobe) line
Hope you remember the

  • bitwise or operator: |
  • bitwise and operator: &
  • bit inversion: ~

The HD44780 library

As already explained several times, a library must supply:

  • The binary code: libhd44780.so
  • The include file hd44780.h

The function prototypes

libFunctions.png

Using the library

In addition to the prototypes, have a look at the doxygen documentation

and you should be able to program the display.

Of course you have to include

-I/opt/ucc/include in your CFLAGS

-L/opt/ucc/lib in your LDFLAGS

and -lhd4780 in your LDLIBS

However, we want to understand what is happening behind the scene!

Testing access

Before starting to write the library we must first test if

  • We can initialize the device ?
  • We can write something to it and read it back ?
  • Or can we find any other function showing us that the device responds?

Back light

To give us some confidence, let’s try to switch the back light on and off:

This one is easy as it does not access the hd44780.

It does test the PCF8574 though!

Switching bit 7 in the data word does the trick.

Later we will read a byte from the display and and/or bit seven

into the byte read before writing it back.

Timing diagrams 4 bit mode

4bitdataTransfer.png

 %SLIDESHOWEND%

-- Uli Raich - 2017-11-06

Line: 11 to 131
 

Comments

<--/commentPlugin-->
Added:
>
>
META FILEATTACHMENT attachment="4bitdataTransfer.png" attr="" comment="" date="1509982394" name="4bitdataTransfer.png" path="4bitdataTransfer.png" size="28652" user="uli" version="1"
META FILEATTACHMENT attachment="4bitTransfer.png" attr="" comment="" date="1509982394" name="4bitTransfer.png" path="4bitTransfer.png" size="24602" user="uli" version="1"
META FILEATTACHMENT attachment="displaySignals.png" attr="" comment="" date="1509982394" name="displaySignals.png" path="displaySignals.png" size="16398" user="uli" version="1"
META FILEATTACHMENT attachment="initProc1.png" attr="" comment="" date="1509982394" name="initProc1.png" path="initProc1.png" size="30639" user="uli" version="1"
META FILEATTACHMENT attachment="initProc2.png" attr="" comment="" date="1509982394" name="initProc2.png" path="initProc2.png" size="28344" user="uli" version="1"
META FILEATTACHMENT attachment="libFunctions.png" attr="" comment="" date="1509982394" name="libFunctions.png" path="libFunctions.png" size="29147" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8574ifce.png" attr="" comment="" date="1509982394" name="pcf8574ifce.png" path="pcf8574ifce.png" size="65250" user="uli" version="1"
META FILEATTACHMENT attachment="strobe.png" attr="" comment="" date="1509982394" name="strobe.png" path="strobe.png" size="69961" user="uli" version="1"
META FILEATTACHMENT attachment="2linedisplay.png" attr="" comment="" date="1509982432" name="2linedisplay.png" path="2linedisplay.png" size="894036" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_pcf8574.png" attr="" comment="" date="1509982435" name="i2c_pcf8574.png" path="i2c_pcf8574.png" size="1038370" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8574write.png" attr="" comment="" date="1509984483" name="pcf8574write.png" path="pcf8574write.png" size="34655" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_write_byte.png" attr="" comment="" date="1509984637" name="i2c_write_byte.png" path="i2c_write_byte.png" size="15228" user="uli" version="1"

Revision 12017-11-06 - uli

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: The 2 Line LCD Display and its HD44780 Controller

The 2 Line LCD Display and its HD44780 Controller

Uli Raich

UCC semester 2017/2018

-- Uli Raich - 2017-11-06

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback