Online Course Reviews:

Thursday, December 04, 2014

Lcd 16x2 Display Interfacing with Pic Microcontroller [step by step]

Lcd 16x2 Display  Interfacing
Lcd 16x2 Display  
In this tutorial, I will show how to interface LCD display with pic18f2550 microcontroller.
Generally, LCD display has 16 pins. 16x2 means the display has 12 column and 2 row.

The picture given below shows about rows and columns.


The picture is given below discuss each pin.

 Proteus Project :

Now we are going to create a new project in Proteus and follow instructions given below :








According to the instruction pick  'pic18f2550', crystal, 22pf capacitor, 5Kohm variable resistor, power and ground. For LCD display please type "LM016L" on keywords.
In this tutorial, we will use 4 data pin [D4-D7]. Now complete the circuit as given below :
Lcd 16x2 Display  Interfacing with Microcontroller [step by step]
Lcd 16x2 Display  Interfacing with Microcontroller [step by step]


We have completed the circuit. Now we need the source hex file. So create a new project in MikroC.
Now follow the instructions:

MikroC Source Code :





MikroC LCD Library :
  1. Lcd_Init             
  2. Lcd_Out      
  3. Lcd_Out_Cp
  4. Lcd_Chr
  5. Lcd_Chr_Cp
  6. Lcd_Cmd
Description :
1.Lcd_Init   :  Initializes Lcd module.
2.Lcd_Out  :  Prints text on Lcd starting from specified position. Both string variables and literals can be passed as a text.
Parameters :
  1. row: starting position row number
  2. column: starting position column number
  3. text: text to be written
3. Lcd_Out_Cp :  Prints text on Lcd at the current cursor position. Both string variables and literals can be passed as a text.

4.Lcd_Chr :  Prints character on Lcd at a specified position. Both variables and literals can be passed as a character. Parameters :
  1. row: writing position row number
  2. column: writing position column number
  3. out_char: character to be written


5.Lcd_Chr_Cp : Prints character on Lcd at the current cursor position. Both variables and literals can be passed as a character.
 6.Lcd_Cmd :   Sends command to Lcd.
a)     Lcd_Cmd(_LCD_SHIFT_RIGHT)  :This function is used for shifting on the right hand side .
          Lcd_Cmd(_LCD_SHIFT_RIGHT);
 Lcd_Cmd(_LCD_SHIFT_RIGHT);

b)     Lcd_Cmd(_LCD_SHIFT_LEFT)  :This function is used for shifting on the left hand side.
c)     Lcd_Cmd(_LCD_CURSOR_OFF) : This function is used for setting the cursor off .
d)     Lcd_Cmd(_LCD_CLEAR) :To Clear the lcd .
Source Code :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



sbit LCD_RS at LATB7_bit;
sbit LCD_EN at LATB6_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End Lcd module connections

void main(){
  ADCON1=0x0F;            // Disable Analog to Digital Converter
  CMCON=7;                    // Disable Comparator

  Lcd_Init();                        // Initialize Lcd
      while(1){
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"Microcontroller");
  Lcd_Out(2,4,"Tutorial");                         // Write text in first row
  delay_ms(400);
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


 Now create a hex file with MikroC .Please follow the instructions :

Now go to the hardware and make double click on the Microcontroller. Please follow the instructions:






Lcd 16x2 Display  Interfacing with Microcontroller [step by step]
Lcd 16x2 Display  Interfacing with Microcontroller [step by step]


 I was just trying to make something good for a beginner. If I made something wrong, forgive me .

Thank You !

1 comment:

  1. You've created an excellent essay UK TFT LCD Display supplier. Your essay gave me some unique and useful information.

    ReplyDelete