Task III: LCD interfacing using 8051
MicrocontrollerAIM/OBJECTIVE:The objective is to interface an
output device such as an LCD using 8051 microcontroller.EQUIPMENT
REQUIRED: One LCD: LM016L One uC: AT89C51SOFTWARE 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, VEE is used for controlling
the contrast. The pin description as listed
below:PinSymbolI/ODescription
1Vss-Ground
2Vcc-+5V Supply
3VEE-Controls contrast
4RSIRS=0: Command RegisterRS=1: Data Register
5R/WIR/W=0: WriteR/W=1: Read
6EI/OEnable
7-14DB0-DB7I/OThe 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. 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:ENABLEBIT P1.1// Pin P1.1 connected to Enable
of LCDRSBIT P1.0// Pin P1.0 connected to Enable of LCD
DATAPORT EQU P2// Port 2 connected as Data Port of LCD ORG
000MAIN:ACALL DELAY// Call DelayACALL SETUP_SERIAL// Initialize
UART at 9600MOV DPTR,#INIT_TEXTACALL SEND_LINE// send string to
Serial terminalACALL INIT_LCD// initialize LCDMOV
DPTR,#MY_TEXTAGAIN_PRINT:// Print to LCDCLR AMOVC A,@A+DPTRACALL
SEND_DATA//Send character to LCDINC DPTRJNZ AGAIN_PRINTMOV
DPTR,#DONE_TEXTACALL SEND_LINE//Send string to serial terminal//MOV
A,#"J"//ACALL SEND_CHAR HERE:ACALL RCV_CHARCJNE A,#27,NEXT// ASCII
ESCAPE=27 DECIMALACALL CLR_LCD//Clear the LCDSJMP HERENEXT:ACALL
SEND_DATASJMP HEREWAIT:SJMP WAITCLR_LCD:MOV A,#01HACALL
SEND_CMD//Send command to the LCDRETINIT_LCD://Initialization
function of LCDMOV A,#38H// INIT 2 LINESACALL SEND_CMDMOV A,#0EH//
DISPLAY ON & CURSOR ONACALL SEND_CMDMOV A,#01H//CLEAR LCDACALL
SEND_CMDMOV A,#06H//SHIFT CURSOR RIGHTACALL SEND_CMDMOV A,#80H//
CURSOR AT LINE1 POSITION n (80H + n)ACALL SEND_CMDRETSEND_CMD:MOV
DATAPORT,ACLR RS//Set as instructionACALL
ENABLE_RRETSEND_DATA://Function to write the LCDMOV DATAPORT,ASETB
RS//Set as DataACALL ENABLE_RRETENABLE_R:CLR ENABLE//ACALL
DELAYSETB ENABLEACALL DELAYCLR ENABLE//ACALL DELAYRETDELAY://Delay
functionMOV R6,1DEL1:MOV R7,100DEL0:DJNZ R7,DEL0DJNZ
R6,DEL1RETSETUP_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 BAUDMOV SCON,#50H//8-bit , 1-stop bit , RECEIVE
ENABLEDSETB TR1CLR RI // clear RI for the 1st
receptionRETRCV_CHAR://Function to receive character from the
terminalWAIT2RCV:JNB RI,WAIT2RCVMOV A,SBUFCLR RIRETSEND_CHAR:MOV
SBUF,AWAIT2SEND:JNB TI,WAIT2SENDCLR TIRETSEND_LINE:CLR AMOVC
A,@A+DPTRACALL SEND_CHARINCDPTRJNZ SEND_LINERETMY_TEXT: DB "NIT
RKL",0INIT_TEXT: DB "INITIALIZING....",0DONE_TEXT: DB
"DONE",13,"TYPE YOUR TEXT BELOW :-" ,13,13,0END
RESULTS:
Figure 1: Connections btw uC and LCD
Figure 2: LCD is successfully written
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