LCD Interfacing PIC16F877a

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

10.

Program For Interfacing Of LCD Display System

OBJECTIVE : To interface 16x2 LCD with 16f677a PIC microcontroller.

REQUIREMENTS : MPLAB X IDE ,PICSIM LAB , Proteus Software.

THEORY :
LCD Stands for Liquid Crystal Display. It has ability to display numbers and
characters. LCDs comes in different sizes and shapes. For this project, we have selected a
16×2 character, alphanumeric LCD. It contains 2 rows of 16 character.

LCD pin description:-

The LCD display has 14 pins. the function of each pin is given in table no.1
Table 1

Pin Symbol I/O Description


1 Vss -- Ground
2 Vcc -- +5V power supply
3 VEE -- Power supply to control contrast
4 RS I RS=0 to select command register,
RS=1 to select data register
5 R/W I R/W=0 for write,
R/W=1 for read
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
Table 2: LCD Command Codes

Code(Hex) Command to LCD Instruction Register


1 Clear display screen
2 Return home
3 Decrement cursor (shift cursor to left)
4 Increment cursor (shift cursor to right)
5 Shift display right
6 Shift display left
7 Display off, cursor off
8 Display off, cursor on
A Display on, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning of 1st line
C0 Force cursor to beginning of 2nd line
38 2 lines and 5x7 matrix
Steps :

One must configure the data bus 4-bit or 8-bit.

Clear the LCD module.

RS line must be low while sending any command.

To turn on LCD module and the cursor.

To clear the LCD screen, then command is “clear screen”.

To set cursor position at any desired position, then command is “set cursor position”.

For writing the data, set lines EN and RS.

Setting Rs to 1will tell that the data being sent is a text data. The data is loaded on the
data bus

and enline is cleared to display the text.

EN line is must go from high to low for the execution of the LCD operation.
PROGRAM :
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS
oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT
disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT
disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR
disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-
Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on
MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code
Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write
Enable bits (Write protection off; all program memory may be
written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code
Protection bit (Code protection off)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#define en PORTEbits.RE1 //ENABLE BIT FOR LCD
#define rs PORTEbits.RE2 //REGISTER SELECT BIT FOR LCD
#define ldata PORTD //PORT FROM DATA TO BE SEND TO LCD
void delay(unsigned int);

void lcdcmd(unsigned char value)


{
ldata=value;
rs=0; //SELECT COMMAND REGISTER
en=1; //SEND HIGH PULSE TO LCD
delay(10); //CALL DELAY
en=0; // SEND LOW PULSE TO LCD
}
void lcddata(unsigned char value)
{
ldata=value;
rs=1; //SELECT DATA REGISTER
en=1; //SEND HIGH PUSE TO LCD
delay(10); //CALL DELAY
en=0; //SEND LOW PULSE TO LCD
}
void main()
{
TRISD=0; //CONFIGURE PORTD AS OUTPUT
TRISE=0; //CONFIGURE PORTE AS OUTPUT
//CONFIGURE PORTC AS OUTPUT
delay(10);
lcdcmd(0x38); //CONFIGURE 16X2 LCD DISPLAY
delay(10);
lcdcmd(0x0E); //DISPLAY ON ,CURSOR ON
delay(10);
lcdcmd(0x01); //CLEAR DISPLAY
delay(10);
lcdcmd(0x06); //ENTRY MODE
delay(10);
lcdcmd(0x84); //SELECT 4TH POSITION ON FIRST LINE OF 16X2
DISPLAY
delay(10);
lcddata('W'); //SEND CHAR 'W'
delay(10);
lcddata('I'); //SEND CHAR 'I'
delay(10);
lcddata('T'); //SEND CHAR 'T'
delay(10);
}

//DELAY SUBROUTINE
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
CONCLUSION :
From this experiment we concluded that , programmed LED’s are vastly used for
industrial as well as commercial applications.

QUESTION :
Q. What is use of busy flag in LCD?

We use RS=0 to read the busy flag bit to see if the LCD is ready to receive information.
The busy flag is D7, and can be read when R/W=1 and RS=0,as follows: if R/W=1,RS=0.
When D7=1,the LED is busy taking care of internal operations and will not accept any new
information .When D7=0, the LCD is ready to receive new information.

You might also like