04 May 2012

16x2 LCD with 16F877A


In this exercise lets look at how can we interface a LCD display with 16F877A PIC microcontroller


The mikroC PRO for PIC provides a library for communication with LCDs (with HD44780 compliant controllers) through the 4-bit interface. 


HD44780 Pinout

  1. Vss (Ground)
  2. VCC (5V)
  3. Contrast (use a potentiometer for variable contrast, or just connect to GND)
  4. Register Select (RS), 0 = command write, 1 = data write
  5. Read/Write (R/W), 0 = write to display, 1 = read from display
  6. Enable (EN) - used to clock in data
  7. DB0 (not used in 4-bit mode) - LSb
  8. DB1 (not used in 4-bit mode)
  9. DB2 (not used in 4-bit mode)
  10. DB3 (not used in 4-bit mode)
  11. DB4 - LSb in 4-bit mode
  12. DB5
  13. DB6
  14. DB7 - MSb
  15. Backlight + (5V)
  16. Backlight - (GND)


4-bit and 8-bit modes


An HD44780 LCD can be operated in two different modes: 4-bit mode and 8-bit mode. In 8-bit mode, pins 7-14 of the LCD are connected to eight I/O pins on the microcontroller; while in 4-bit mode, pins 11-14 on the LCD are connected to four I/O pins on the microcontroller. The advantage to operating in 8-bit mode is that the programming is a bit simpler and data can be updated more quickly. The obvious reason to operate in 4-bit mode is to save four I/O pins on the PIC microcontroller.

Circuit Diagram for 16x2 LCD


Complete Circuit Diagram with PIC Microcontroller

MikroC Code:


// 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


void main() {


  int i=0;
  char text[]="16x2 LCD Disply";


  ADCON1=0x06; // Configure all input and output in to digital
  Lcd_init();  // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off


  do{
     Lcd_Out(1,1,"   Electronic   ");  //Write text on raw 1, column 1
     Lcd_Out(2,1,"   Work Space   ");  //Write text on raw 1, column 1
     Delay_ms(1000);  // Delay 1 second
     Lcd_Cmd(_LCD_CLEAR);               // Clear display
 
     for(i=0;i<16;i++){
       Lcd_Chr(1,i+1,text[i]);            //Display charactor by charactor
       Delay_ms(500);
     }
   }while(1); // continue  infinite loop
}

1 comments:

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;