Wednesday, October 14, 2015

Interfacing PIC18F4550 With LCD Display

PIC18F4550 LCD Example
LCD Scrolling
In this topic we are going to interface Microchip PIC18F4550 8-bit microcontroller with 1602 LCD display and we are going to some techniques using MikroC PRO for PIC compiler.
Interfacing of the lcd display with the microcontroller is quite easy we will use 4-bit mode for the lcd to interface with the PIC18F4550, we are going to see how write texts and numbers and how to turn on and off the lcd and also we are going to see how scroll a text displayed on the lcd.
Interfacing PIC18F4550 With LCD Display Cricuit:
The circuit diagram of interfacing PIC18F4550 with 1602 LCD display is shown below:

Interfacing PIC18F4550 With LCD Display Cricuit

Interfacing PIC18F4550 with LCD display MikroC code:
The code can be divided into 4 parts:
1-  The lcd scrolls left at the first row text "PIC18F4550" and text "LCD Example" at the second row,
2-  The lcd shows the text "www.elecnote." at the first row and "" at the second row,
3-  The lcd turns on and off for 4 times the previous two texts,
4-  The lcd displays at the first row the text "Hello world!" and a counting number at the second row.
The internal oscillator of the microcontroller is used and set to 8MHz and the MCLR pin is disabled in order to make our circuit more simple.
The configuration of the MikroC can be accessed using: Project ---> Edit Project and the following configuration should be set:

mikroc lcd hd44780

pic18f4550 mikroc

And Proteus settings for the microcontroller are as follows:

mikroc lcd

Interfacing PIC18F4550 with LCD display mikroC Code:
 // LCD module connections
 sbit LCD_RS at RB5_bit;
 sbit LCD_EN at RB4_bit;
 sbit LCD_D4 at RB3_bit;
 sbit LCD_D5 at RB2_bit;
 sbit LCD_D6 at RB1_bit;
 sbit LCD_D7 at RB0_bit;
 sbit LCD_RS_Direction at TRISB5_bit;
 sbit LCD_EN_Direction at TRISB4_bit;
 sbit LCD_D4_Direction at TRISB3_bit;
 sbit LCD_D5_Direction at TRISB2_bit;
 sbit LCD_D6_Direction at TRISB1_bit;
 sbit LCD_D7_Direction at TRISB0_bit;
 // End LCD module connections
 char i;
void main() {
 OSCCON =  0X70;    // Set internal oscillator at 8MHz
 ADCON1 = 0x0F;        // Configure AN pins as digital
 Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
 Lcd_Cmd(_LCD_CLEAR);             // clear LCD
 Lcd_Out(2,17,"LCD Example");
 for(i=0; i<16; i++) {             // Move text to the left 16 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);    // Shift display to the left
 for(i=0; i<14; i++) {
 for(i=0; i<4; i++) {
      Lcd_Cmd(_LCD_TURN_OFF);   // Turn Lcd display off
      Lcd_Cmd(_LCD_TURN_ON);    // Turn Lcd display on
 Lcd_Out(1,3,"Hello world!");
 while(1) {
   for (i =0; i<200; i++){
   Lcd_Chr(2, 8, (i/100) + 48);
   Lcd_Chr(2, 9, ((i/10) % 10) + 48);
   Lcd_Chr(2, 10, (i % 10) + 48);

The following video shows simulation using Proteus of our project:

Simulation files download:
The simulation was done using Proteus V8.2 and it can be downloaded from the following link:
PIC18F4550 LCD Simulation