Aim
To interface a 16×2 character LCD (HD44780) with the 8051 and write an Embedded C program to display messages on the LCD.
Learning objectives
Identify RS, RW, EN and D0–D7 and their roles.
Send the init sequence 38H, 0CH, 01H, 06H in the right order with correct delays.
Write command and data functions using RS.
Place text on line 1 (80H) and line 2 (C0H).
Send C strings with a pointer loop.
Respect busy times: 40 µs per write, 1.64 ms for clear/home.
What this experiment demonstrates
- A parallel bus protocol with a strobe signal (EN).
- Why timing matters: a write while the controller is busy is lost.
- Converting numbers to ASCII for display.
Sub-tasks
- 10.1 A Display two messages
- 10.1 B Scrolling message
- 10.1 C Live counter (number → ASCII)
LCD interface
Software delay in C
The exact count depends on the compiler's optimisation level, so calibrate it with Keil's stopwatch (t1 in the status bar) or this simulator's clock. The often-quoted value 1275 was calibrated for a 1-clock DS89C4x0 chip. On a classic 12-clock 8051 it gives about 11 ms per count.
Initialisation sequence
Each write is a pulse on EN: put the data on D0–D7, set RS (0 = command, 1 = data) and RW = 0, then EN = 1 → EN = 0. The LCD latches the data on the falling edge.
Board wiring (this lab)
| LCD | 8051 |
|---|---|
| D0–D7 | P1.0–P1.7 |
| RS | P2.0 |
| RW | P2.1 (kept 0) |
| EN | P2.2 |
| V0 (contrast) | 10 k pot |
Apparatus & environment
| Item | Specification | Qty |
|---|---|---|
| PC with Keil µVision | C51/A51 tool chain (evaluation version is fine) | 1 |
| 8051 trainer board | Nuvoton W78E052D, 11.0592 MHz crystal | 1 |
| Nuvoton ISP-ICP utility | APROM programming over USB-UART (CH340) | — |
| USB cable | USB-A to the board's serial/ISP port | 1 |
| Power supply | +5 V regulated (board adapter) | 1 |
| LCD module | 16×2 HD44780 with backlight | 1 |
| Potentiometer | 10 kΩ for contrast | 1 |
Safety rules & good practice
- ⚡ Switch the board off before connecting or removing modules, ribbon cables or jumpers.
- 🔌 Check the supply: +5 V only. Reverse polarity or more than 6 V destroys the controller.
- 🧲 Handle ICs by the edges and touch a grounded surface first (ESD).
- 🔁 Do not drive a port pin connected to a switch with 0 while the switch is pressed to VCC. Read inputs only after writing 1s.
- 🔥 If a component gets hot or smells, switch off immediately and inform the instructor.
- 🔆 Adjust the contrast pot until the top row just shows faint blocks before running the program.
Procedure (hardware / real tools)
- Connect D0–D7 to Port 1, RS/RW/EN to P2.0/P2.1/P2.2 and the contrast pot, with the power off.
- Power on without a program: the top row should show dark blocks (an uninitialised LCD).
- Build and program 10.1 A. Check both lines.
- Remove the delay after the clear command and observe lost characters.
- Build 10.1 B and 10.1 C (scrolling and counter).
Doing it in this virtual lab
- Choose a sub-task chip. The program opens in the µVision window.
- Press 🔨 Build (F7). Errors are listed in Build Output: click one to jump to the line.
- Press ▶ Run (F5) and watch the board. Use ¼× to 1/1000× slow motion to see fast events.
- Use Step (F11) and Step Over (F10), and click line numbers to set breakpoints.
- Edit the code (delay, pattern, pins), rebuild, and observe the change. Press ● Record to log results.
- The LCD card shows a log of every command the controller receives. Busy violations are flagged.
Pre-Lab Test 6 questions · diagnostic
Check your prerequisite knowledge. Each answer gets instant feedback. Score at least 4/6 before using the simulator.
Observation table
Rows are added by ● Record in the simulator: inputs, the expected (theoretical) value and the simulator result. Type your own hand calculation in "Your value" to check it. Add rows by hand for hardware-bench readings. The table is saved in this browser.
| # | Sub-task | Inputs | Expected | Simulator | Your value | Check | Note |
|---|
Edge cases to test
- Remove
delay_ms(2)from lcd_cmd(): characters are lost after the clear command. - Remove
lcd_cmd(0x38): line 2 stays blank (1-line mode). - Use 0x0E or 0x0F instead of 0x0C to show the cursor or make it blink.
- Send a digit as a number (lcd_data(7)) instead of ASCII.
- Write more than 16 characters on line 1 without scrolling: where do they go?
- Set RW = 1 during a write.
Analysis & conclusion
Post-Lab Test 9 questions · instant hints
A wrong answer shows a hint so you can try again. Only first attempts count towards the score.
Self-evaluation
Tick what you can now do confidently.