Sunday, 19 July 2015

Lesson 5 LCD Interfacing With PIC 16F877A (MikroC)

LCD Interfacing With PIC 16F877A (MikroC)

Liquid Crystal Display(LCD) is used for displaying messages. In this tutorial we are using 2x16  LCD. It has 2 lines and 40 characters per line. Only the first 16 characters of each line are visible. The LCD  has 14 pins plus 2 additional pins for its backlight.

 
2x16 LCD


  • Vss is the ground pin (0V)
  • Vdd is the power supply (5v)
  • Vee is LCD contrast (0-5V)
  • RS is Register Select
  • R/W is Read/Write pin (allows data to be written to or read from an LCD)
  • E is Enable pin (enables/disable access to LCD)
  • D0 - D7 are data lines 

LCD CONNECTION

It can be connected in two ways :
  • 8 bit Mode
  • 4 bit Mode
In 8 bit mode all the data lines D0 - D7 transfer data (it doesn't save MCU I/O pin).
4 bit mode uses only upper 4 bits (D4 - D7) and the lower data lines are left unconnected. Thus saving MCU I/O pins.
Vee is normally connected to a potentiometer to vary LCD contrast.
R/W is connected to the ground since data is rarely read from the LCD.

MikroC has LCD library functions which makes writing the code very easy. You can check out the library functions and how to use them from MikroC help files. Search for LCD library

**   Ensure to check LCD in the library manager to avoid errors when compiling.
*** For the LCD backlight pins, a limiting resistor should be connected to one of the pins during operation.

MikroC Code;

/**********************************
Project Name :
   LCD Display
Author : Promise
Description :
   This project displays text on the LCD
Test configuration:
   MCU:  PIC 16F877A
   Oscillator: XT 8.0000 MHz, 8.0000 MHz Crystal
***********************************/

// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
// End LCD module connections


char txt[]= "WELCOME TO OUR " ;
char txt1[]="BLOG!!!";
void main() {
   Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  
while(1){                            //endless loop
Lcd_Out(1,1,txt);                   // Output txt
Lcd_Out(2,6,txt1);                  // outut txt1
}

}
Proteus Schematic:

LCD in 4 bits mode




No comments:

Post a Comment