February 2012 Doc ID 022651 Rev 1 1/19
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.
www.st.com
Contents AN4032
2/19 Doc ID 022651 Rev 1
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