PIC16F877A LCD example

This topic shows a simple example for interfacing LCD display (with HD44780 or compliant controller) with PIC16F877A microcontroller using CCS PIC C compiler.
In 4-bit mode there are 7 data lines between the PIC microcontroller and the LCD which are: RS, R/W, E, D4, D5, D6 and D7.
Interface PIC16F877A with LCD circuit:
PIC16F877A LCD example circuit schematic diagram is shown below.
In this example the PIC16F877A microcontroller runs with 8MHz crystal oscillator and it must be supplied with 5V between pins VDD (#11) and VSS (#12).
Interface PIC16F877A with LCD display C code:
The C code below was tested with CCS C compiler version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// Interfacing PIC16F877A with LCD display CCS C code //LCD module connections #define LCD_RS_PIN PIN_C0 #define LCD_RW_PIN PIN_C1 #define LCD_ENABLE_PIN PIN_C2 #define LCD_DATA4 PIN_C3 #define LCD_DATA5 PIN_C4 #define LCD_DATA6 PIN_C5 #define LCD_DATA7 PIN_C6 //End LCD module connections #include <16F877A.h> #use delay(crystal=8000000) #include <lcd.c> char i; void main(){ lcd_init(); // Initialize LCD module while(TRUE){ lcd_putc('f'); lcd_gotoxy(4, 1); // Go to column 4 row 1 lcd_putc("PIC16F877A"); lcd_gotoxy(4, 2); // Go to column 4 row 2 lcd_putc("LCD example"); delay_ms(5000); lcd_putc('f'); // LCD clear lcd_gotoxy(3, 1); // Go to column 3 row 1 lcd_putc("Hello world!"); lcd_gotoxy(2, 2); // Go to column 2 row 2 lcd_putc("Have a nice day"); delay_ms(5000); lcd_putc('f'); // LCD clear lcd_gotoxy(3, 1); // Go to column 3 row 1 lcd_putc("Hello world!"); for(i = 0; i < 200; i++){ lcd_gotoxy(7, 2); // Go to column 7 row 2 printf(lcd_putc,"%3u",i); // Write i with 3 numbers max delay_ms(100);} } } |
Interface PIC16F877A with LCD video: