You have no items in your shopping cart.

Subtotal: 0.00

How to interface LCD with PIC16F877A PIC Evaluation Board

PIC16F/18F Evaluation board

The PIC16F/18F Evaluation 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 Evaluation 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 2x16 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).



Fig. 1 Interfacing LCD to Microcontroller

 

Interfacing LCD with PIC16F877A

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

The PIC16F/18F Evaluation 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

 

 

 

GLCD/LCD

PIC16F/18F

LCD | 128x64 GLCD Selection

CONTROL L LINES

RS

PORTE.0

 

 

 

 

 

R/W

PORTE.1

E

PORTE.2

LCD – DATA LINES

DB0

PORTD.0

DB1

PORTD.1

Connections

DB2

PORTD.2

*Connect PORTD with JP9 (LCD) via FRC Cable

 

*Place a Jumper on BL-SEL (J7) to Enable Backlight

 

*Press RESET Once.

 

*Adjust the POT (CONTRAST) Right or Left until the    

   letters are visible

DB3

PORTD.3

DB4

PORTD.4

DB5

PORTD.5

DB6

PORTD.6

DB7

PORTD.7

Output: The Strings “PIC DEV. BOARD” and "LCD DEMO PROGRAM" will be displayed on LCD.

 



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 must 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 Evaluation board; the LCD is connected with microcontroller PIC16F/18F Evaluation board. When the program is downloading into PIC16F877A in Evaluation Board, the screen should show some text messages.

If you are not reading any text from LCD, then you just check the jumper connections and 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.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible 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.
  • More instructions are available in following Tutorials

User manual for PIC Evaluation Board

Create & Debug a project in Mplab using PIC16F877A