Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Interfacing PIC16F877A with LCD

Interfacing PIC16F877A with LCD

Fig: Liquid crystal display 

Interfacing PIC16F877A with LCD


In this tutorial i will take you through the process of interfacing PIC16F877A  with a Liquid crystal display (LCD). If you haven't gone through my previous post on Reading a Switch with PIC16F877A and you love to do so, click here .

 LCDs are alphanumeric or graphical displays and they are widely used in microcontroller based applications. In resent years, LCDs are replacing LEDs and Seven segment displays due to:
  • Declining price of LCDs
  • Ease to programming for characters and graphics
  • Ability to display numbers, characters and graphics unlike LEDs which can display only numbers and a few characters. 
LCDs comes in different sizes some can display up to forty (40) characters with up to four (4) lines       ( rows and columns) with each character consisting of a 5x8 or 5x11 dot matrix.
In this tutorial we will focus on the 16x2 Hitachi HD44780 LCD (i.e. 16 characters (columns) and two lines(rows) ).

We have :
  • Serial LCDs
  • Parallel LCDs
Serial LCDs are connected to the microcontroller using one data line and the data is transferred using the RS232 serial communication protocol. The serial LCDs are easy to use but more expensive than the parallel LCDs. In this article we will concentrate on the parallel LCDs 

LCD Pin Description:

  1. VSS       -----------  Ground pin
  2. VCC      ----------- +5V power supply
  3. VEE      -----------  power supply to control contrast
  4. RS         -----------  RS = 0 to select command register, RS = 1 to select data register.
  5. R/W      -----------  R/W = 0 for write, R/W = 1 to read.
  6. E           -----------  Enable pin
  7. DB0      ----------    8 bit data bus
  8. DB1     ----------    8 bit data bus
  9. DB2      ----------    8 bit data bus
  10. DB3     ----------    8 bit data bus
  11. DB4      ----------    8 bit data bus
  12. DB5      ----------    8 bit data bus
  13. DB6      ----------    8 bit data bus
  14. DB7      ----------    8 bit data bus

If RS = 0, the instruction "command" code register is selected and the user can send a command such as " clear display, cursor at home etc."
If  RS = 1, the "data" register is selected and the user can send a data to be displayed on the LCD screen.

Writing to the LCD at low level is not too easy but MikroC Pro for PIC Compiler has a good number of built-in functions that makes it very easy to interface the LCD with PIC16F877A.

MikroC has alot of functions that makes it easy to interface a PIC MCU with LCD, check out these funcions and description  here.




Circuit Diagram:



CODE:

/*
    Name     : Interfacing PIC16F877A with LCD
    Author   : Daniel Oluwole
                       (C) 2020 Danitronics
                       danieloluwole51@gmail.com, danieloluwole51@yahoo.com
    Mobile:    +234 8188508765.
   
    Notes    :   Our aim is to turn ON or turn OFF an LED whenever the switch is closed or opened
    Device   : PIC16F877A.
*/
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "DANITRONICS";

char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){

Lcd_Init();                          // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt1);                           // display "DANITRONICS"
 //Lcd_Out(1,6,"DANITRONICS");     // Alternative method to display "DANITRONICS"


  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }
}



NEXT POST:

Post a Comment

0 Comments

Ad Code

Responsive Advertisement