8051 interfacing with LCD display in proteus
In this article we will learn how to Interface 8051 with LCD display in proteus.
In the last post we will learn how to Interface Arduino TC74 sensor with Alphanumeric LCD circuit in proteus. You can visit our website,
I hope you appreciate my work, let’s discuss about today’s project.
Components:
- IC (80C51)
- IC (74LS373)
- NAND 2
- LCD display (LM032L)
- Crystal (1.2/MHz)
- Capacitor (33p)
- Jumper wires
Construction…
- Connect pin 9 of 8051 with +ve
- Connect pin 18 of 8051 with one side of capacitor 33p through the one side of crystal
- Connect 2nd side of capacitor with one side of 2nd capacitor and then connect them with GND
- Connect the pin 19 of 8051 with 2nd side of crystal through the 2nd side of 2nd capacitor
- Connect pin 16 of 8051 with one terminal of NAND
- Connect pin 17 of 8051 with 2nd terminal of NAND
- Connect signal pin of NAND with E pin of LCD display
- Connect VSS pin of LCD display with GND
- Connect VDD pin of LCD display with +ve
- Connect RS pin of LCD display with pin 2 of IC (74L)
- Connect RW pin of LCD display with pin 5 of IC (74L)
- Connect pin 3 of IC (74L) with D0 pin of LCD display
- Connect pin 4 of IC (74L) with D1 pin of LCD display
- Connect pin 7 of IC (74L) with D2 pin of LCD display
- Connect pin 8 of IC (74L) with D3 pin of LCD display
- Connect pin 13 of IC (74L) with D4 pin of LCD display
- Connect pin 14 of IC (74L) with D5 pin of LCD display
- Connect pin 17 of IC (74L) with D6 pin of LCD display
- Connect pin 18 of IC (74L) with D7 pin of LCD display
- Connect pin 11 of IC (74L) with the pin 30 of 8051
- Connect pin 1 of IC (74L) with GND
Working…
Interfacing an 8051 microcontroller with an LCD (Liquid Crystal Display) is a common task in embedded systems and microcontroller-based projects. The 8051 microcontroller communicates with the LCD to display characters, numbers, and other information on the screen.
Applications…
- Digital Thermometer
- Weather Station
- Home Automation
- Digital Clock
- Attendance System
Advantages…
- Low Power Consumption
- Simplicity
- Cost-Effective
- Compatibility
- Real-Time Feedback
Program code…
<div>#include <bitdef.h></div>
<div>#include <io80C51BH.h></div>
<div></div>
<div>;LCD Registers addresses</div>
<div>LCD_CMD_WR equ 0</div>
<div>LCD_DATA_WR equ 1</div>
<div>LCD_BUSY_RD equ 2</div>
<div>LCD_DATA_RD equ 3</div>
<div></div>
<div>;LCD Commands</div>
<div>LCD_CLS equ 1</div>
<div>LCD_HOME equ 2</div>
<div>LCD_SETMODE equ 4</div>
<div>LCD_SETVISIBLE equ 8</div>
<div>LCD_SHIFT equ 16</div>
<div>LCD_SETFUNCTION equ 32</div>
<div>LCD_SETCGADDR equ 64</div>
<div>LCD_SETDDADDR equ 128</div>
<div></div>
<div>;Reset vector</div>
<div>org 0000h</div>
<div>jmp start</div>
<div></div>
<div></div>
<div>;Start of the program</div>
<div>org 0100h</div>
<div></div>
<div>string1a:db ' !! A M A Z I N G !! '</div>
<div>db 0</div>
<div>string1b:db '!! A M A Z I N G !! '</div>
<div>db 0</div>
<div>string2:db ' A virtual LM032L… '</div>
<div>db 0</div>
<div></div>
<div>string3:db ' driven by a virtual '</div>
<div>db 0</div>
<div>string4:db ' 8051 processor!'</div>
<div>db 0</div>
<div></div>
<div>start: mov A,#038h</div>
<div>call wrcmd</div>
<div></div>
<div>loop: mov A,#LCD_SETVISIBLE+6 ;Make the display & blink visible:</div>
<div>call wrcmd</div>
<div></div>
<div>mov R7,#2</div>
<div>loop2:</div>
<div>mov DPTR,#string1a</div>
<div>call wrstr</div>
<div></div>
<div> mov DPTR,#200</div>
<div> call wtms</div>
<div></div>
<div>mov A,#LCD_CLS;Clear screen</div>
<div>call wrcmd</div>
<div></div>
<div>mov DPTR,#string1b</div>
<div>call wrstr</div>
<div></div>
<div> mov DPTR,#200</div>
<div> call wtms</div>
<div></div>
<div>mov A,#LCD_CLS;Clear screen</div>
<div>call wrcmd</div>
<div></div>
<div>djnz R7,loop2</div>
<div></div>
<div>mov DPTR,#string1a</div>
<div>call wrstr</div>
<div></div>
<div> mov DPTR,#400</div>
<div> call wtms</div>
<div></div>
<div>mov A,#LCD_SETDDADDR+64</div>
<div>call wrcmd</div>
<div></div>
<div>mov DPTR,#string2</div>
<div>call wrslow</div>
<div></div>
<div> mov DPTR,#200</div>
<div> call wtms</div>
<div></div>
<div>mov A,#LCD_CLS;Clear screen</div>
<div>call wrcmd</div>
<div></div>
<div>mov DPTR,#string3</div>
<div>call wrslow</div>
<div></div>
<div> mov A,#LCD_SETDDADDR+64</div>
<div>call wrcmd</div>
<div></div>
<div>mov DPTR,#string4</div>
<div>call wrslow</div>
<div></div>
<div>mov A,#LCD_SETVISIBLE+7;Show the blink cursor as well.</div>
<div>call wrcmd</div>
<div></div>
<div> mov DPTR,#2000</div>
<div> call wtms</div>
<div></div>
<div>mov A,#LCD_CLS;Clear screen</div>
<div>call wrcmd</div>
<div></div>
<div>jmp loop</div>
<div></div>
<div></div>
<div>;Sub routine to write null terminated string at DPTR in program ram.</div>
<div>wrstr: mov R0,#LCD_DATA_WR</div>
<div>wrstr1: clr A</div>
<div>movc A,@A+DPTR</div>
<div>jz wrstr2</div>
<div>movx @R0,A</div>
<div>call wtbusy</div>
<div>inc DPTR</div>
<div>push DPL</div>
<div>push DPH</div>
<div>pop DPH</div>
<div>pop DPL</div>
<div>jmp wrstr1</div>
<div>wrstr2: ret</div>
<div></div>
<div>;Sub routine to write null terminated string at DPTR in program ram. Slowly</div>
<div>wrslow: mov R0,#LCD_DATA_WR</div>
<div>wrslw1: clr A</div>
<div>movc A,@A+DPTR</div>
<div>jz wrslw2</div>
<div>movx @R0,A</div>
<div>call wtbusy</div>
<div>inc DPTR</div>
<div>push DPL</div>
<div>push DPH</div>
<div> mov DPTR,#100</div>
<div> call wtms</div>
<div>pop DPH</div>
<div>pop DPL</div>
<div>jmp wrslw1</div>
<div>wrslw2: ret</div>
<div></div>
<div></div>
<div>;Sub routine to write command:</div>
<div>wrcmd: mov R0,#LCD_CMD_WR</div>
<div>movx @R0,A</div>
<div>jmp wtbusy</div>
<div></div>
<div></div>
<div>;Sub routine to write character:</div>
<div>wrchar: mov R0,#LCD_DATA_WR</div>
<div>movx @R0,A</div>
<div></div>
<div>;Subroutine to wait for busy clear</div>
<div>wtbusy: mov R1,#LCD_BUSY_RD</div>
<div>movx A,@r1</div>
<div>jb ACC.7,wtbusy</div>
<div>ret</div>
<div></div>
<div>;Wait for number of seconds in A</div>
<div>wtsec: push ACC</div>
<div>call wtms</div>
<div>pop ACC</div>
<div>dec A</div>
<div>jnz wtsec</div>
<div>ret</div>
<div></div>
<div>;Wait for number of milliseconds in DPTR</div>
<div>wtms: xrl DPL,#0FFh ;Can't do DEC DPTR, so do the loop by forming 2's complement</div>
<div>xrl DPH,#0FFh;and incrementing instead.</div>
<div>inc DPTR</div>
<div>wtms1: mov TL0,#09Ch ;100 ticks before overflow = 1ms at 1.2MHz Clock</div>
<div>mov TH0,#0FFh</div>
<div>mov TMOD,#1;Timer 0 mode 1</div>
<div>setb TCON.4;Timer 0 runs</div>
<div>wtms2:jnb TCON.5,wtms2</div>
<div>clr TCON.4;Timer 0 stops</div>
<div>clr TCON.5</div>
<div>inc DPTR</div>
<div>mov A,DPL</div>
<div>orl A,DPH</div>
<div>jnz wtms1</div>
<div>ret</div>