lcdinterfacing

Interfacing LCD to PIC16F877A

TELL A FRIEND
  
PIC16F877A is used here to display message on the Hitachi HD44780-based character LCD module. PIC16F877A is 8-bit microcontroller based on reduced instruction set computer (RISC) architecture. It has 8kx14-bits flash program memory, 368 bytes of RAM. Here PIC16F877A microcontroller is connected to HD44780 LCD in 4-bit interface data, only four bus lines (DB4 to DB7) are used for data transfer. Bus lines DB0 to DB3 are having no connection with microcontroller. The data transfer between the HD44780U and the PIC16F877A is completed after the 4-bit data has been transferred twice. 
 

As for the order of data transfer, the four high order bits (for 8-bit operation, DB4 to DB7) are transferred before the four low order bits (for 8-bit operation, DB0 to DB3).

Any character on HD44780 LCD is displayed by sending its respective ASCII code. Hence to display 1 on LCD microcontroller has to send 31h as data.

When RS pin =0 instruction register is selected and information on data bus is taken as commands. The IR stores instruction codes, such as display clear and cursor shift, and address information for display data RAM (DDRAM) and character generator RAM (CGRAM). The IR can only be written from the PIC16F877A.

When RS pin=1 data register is selected and information on data bus is taken as ASCII value of respective character to be displayed on HD44780 LCD. The DR temporarily stores data to be written into DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. When address information is written into the IR, data is written and then stored into the DR from DDRAM or CGRAM by an internal operation

RW pin is used to either read from LCD (RW=1) or write to LCD (RW=0). When a High to Low pulse is applied on the Enable pin the information present on the data bus is latched into the LCD register.

Addresses of cursor position for 16x2 HD44780 LCD

line1  80H  81H  82H  83H  84H  85H  86H  87H  88H  89H  8AH  8BH  8CH  8DH  8EH  8FH 
line2  C0H  C1H  C2H  C3H  C4H  C5H  C6H  C7H  C8H  C9H  CAH  CBH  CCH  CDH  CEH  CFH 

PIC16F877A microcontroller connection with HD44780 LCD

PORTD bits 0-3 are connected to the LCD data bits 4-7 (high nibble) of LCD

PORTA bit 3 is connected to the LCD RS input (register select)

PORTA bit 2 is connected to the LCD RW bit

PORTA bit 1 is connected to the LCD EN bit (enable)

Crystal used is 4MHz

Set up the PORTA and PORTD as I/O (TRISA, TRISD)

Ciruit Diargram :PIC16F877A connected to LCD

C code for programming PIC16F877A to interface LCD

void lcd_init(char c) Initialise LCD in 4-bit mode

RS=0 command mode RW=0 lcd in write mode

wait 15mSec after power is applied

send 0x3 and High to low pulse at Enable pin

wait 5mSec and High to low pulse at Enable pin

wait 200uSec and High to low pulse at Enable pin

wait 200uSec

send 0x2 Four bit mode and High to low pulse at Enable pin

send 0x28 Set interface length

send 0xf Display On, Cursor On, Cursor Blink

send 0x1 Clear screen

Send 0x6 Set entry Mode

void lcd_write(unsigned char c) write a byte to the LCD in 4 bit mode

send higher nibble of data byte

High to low pulse at Enable pin

Send lower nibble of data byte

High to low pulse at Enable pin

void lcd_character(char c) write one character to the LCD using

wait for 40 usecond

Set RS =1 to send ASCII code of character to LCD

Call lcd_write function

PIC16f877_LCD.c

#include<pic.h>

#include "delay.h"

#include "lcd.h"

void main()

{

TRISD=0X00;

PORTD=0;

lcd_init(); //LCD initialized

lcd_line1(0); //LCD address specified AT LINE 1

lcd_string("INTERFACING LCD"); //Displays message "LCD INTERFACING"

lcd_line2(0); //LCD address specified AT LINE 2

lcd_string(" PIC 16F877A");//Displays message " PIC 16F877A"

while(1);

}

study projects files given below for more details on Interfacing LCD to PIC16F877A microcontroller

Output on LCD using PIC16F877A microcontroller

Project files: pic16f877a_lcd.rar

Acceptance of ignorance is true path of knowledge -Pujya Dadashri

© 2010 LCD Interfacing.