Fork me on GitHub

Project Notes

#778 AT89C2051 LCD Control

Demonstrates HD44780-based LCD control using the AT89C2051 (8051) microprocessor, compiled with SDCC on macOS.

Build

Notes

This is a demonstration of how to control an HD44780-based LCD such as the QC1602A. See LEAP#749 HD44780-based LCD Modules for more information about such displays.

In this example, we will be controlling the 16-pin interface directly. No libraries are used.

Circuit Design

bb

schematic

bb_build

Code

All the code is in a single file: LcdControl.c.

The main function:

  • calls init_lcd to initialise the display
  • calls write_welcome to send a message to the display (“MAKE MORE PROJECTS”)
  • goes into an endless do-nothing loop

All LCD interaction is accomplished with the send_command and send_data functions. These simply:

  • load the command/data into the P1 8-bit register
  • set the appropriate Register Select (RS) - command or data
  • toggle the enable line high then low, with a suitable delay
/*
 * Command: send LCD command. Assumes RW=0 (write mode) is hard-wired.
 */
void send_command(unsigned int command_value ) {
  P1=command_value;
  RS=0;
  E=1;
  ms_delay(10);
  E=0;
}

/*
 * Command: send LCD data. Assumes RW=0 (write mode) is hard-wired.
 */
void send_data(unsigned int data_value) {
  P1=data_value;
  RS=1;
  E=1;
  ms_delay(10);
  E=0;
}

Programming

The Makefile is setup to compile the code using the SDCC compiler .. running on macOS in this instance:

$ make
sdcc -mmcs51 --code-size 2048 LcdControl.c -o LcdControl.ihx
packihx LcdControl.ihx > LcdControl.hex
packihx: read 21 lines, wrote 31: OK.

And program the chip using at89overlord and the LEAP#394 AT89C2051 Programmer:

$ at89overlord -p /dev/tty.usbserial-2420 -f ./LcdControl.hex
# Initializing the programmer...
# Initialized!
# Confirming chip ID...
# Confirmed!
# Erasing flash...
# Done!
# Writing flash...
# Done!
# Verifying...
# Done!

Credits and References

About LEAP#778 8051HD44780LCD

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader