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

Table of Contents

Title ............................................................................................................................................................... 2

Objective ....................................................................................................................................................... 2

Introduction .................................................................................................................................................. 2

Materials Used .............................................................................................................................................. 5

Project Code .................................................................................................................................................. 5

Result: ........................................................................................................................................................... 7

1
Title: LCD Interfacing with PIC16F877A to display “G4 COMPUTER ENGINEERING”

Objective:
- To learn LCD Interfacing with PIC16F877A

-To understand about LCD interfacing

-To know how to interrupt in PIC16F877A

Introduction
We always use devices made up of Liquid Crystal Displays (LCDs) like computers, digital
watches and also DVD and CD players. They have become very common and have taken a giant
leap in the screen industry by clearly replacing the use of Cathode Ray Tubes (CRT). CRT draws
more power than LCD and are also bigger and heavier. All of us have seen a LCD, but no one
knows the exact working of it. Let us take a look at the working of a LCD.

Here we are using alphanumeric LCD 16×2. A 16×2 LCD display is very basic module and is
very commonly used in various devices and circuits. These modules are preferred over seven
segments and other multi segment LEDs. The reasons being: LCDs are economical; easily
programmable; have no limitation of displaying special & even custom characters (unlike in
seven segments), animations and so on.

A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD
each character is displayed in 5×7 pixel matrix. This LCD has two registers, namely, Command
and Data. The command register stores the command instructions given to the LCD. A command
is an instruction given to LCD to do a predefined task like initializing it, clearing its screen,
setting the cursor position, controlling display etc. The data register stores the data to be
displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

2
Pin Diagram

LCD COMMANDS:

3
Pin Description:

The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for the data
bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus.
If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4
lines for the data bus). If an 8-bit data bus is used the LCD will require a total of 11 data lines (3
control lines plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.

The EN line is called “Enable.” This control line is used to tell the LCD that you are sending it
data. To send data to the LCD, your program should make sure this line is low (0) and then set
the other two control lines and/or put data on the data bus. When the other lines are completely
4
ready, bring ENhigh (1) and wait for the minimum amount of time required by the LCD
datasheet (this varies from LCD to LCD), and end by bringing it low (0) again.

The RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1),
the data being sent is text data which should be displayed on the screen. For example, to display
the letter “T” on the screen you would set RS high.

The RW line is the “Read/Write” control line. When RW is low (0), the information on the data
bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction (“Get LCD status”) is a read command. All others are
write commands–so RW will almost always be low.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the
user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4,
DB5, DB6, and DB7.

Connections:

RS – Port C .0 (RC0)

RW – Port C.1 (RC1)

EN – Port C.2 (RC2)

Data lines – Port B

Materials Used
-PIC16F877A

-LCD

Project Code:
/*EMBADDED GROUP PROJECT*/

#define rs PORTC.RC0
#define rw PORTC.RC1

5
#define en PORTC.RC2
#define delay for(i=0;i<1000;i++)
#define _XTAL_FREQ 20000000
int i;

void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);

void main()
{
unsigned int i;
TRISB=0x00;
TRISC0_bit=0x00;
TRISC1_bit=0x00;
TRISC2_bit=0x00;
lcd_init();
cmd(0x90);
show("G4 COMPUTER ENGINEERING");
while(1) {
for(i=0;i<15000;i++);
cmd(0x18);
for(i=0;i<15000;i++);

}
}

void lcd_init()
{
cmd(0x38);
cmd(0x0c);
cmd(0x06);
cmd(0x80);
}

void cmd(unsigned char a)


{
PORTB=a;
rs=0x00;
rw=0x00;
en=0xff;
delay;
en=0x00;
}

void dat(unsigned char b)


{
PORTB=b;

6
rs=0xff;
rw=0x00;
en=0xff;
delay;
en=0x00;
}

void show(unsigned char *s)


{
while(*s) {
dat(*s++);
}
}

Result:

You might also like