ST AN4032 APPLICATION NOTE

AN4032

Application note

Interfacing an HD44780 2-line LCD display with the STM8SVLDISCOVERY

Introduction

This application note describes how to use a firmware example that drives a standard HD44780 2-line LCD display with the STM8SVLDISCOVERY.

The example uses an LCD display driver that has been developed to be as generic as possible, so it can be reused with any STM8 device.

The firmware package associated to this application note includes a pre-configured project template which facilitates development of your own application to use an HD44780 LCD display module.

The LCD interface offers many ways to easily create a user interface to display text messages and other application related information, whilst using very few internal hardware resources.

The HD44780 is a common LCD controller and is very widespread through various formats, 1 X 8, 2 x 16, 2 x 20, 4 x 20 and others. This example uses the very popular 2 x 16 format (2 lines of 16 characters) which is now offered at a very reasonable price. Other LCD display modules based on compatible ST7066 or KS0066U controllers could also be used.

This application example intentionally uses the least possible microcontroller pins as the interface bus to the LCD module is 4-bits wide.

This application example requires additional hardware:

LCD module HD44780

Potentiometer to adjust LCD contrast.

Reference documents

STM8SVLDISCOVERY STM8S value line discovery (UM1482).

STM8SVLDISCOVERY quick start guide (UM1480)

All these documents are available at http://www.st.com.

February 2012

Doc ID 022651 Rev 1

1/19

www.st.com

Contents

AN4032

 

 

Contents

1

Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

1.1

Hardware required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

1.2

STM8SVLDISCOVERY hardware settings . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

1.3

HD44780 LCD display module description . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

1.4

Hardware interface application schematics . . . . . . . . . . . . . . . . . . . . . . . .

6

 

1.5

Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

1.5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.5.2 LCD interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.5.3 Custom characters definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2

Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

 

2.1

STM8S peripherals used by the application . . . . . . . . . . . . . . . . . . . . . . .

11

 

2.2

Configuring STM8S/A standard peripherals library . . . . . . . . . . . . . . . . .

12

2.2.1 For use with this application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.2 For other uses of the HD44780 LCD display driver . . . . . . . . . . . . . . . . 12

2.3 Application software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.3.1 Main application flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.3.2 HD44780 LCD display module library description . . . . . . . . . . . . . . . . . 15

3

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

4

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18

2/19

Doc ID 022651 Rev 1

AN4032

List of tables

 

 

List of tables

Table 1. LCD display module connector pin assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Table 2. HD44780.c functions relevant to LCD display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Table 3. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Doc ID 022651 Rev 1

3/19

List of figures

AN4032

 

 

List of figures

Figure 1. HD44780 LCD display module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 5

Figure 2. Hardware interface of the LCD display and the STM8SVLDISCOVERY . . . . . . . . . . . . . .

. 7

Figure 3.

HD44780 LCD display demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 8

Figure 4.

Example of A character definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 9

Figure 5.

Custom characters of application example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

Figure 6.

Main application flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

4/19

Doc ID 022651 Rev 1

ST AN4032 APPLICATION NOTE

AN4032

Application description

 

 

1 Application description

1.1Hardware required

This application uses the STM8SVLDISCOVERY on-board LED LD1, an HD44780 or equivalent 2-line LCD display and a 10 kΩto 20 kΩpotentiometer to adjust LCD contrast. Some LCD models include an LCD backlight feature but this application note does not deal with this implementation. The LCD display module used in this example is a WINTEK WDC1602R which is fully compliant with an HD44780 controller, it has 16 characters X 2 lines and a character format of 5 X 8 dots. The LCD current consumption for logic is typically

2 mA.

1.2STM8SVLDISCOVERY hardware settings

JP1 (power supply jumper) must be put in the 5V position, to provide the correct VDD for LCD module operation. There are no other specific settings for the STM8SVLDISCOVERY. The LCD can be:

Connected directly with extra wires to the STM8SVLDISCOVERY CN1, CN2 and CN3 connectors.

Interfaced with a daughterboard (connected via these same connectors, plus CN4 for mechanical support) that receives the LCD module and the potentiometer with a proper PCB layout (not detailed here).

1.3HD44780 LCD display module description

The LCD display module includes 2 16-character lines and a 16-pin connector. Each character position is identified by its row number (1 or 2), and its column number (from 1 to 16). For example, when used in the software library: Location (2, 10) refers to the 10th character of the 2nd line. See Table 1 on page 6 for connector details.

Figure 1. HD44780 LCD display module

 

 

 

 

 

 

 

 

 

 

 

 

-3 6

Doc ID 022651 Rev 1

5/19

Application description

 

 

 

 

 

 

 

 

 

 

AN4032

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table 1.

LCD display module connector pin assignments

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

GND

VCC

VEE

RS

R/W

E

DB0

DB1

DB2

DB3

DB4

DB5

DB6

DB7

NC

NC

or V0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LCD

Register

Read/Write

Enable

 

 

 

 

 

 

 

 

 

 

 

 

Select

4-bit low order data

4-bit high order data

-

-

0V

+5V

power

0: Write

LCD

 

 

supply

0: Command

1: Read

module

bus

 

 

 

bus

 

 

 

 

 

 

 

1: Data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.4Hardware interface application schematics

The LCD display module can easily be interfaced with the STM8SVLDISCOVERY using the application schematics (Figure 2).

On the STM8SVLDISCOVERY side, the application uses 7 microcontroller I/Os, see the proposed hardware configuration in Figure 2. When required, users can easily modify the pin selection in the application software by editing the LCD port declarations in the HD44780.h header file. The only considerations to take into account are the pins’ compatibility according to their function:

For example, PE5 supplies LCD drive current due to its high sink capability (can drive more current than a standard port). If you change the MCU I/O which powers the LCD module, you must ensure that it features high sink capability.

Some pins of the STM8S003K3 have no internal push-pull capability so they cannot be selected for the LCD port, control or power pins. Please read the pins description in the STM8S003K3 datasheet carefully if hardware configuration change is required.

On the LCD display side:

In order to display a character or send a command to the LCD, a byte corresponding to the character ASCII code or to the command byte value must be sent. Data can be sent from the MCU to the LCD in 4-bit or 8-bit operation.

In 8-bit mode, this operation is done in one send.

In 4-bit mode, this operation requires two sends of 4-bit data.

This application uses 4-bit operation, so only DB4 to DB7 need to be connected (LCD 4-bit data bus) and DB0 to DB3 are not connected.

If the LCD port is changed, the user must assign the lower nibble of a new MCU port to the LCD data bus. For example, in this application example MCU port B is the LCD port with PB0 to PB3 pins. If a different MCU port was chosen, the choice of possible LCD port pins is limited to Px0 to Px3 (due to firmware management), where x can be A, B, C, etc… according to the pins availability on the device.

The R/W pin of the LCD display module is connected to GND (Write is active). Only Write operations to LCD memory are performed in this example. Data are exclusively written into LCD and the firmware provides adequate timing needed for each command without polling the internal LCD busy flag.

A potentiometer is connected to VEE/V0. Contrast can be adjusted accordingly.

6/19

Doc ID 022651 Rev 1

Loading...
+ 13 hidden pages