Interfacing An LCD With Microcontroller
Introduction
In this project, we will interface an LCD with Microcontroller PIC16F877A. It's considered as second level tutorials.The LCD will be connected to Ports B and C as you will see in the schematic diagram.
MikroC Compiler is used.This tutorial assumes you have basic knowledge about programming PIC Microcontroller , if not , start with this tutorial and this.
MikroC Compiler is used.This tutorial assumes you have basic knowledge about programming PIC Microcontroller , if not , start with this tutorial and this.
Learn another LCD connection way
Schematic
Note: VDD and VSS of the pic Microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND. A Variable Resistor (Potentiometer) is provided in the circuit to adjust the Contrast of the LCD Display. LCD Module usually comes with back light, usually 15th pin is +ive and 16th pin is -ive of the Back light LED (Not Shown In the Circuit).
In 4-bit mode D0 – D3 pins and R/W pin are grounded. The variable resistor is used to adjust the contrast of the display.
In 4-bit mode D0 – D3 pins and R/W pin are grounded. The variable resistor is used to adjust the contrast of the display.
More LCD commands
MikroC Program
// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB7_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB7_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main() {
while(1)
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"LongJump Software-Technology");//Write text'LongJump Software-Technology' in first row
}
}
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB7_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB7_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main() {
while(1)
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"LongJump Software-Technology");//Write text'LongJump Software-Technology' in first row
}
}