You are currently viewing How to Interface LCD with PIC16F877A PIC Development Board

How to Interface LCD with PIC16F877A PIC Development Board

Spread the love

The PIC16F/18F Development Board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s PIC (PIC16F877A), PIC16F/18F Development Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

LCD (Liquid Crystal Display)

Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. A liquid crystal display (LCD) is a flat panel display that uses the light modulating properties of liquid crystals (LCs). LCD Modules can present textual information to user.

Interfacing LCD

Fig. 1 shows how to interface the LCD to microcontroller. The 2×16 character LCD interface card with supports both modes 4-bit and 8-bit interface, and also facility to adjust contrast through trim pot. In 8-bit interface 11 lines needed to create 8-bit interface; 8 data bits (D0 – D7), three control lines, address bit (RS), read/write bit (R/W) and control signal (E).

Interfacing LCD with PIC16F877A PIC Development Board

Fig. 1 Interfacing LCD to Microcontroller

Interfacing LCD with PIC16F877A

We now want to display a text in PIC16F/18F Development Board by using LCD module. In PIC16F/18F Development Board contains the LCD connections in a single header.

The PIC16F/18F Development Board has eleven numbers of LCD connections, connected with I/O Port lines (PORTE.0 – PORTE.3 && PORTD.0 – PORTD.7) to make LCD display.

Pin Assignment with PIC16F877A

Circuit Diagram to Interface LCD with PIC16F877A

Source Code

The Interfacing LCD with PIC16F877A program is very simple and straight forward, which display a text in 2 X 16 LCD modules. Some delay is occurring when a single command / data is executed.

C Program to display a text in LCD using PIC16F877A

#include
//Define PIC Registers
#include
//Define I/O Functions __CONFIG(0x3f72);
//Select HS oscillator, Enable (PWRTE,BOREN),
//Disable (CPD,CP,WDTEN,In-circuit Debugger)
#define RS RE0
//LCD Register Select
#define RW RE1
//LCD Read/Write Pin
#define EN RE2
//LCD Enable Pin
#define DATA PORTD
//LCD Data Port
#define DATADIR TRISD
//LCD Data Port Direction Register
#define CNTRLDIR TRISE //RS,RW,EN Direction Register void lcdinit(void);
//LCD initialization Function void lcdclr(void);
//LCD Clear Function void lcdcomd(unsigned char);
//LCD Command Declaring Fucntion void lcddata(unsigned char);
//LCD Data Display Fucntion void DelayMs(unsigned int);
void main()
{
int i;
unsigned char First[]={" PIC DEV. BOARD "};
unsigned char Secnd[]={"LCD DEMO PROGRAM"};
DelayMs(500);
lcdinit();
DelayMs(500);
while(1)
{
lcdclr();
lcdcomd(0x80);
for(i=0;i<16;i++)
//Display the Message
{
lcddata(First[i]);
DelayMs(50);
}
lcdcomd(0xc0);
for(i=0;i<16;i++)
//Display the Message
{
lcddata(Secnd[i]);
DelayMs(50);
}
DelayMs(500);
}
}
void lcdinit(void)
{
int i;
unsigned char command[]={0x38,0x0c,0x06,0x01};
//LCD Command set for 8 bit Interface, 2 Lines, 5x7 Dots ADCON1 = 0x07;
//Make PORTE Pin as Digital CNTRLDIR = 0x00;
//Make LCD control port (PORTE) as output DATADIR = 0x00; DelayMs(50);
//Make LCD Data Port (PORTD) as output port for(i=0;i<4;i++)
{
lcdcomd(command[i]);
//Send the Initialisation Commands DelayMs(5);
}
DelayMs(500);
}
void lcdclr(void)
//Send LCD clear command
{
lcdcomd(0x01);
DelayMs(2);
}
void lcdcomd(unsigned char cmd)
{
RS=0;
RW=0;
//Select Command Register, R/W--write enabled EN=1;
//Enable LCD to accept commands DATA=cmd;
EN=0; DelayMs(5);
//Give a Pulse via Enable pin
}
void lcddata(unsigned char byte)
{
RS=1;
RW=0;
//Select Data register, R/W--write enabled EN=1;
DATA=byte;
//Give a Pulse via Enable pin EN=0;
DelayMs(5);
}
void DelayMs(unsigned int Ms)
{
int delay_cnst;
while(Ms>0)
{
Ms--;
for(delay_cnst = 0;
delay_cnst <220;delay_cnst++);
}
}

To compile the above C code you need the Mplab software & Hi-Tech C Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without microcontroller Board.

The PICKIT2 software is used to download the hex file into your microcontroller through USB port.

Testing the LCD Module with PIC16F877A

Give +12V power supply to PIC16F/18F Development Board; the LCD is connected with microcontroller PIC16F/18F Development Board. When the program is downloading into PIC16F877A in Development Board, the screen should show the text messages.

If you are not reading any text from LCD, then you just check the jumper connections & adjust the trim pot level. Otherwise you just check it with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link.

How to create & Debug a Project in Mplab using PIC16F using Hi-Tech Compiler.

General Information

☞For proper working use the components of exact values as shown in Circuit file. Use new components.

☞Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.

☞Use the exact value crystal shown in schematic

This Post Has One Comment

  1. budi

    i’m very happy reading your tutorial …good and next turial with advance

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.