Vous êtes sur la page 1sur 7

Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 42

Write a program for interfacing the 16x2 LCD MODULES

Aim:
Write a program for interfacing the 16x2 lcd module

Hardware requirements:-
1. UTS-MS-KIT-M7.
2. A serial cable,9 pin cable wired one to one from female connector to male
connector.
3. PC with serial port.
4. 5V adopter.

Software requirements:-
1. UTS EDS or Kiel evaluation software.

2. Flash Magic.

Experimental procedure:

1. Open the KEIL IDE and create a new microvision project from Project menu and
save it in a folder.
2. Goto File menu and create a new document, write C code in that document, save
it in above created folder and add it to source group1 which is in target folder.
3. Goto Flash menu and click on configure flash tools.
- Click on output menu
i. Select create hex file option
ii. Set oscillator frequency = 11.0592MHz
4. Goto Project -> build target, then Hex file will be created.
5. Open Flash magic to download into the micro controller.

Settings:
COM Port : COM1
Baud Rate : 9600
Device : 89V51RD2
Interface : None (ISP)

Embedded Systems Design Lab Dept of ECE


MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 43

Oscillator Frequency (MHz) : 11.0592


Tick Erase All Flash + Security + Clks
Tick verify after programming
Now go to Option -> Advanced options -> Hardware Configuration and
uncheck “Use DTR to control Reset”.
6. Browse the Hex file, which is to be downloaded into the micro controller.
7. Turn on the Board Power, Connect the serial port to board from computer.
8. Press and hold the reset button on board and click on start button on flash magic.
Wait until a small window comes with message “Reset the device into ISP
mode”. Once this window comes release the reset button.
9. If we get finished message in the flash magic then we have to press reset button
once to enter in to run mode.

Theory:-

LCDs can add a lot to your application in terms of providing an useful interface
for the user, debugging an application or just it a “professional” look. LCDs can be added
quite easily to an application and use as few as three digital output pins for contr The
most common connector used for the LCDs is 16pins in a row.
• In the Kit 8 bit mode is configured.
• R/S is controlled by P3_5 of the microcontroller.
• R/W is permanently grounded to make it in always write mode to LCD.
• Data Bus are connected to microcontroller Buffered Data Bus.

Embedded Systems Design Lab Dept of ECE


MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 44

Internal Block Diagram of the LCD is shown in figure


The interface is a parallel bus, allowing simple and fast writing of data to the
LCD. This waveform will write an ASCII Byte out to the LCD's screen. The ASCII code
to be displayed is eight bits long and is sent to the LCD either four or eight bits at a time.
If four bit mode is used, two "nibbles" of data (Sent high four bits and then low four bits
with an "E" Clock pulse with each nibble) are sent to make up a full eight bit transfer.
The "E" Clock is used to initiate the data transfer within the LCD. Sending parallel data
as either four or eight bits are the two primary modes of operation.

While there are secondary considerations and modes, deciding how to send the
data to the LCD is most critical decision to be made for an LCD interface application.
Eight bit mode is best used when speed is required in an application and at least ten I/O
pins are available. Four bit mode requires a minimum of six bits. To wire a
microcontroller to an LCD in four bit mode, just the top four bits (DB4- 7) are written to.
The "R/S" bit is used to select whether data or an instruction is being transferred between
the microcontroller and the LCD. If the Bit is set, then the byte at the current LCD
"Cursor" Position can be read or written. When the Bit is reset, either an instruction is
being sent to the LCD or the execution status of the last instruction is read back (whether
or not it has completed).

C SOURCE CODE

#include <reg51.h> /* define 89C52 registers */

//MEMORY MAPPING

#define Cs82551BaseAdress 0x8000


#define CsLCD 0xB000
#define Cs82551Control Cs82551BaseAdress+0x03
#define Cs82552Control Cs82552BaseAdress+0x03

//FUNCTION PROTOTYPE DECLARATION

void ClrLcd(void);
void Delay(unsigned int duration);
void configlcd(void);
void lcdcommand(unsigned char value);
void lcddata(unsigned char value);
void putchar(unsigned char row,unsigned char col,unsigned char t);
void putstring(unsigned char row,unsigned char col,unsigned char *string);
void lineclear(unsigned char line);
void lineclear(unsigned char line);

Embedded Systems Design Lab Dept of ECE


MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 45

//MAKING PORT3 5TH PIN AS AN RS PIN FOR THE LCD

sbit rs =P3^5;

//GLOBAL VARIABLES DECLARATION

unsigned char xdata *ptr;


unsigned char xdata *lcd_pointer = 0xB000;
unsigned char *mes;

//MAIN PROGRAM STARTS HERE

void main (void)


{ /* main program */

// 8255 intialization
Delay(50);
ptr = Cs82551Control;
*ptr = 0x82;

// LCD intialization
ClrLcd();
configLcd();
Delay(15);
rs=1;

mes="WELCOME TO DEMO";

ptr = CsLCD;
ClrLcd();
while(1)
{
putstring(1,0,mes);
putstring(2,0,mes);
lineclear(1);
lineclear(2);
}

while(1);
}

//FUNCTIONS

//DELAY FUNCTION
Embedded Systems Design Lab Dept of ECE
MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 46

void Delay(unsigned int duration)


{
unsigned int r1,r2;
for (r2 = 0; r2<= duration;r2++)
{
for (r1 = 0; r1<= 2000;r1++);
}
}

//LCD INSTRUCTIONS CAN BE GIVEN THROUGH THIS FUNCTION

void lcdcommand(unsigned char value)


{
rs=0;
Delay(15);
*lcd_pointer = value;
}
//LCD DATA CAN BE GIVEN THROUGH THIS FUNCTION

void lcddata(unsigned char value)


{

rs=1;
Delay(15);
*lcd_pointer = value;
}

//Function For Giving Single Character To The Exact Position Of The Lcd

void putchar(unsigned char row,unsigned char col,unsigned char t)


{
switch(row)
{
case 1:row=0x80;
break;
case 2:row=0xc0;
break;
}

lcdcommand(row+col);
lcddata(t);
}

//FUNCTION FOR PASSING STRING TO THE EXACT LINE OF THE LCD


Embedded Systems Design Lab Dept of ECE
MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 47

void putstring(unsigned char row,unsigned char col,unsigned char *string)


{
switch(row)
{
case 1:row=0x80;
break;
case 2:row=0xc0;
break;
}
lcdcommand(row+col);
while(*string)
{
lcddata(*string++);
}
}

//FUNCTION FOR CLEARING THE LCD

void ClrLcd(void)
{
rs=0;

*lcd_pointer = 0x01;
Delay(15);

rs=1;
}

//FUNCTION FOR CONFIGURATION OF THE LCD

void configLcd (void)


{
rs=0;

*lcd_pointer = 0x38; /*for 162 display funnction set*/


Delay(2);
*lcd_pointer = 0x38; /*for 162 display funnction set*/
Delay(2);
*lcd_pointer = 0x0c; /* display control*/
Delay(2);
*lcd_pointer = 0x0c; /* display control*/
Delay(2);
*lcd_pointer = 0x06; /* entry mode set, no shift, increment address
counter*/
Delay(2);
Embedded Systems Design Lab Dept of ECE
MREC
Exp No: 5 Interfacing 16x2 LCD(8051) Page No : 48

*lcd_pointer = 0x06; /* entry mode set, no shift, increment address


counter*/
Delay(2);

}
//FUNCTION FOR CLEARING THE EXACT LINE IN THE LCD

void lineclear(unsigned char line)


{
unsigned char l,row;

switch(line)
{
case 1:row=0x80;
break;
case 2:row=0xc0;
break;
}

for(l=0;l<16;l++)
{
lcdcommand(row+l);
lcddata(' ');
}
}

Results/Discussion:

After programming the code into the microcontroller just reset the
microcontroller and put it in the run mode. We can observe display on the LCD.

Embedded Systems Design Lab Dept of ECE


MREC

Vous aimerez peut-être aussi