Sunteți pe pagina 1din 7

Task III: LCD interfacing using 8051 Microcontroller

AIM/OBJECTIVE:
The objective is to interface an output device such as an LCD using 8051 microcontroller.
EQUIPMENT REQUIRED:
One LCD: LM016L
One uC: AT89C51
SOFTWARE USED:

Proteus ISIS Professional


Keil uVision 4

SUMMARY ON DATASHEET:
HD44780U is a 16*2 bit LCD device. The input voltage range is from 2.7 to 5.5V.The LCD chip used in here has 14
pins. While Vcc and Vss provide +5V and ground respectively, V EE is used for controlling the contrast. The pin
description as listed below:
Pin
1
2
3
4

Symbol
Vss
Vcc
VEE
RS

I/O
I

R/W

6
7-14

E
DB0-DB7

I/O
I/O

Description
Ground
+5V Supply
Controls contrast
RS=0: Command Register
RS=1: Data Register
R/W=0:
Write
R/W=1: Read
Enable
The 8-Bit Data bus

THEORY:
. LCD is fast replacing LED for displaying data as it can display not only numbers unlike LED but can also print out
Alphabets and other characters using their ASCII values. Moreover, with the decrease in their prices, there is no
moving back for LCDs. An LCD has 2 registers of importance; Data Register and Instruction command register. The
RS pin select is used to differentiate between command signal and data signal according to the configuration
discussed in Datasheet. R/W pin is used to either write or read the LCD. Enable pin is used to latch the data present
at the data pins of the LCD chip. When data is supplied, the enable pin must undergo a high to low transition to latch
the data.

1 | Page

There are 8 I/O data pins to send and receive information to and from the LCD. RS pin along with R/W pin is used
to monitor the Busy flag. When RS=0 along with R/W=1 and if Busy flag status is 1, the LCD wont accept any new
information and would carry on its own internal functions.
PROCEDURE:

The LCD and microcontroller were connected according to Fig 1. They were then connected to the Virtual

Terminal.
The program was written in Keil and was embedded in the microcontroller.
Port 1 of the microcontroller was assigned the pins like Enable, RS and R/W to perform specific functions

on the LCD.
Port 2 of the microcontroller was connected to the data bus of the LCD for either information or data

transfer between the two.


Different data inputs were written on to the LCD like Data, Instruction, Numbers and Alphabets and were
successfully tested.

PROGRAM CODE:
ENABLE

BIT P1.1

// Pin P1.1 connected to Enable of LCD

RS

BIT P1.0

// Pin P1.0 connected to Enable of LCD

DATAPORT EQU P2

// Port 2 connected as Data Port of LCD

ORG 000
MAIN:
ACALL DELAY

// Call Delay

ACALL SETUP_SERIAL

// Initialize UART at 9600

MOV DPTR,#INIT_TEXT
ACALL SEND_LINE

// send string to Serial terminal

ACALL INIT_LCD

// initialize LCD

MOV DPTR,#MY_TEXT
AGAIN_PRINT:

// Print to LCD

CLR A
MOVC A,@A+DPTR
ACALL SEND_DATA
INC DPTR
JNZ AGAIN_PRINT

2 | Page

//Send character to LCD

MOV DPTR,#DONE_TEXT
ACALL SEND_LINE

//Send string to serial terminal

//MOV A,#"J"
//ACALL SEND_CHAR
HERE:ACALL RCV_CHAR
CJNE A,#27,NEXT

// ASCII ESCAPE=27 DECIMAL

ACALL CLR_LCD

//Clear the LCD

SJMP HERE
NEXT:ACALL SEND_DATA
SJMP HERE
WAIT:SJMP WAIT
CLR_LCD:
MOV A,#01H
ACALL SEND_CMD

//Send command to the LCD

RET
INIT_LCD:
MOV A,#38H

//Initialization function of LCD


// INIT 2 LINES

ACALL SEND_CMD
MOV A,#0EH

// DISPLAY ON & CURSOR ON

ACALL SEND_CMD
MOV A,#01H

//CLEAR LCD

ACALL SEND_CMD
MOV A,#06H

//SHIFT CURSOR RIGHT

ACALL SEND_CMD
MOV A,#80H

// CURSOR AT LINE1 POSITION n (80H + n)

ACALL SEND_CMD
RET
SEND_CMD:
MOV DATAPORT,A
CLR RS

3 | Page

//Set as instruction

ACALL ENABLE_R
RET
SEND_DATA:

//Function to write the LCD

MOV DATAPORT,A
SETB RS

//Set as Data

ACALL ENABLE_R
RET
ENABLE_R:
CLR ENABLE
//ACALL DELAY
SETB ENABLE
ACALL DELAY
CLR ENABLE
//ACALL DELAY
RET
DELAY:

//Delay function

MOV R6,1
DEL1:
MOV R7,100
DEL0:DJNZ R7,DEL0
DJNZ R6,DEL1
RET
SETUP_SERIAL:
MOV TMOD,#20H //TIMER1 MODE2(for serial) and TIMER0 MODE2(auto-reload mode for
generating clock of ~10KHz for ADC 0808)

;SET TIMER1 CONFIG.(used for serial comm.)


MOV TH1,#-3

//9600 BAUD

MOV SCON,#50H

//8-bit , 1-stop bit , RECEIVE ENABLED

SETB TR1
CLR RI // clear RI for the 1st reception

4 | Page

RET
RCV_CHAR:

//Function to receive character from the terminal


WAIT2RCV:JNB RI,WAIT2RCV
MOV A,SBUF
CLR RI
RET

SEND_CHAR:
MOV SBUF,A
WAIT2SEND:JNB TI,WAIT2SEND
CLR TI
RET
SEND_LINE:
CLR A
MOVC A,@A+DPTR
ACALL SEND_CHAR
INC

DPTR

JNZ SEND_LINE
RET
MY_TEXT: DB "NIT RKL",0
INIT_TEXT: DB "INITIALIZING....",0
DONE_TEXT: DB "DONE",13,"TYPE YOUR TEXT BELOW :-" ,13,13,0
END

RESULTS:

5 | Page

Figure 1: Connections btw uC and LCD

Figure 2: LCD is successfully written

6 | Page

CONCLUSION:
The LCD was successfully interfaced by using the 8051 microcontroller. Sentences, Numbers and special characters
were tested. Even a few instructions were loaded which worked perfectly.

7 | Page

S-ar putea să vă placă și