This repository demonstrates interfacing a 16x2 alphanumeric LCD with the 8051 Microcontroller using Assembly language. The project is designed to show how to send data from the 8051 microcontroller to an LCD. It includes Proteus simulation files for testing and visualization.
Fig-1: 8051 Microcontroller LCD Interface (Schematic Diagram).
The figure above shows the circuit schematic for interfacing the **16x2 LCD** with the **AT89C51 Microcontroller**. It includes essential connections for data transfer, control, and power, enabling the display of alphanumeric characters using **8-bit data mode**.
AT89C51 Microcontroller | Assembly Language | Proteus | 16x2 LCD | LCD Interfacing
This project demonstrates LCD interfacing with the AT89C51 Microcontroller. It is useful for educational purposes and embedded systems applications, allowing the microcontroller to display data on the LCD.
Feature | Description |
---|---|
π LCD Display | Displays data entered or processed by the microcontroller |
π₯οΈ Proteus Simulation | Includes a ready-to-use simulation circuit compatible with Proteus 8.9 |
πΎ Assembly Programming | Optimized assembly code for efficient execution on the AT89C51 |
π οΈ Real Hardware Test | Successfully tested on actual hardware for reliable performance |
File | Description |
---|---|
Assembly Code | The core assembly code for initializing and operating the LCD. (exampleproject.asm ) |
Proteus Simulation | Simulation file for testing the LCD interface in Proteus. (exampleproject.pdsjr ) |
HEX File | Compiled HEX file for uploading to the 8051 microcontroller. (exampleproject.hex ) |
Test Run Image | Image showing the test run result. |
-
Clone this repository:
git clone https://github.com/gmostofabd/8051-LCD.git
-
Compile the Assembly Code: Open the
AT89C51_LCD_Keypad.asm
file in MIDE-51 or any compatible IDE, and compile it to generate the HEX file. -
Simulate in Proteus: Open Proteus Design Suite, load the provided simulation file, and run the simulation to observe the interface's functionality.
-
Program the Microcontroller: For real hardware, upload the HEX file to the AT89C51 microcontroller using a compatible programmer.
-
Test the Circuit: Assemble the hardware based on the provided circuit diagram, power it on, and verify the LCD's functionality.
Component | Description |
---|---|
AT89C51 Microcontroller | The core of the project, programmed in Assembly language to control the LCD. |
16x2 LCD | Displays the output of the microcontroller in alphanumeric form. |
Crystal Oscillator (11.0592 MHz) | Provides a clock signal to the microcontroller for accurate timing. |
33pf Capacitors (2x) | Used with the crystal oscillator to stabilize the clock signal, connected between XTAL1 and XTAL2 of the microcontroller and ground. |
100 Ohm Resistor | Limits current in the circuit to protect components. |
10K Variable Resistor (Potentiometer) | Adjusts the contrast of the LCD, wired between VCC and GND, with the wiper connected to the contrast pin (V0) of the LCD. |
Push-button Switch (Reset) | Connected to the RST pin of the microcontroller for manual reset, with a pull-down resistor for stability. |
Jumper Wires | Connects components as needed. |
A Liquid Crystal Display (LCD) provides a useful interface for embedded systems. The 16x2 LCD displays textual information across two rows, each capable of showing 16 characters, with each character occupying a 5x7 matrix space on the screen.
To interface with the 16x2 LCD, follow these mandatory steps:
-
Initialization:
- Set the LCD to 8-bit mode by sending initialization commands.
-
Set RS and RW Pins:
- RS: Set to
0
for commands,1
for data. - RW: Set to
0
for writing,1
for reading (not often used in basic setups).
- RS: Set to
-
Send Commands/Data:
- Place the command or data in the data register and trigger the Enable Pin.
-
Enable Pulse:
- Toggle the Enable Pin to send the command/data.
-
Delay:
- Wait briefly after each command/data transfer to allow the LCD to process it.
; -----------------------------
; LCD Interfacing in 8-Bit Mode (lcd_8bit.asm)
; -----------------------------
ORG 00H ; Set origin to address 00H
MOV SP, #70H ; Initialize stack pointer at address 70H
MOV PSW, #00H ; Set program status word to 00H
LCD_IN:
MOV A, #38H ; Initialize LCD for 2 lines, 5x7 matrix
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #0EH ; Display ON, Cursor ON
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #01H ; Clear LCD display
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #06H ; Shift cursor to the right
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #85H ; Set cursor at line 1, position 1
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'E' ; Display letter 'E'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'X' ; Display letter 'X'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'P' ; Display letter 'P'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #':' ; Display colon ':'
LCALL DATAWRT ; Call data write subroutine
MOV A, #'0' ; Display number '0'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'4' ; Display number '4'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #0C3H ; Set cursor at line 2, position 1
LCALL COMNWRT ; Call command write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'8' ; Display number '8'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #' ' ; Display space
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'B' ; Display letter 'B'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'i' ; Display letter 'i'
LCALL DATAWRT ; Call data write subroutine
MOV A, #'t' ; Display letter 't'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #' ' ; Display space
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'L' ; Display letter 'L'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'C' ; Display letter 'C'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
MOV A, #'D' ; Display letter 'D'
LCALL DATAWRT ; Call data write subroutine
LCALL DELAY ; Give LCD some time
SJMP $ ; Infinite loop
; -----------------------------
; Command Write Subroutine
; -----------------------------
COMNWRT:
LCALL READY ; Prepare for sending command to LCD
MOV P1, A ; Copy content of register A to port 1
CLR P3.4 ; Set RS = 0 for command mode
CLR P3.5 ; Set R/W = 0 for write mode
SETB P3.6 ; Set E high for pulse
ACALL DELAY ; Give LCD some time
CLR P3.6 ; Set E low for H-to-L pulse
RET
; -----------------------------
; Data Write Subroutine
; -----------------------------
DATAWRT:
LCALL READY ; Prepare for writing data to LCD
MOV P1, A ; Copy content of register A to port 1
SETB P3.4 ; Set RS = 1 for data mode
CLR P3.5 ; Set R/W = 0 for write mode
SETB P3.6 ; Set E high for pulse
ACALL DELAY ; Give LCD some time
CLR P3.6 ; Set E low for H-to-L pulse
RET
; -----------------------------
; Ready Check Subroutine
; -----------------------------
READY:
SETB P1.7 ; Set P1.7 to indicate readiness
CLR P3.4 ; Clear RS
SETB P3.5 ; Set R/W = 1 for read mode
WAIT:
CLR P3.6 ; Clear E
ACALL DELAY ; Wait for delay
SETB P3.6 ; Set E high
JB P1.7, WAIT ; Wait until P1.7 is high (LCD ready)
RET
; -----------------------------
; Delay Subroutine
; -----------------------------
DELAY:
MOV R3, #50 ; Set outer loop count (50 or higher for fast CPUs)
HERE2:
MOV R4, #255 ; Set inner loop count (255)
HERE:
DJNZ R4, HERE ; Decrement R4 and repeat until it reaches 0
DJNZ R3, HERE2 ; Decrement R3 and repeat until it reaches 0
RET
END ; End of program
- LCD Initialization: The
LCD_INIT
procedure sets the LCD in 8-bit mode, turns on the display, and clears it. - Command and Data Functions:
LCD_CMD
sends commands to the LCD, whileLCD_DATA
sends data (characters). - String Sending: The
SEND_STRING
procedure sends a null-terminated string to the LCD for display. - Main Program: The
MAIN
procedure initializes the LCD and sends the string to display.
- Save the Code: Copy this code into a file named
lcd.asm
. - Compile: Use a compatible assembler to compile the code.
- Simulate or Upload: Use Proteus for simulation or upload it to the AT89C51 microcontroller.
Upon powering the circuit, the AT89C51 microcontroller initializes the LCD and sends a message to be displayed. This can be tested through simulation or real hardware.
Command | Hex Code | Description |
---|---|---|
Clear Display | 0x01 |
Clears the LCD and resets the cursor to home position. |
Return Home | 0x02 |
Returns the cursor to the home position. |
Entry Mode Set | 0x04 |
Sets the entry mode; cursor moves to the right. |
Display ON/OFF Control | 0x0C |
Turns the display on with the cursor off. |
Cursor ON/OFF Control | 0x0E |
Turns the cursor on, but without blinking. |
Blinking Cursor ON | 0x0F |
Turns the blinking cursor on. |
Shift Display Right | 0x1C |
Shifts the entire display to the right. |
Shift Display Left | 0x18 |
Shifts the entire display to the left. |
Function Set | 0x38 |
Sets the interface to 8-bit, 2-line mode with 5x7 dots. |
Set Cursor Position | 0x80 |
Sets the cursor position to the specified address. |
Scroll Display Right | 0x1C |
Scrolls the display right. |
Scroll Display Left | 0x18 |
Scrolls the display left. |
Set CGRAM Address | 0x40 |
Sets the address for the character generator RAM. |
Set DDRAM Address | 0x80 |
Sets the address for the display data RAM. |
- Verify the connections based on the schematic.
- Modify the code to display different messages.
- Experiment with the contrast and observe its effects.
- 8051 Microcontroller Reference: Datasheet
- LCD Datasheet: HD44780 LCD Controller
- Adding more functionalities such as scrolling text, custom characters, and additional interfacing techniques like 4-bit mode.
``` ---