LCD Programming Examples

Program Code (more information below)

Four-bit interface using software time delays.   Assembly Language     C     Arduino
Four-bit interface using the busy flag.             Assembly Language     C     Arduino
Eight-bit interface using software time delays.  Assembly Language     C     Arduino
Eight-bit interface using the busy flag.            Assembly Language     C     Arduino

Eight-bit interface using software time delays, simple version. Assembly Language     C

Character based LCD modules

The programming examples in this section are for use with character based LCD modules, specifically those controlled by an Hitachi HD44780U or equivalent.

Target Processor

These examples are all written for the Atmel ATmega328p microcontroller since that is the platform for which I currently have equipment.   These programs are fully commented and they should be of value regardless of the processor that you are using.   These programs are actually based on code that I wrote for the 8085 processor about 20 years ago.   They were first modified for use on the 68HC11, then for some early PICs, and most recently for the ATmega328.

Programming language

I have examples written in assembly language, in C, and for most versions in the Arduino IDE version of C.

Program Philosophy

These programs are intended to be as easy to follow as possible.   No clever programming techniques have been used to reduce the size of the code or improve the speed of the code.   There are different techniques that can be used to accomplish many of the tasks required by these programs, the techniques in these programming examples are the ones that I happen to be using at the present time.   I am not implying that the techniques presented here are the simplest, the fastest, the most efficient, or anything else.   I do know that they work quite reliably.

Program License

These programs are licensed under the terms of the GNU General Public License.
You can see a copy of the license here: The GNU General Public License.
You can get more information about the license here: Information about the GNU General Public License.

More information about each of the Example Programs

Eight-bit interface using software time delays, simple version.

If you are just starting out then this is the configuration that I recommend you use.   All eight LCD data lines must be implemented, in sequence, on a single 8-bit port but that restriction simplifies the programming.   The Enable and Register Select lines may be implemented on any two available pins of any other port.

Programming example in Assembly Language.
Programming example in C.

Eight-bit interface using software time delays.

This is a much more useful version than the simplified one.   At the expense of some slightly more complicated programming the eight data lines as well as the Enable and Register Select lines may be implemented on any available I/O pin of any port.   This means that you can easily work around other devices that require the use of specific I/O pins.

Programming example in Assembly Language.
Programming example in C.
Programming example in Arduino IDE C.

Four-bit interface using software time delays.

This is the version that you will most likely want to use for most of your applications.   It uses only six I/O lines and since you can use any available I/O pin for any of the signals it allows you to easily work around other devices that require the use of specific I/O pins.

Programming example in Assembly Language.
Programming example in C.
Programming example in Arduino IDE C.

Eight-bit interface using the busy flag.

If you feel that you want to learn how to implement the use of the busy flag then you should do this first with an eight-bit interface.   This version allows you to use any available I/O pin for any of the signals.   There are now three control lines so you will need eleven I/O pins.

Programming example in Assembly Language.
Programming example in C.
Programming example in Arduino IDE C.

Four-bit interface using the busy flag.

If you really want to use the busy flag in your application then this is the version to use.   This version allows you to use any available I/O pin for any of the seven signals.

Programming example in Assembly Language.
Programming example in C.
Programming example in Arduino IDE C.