Experiment4 LCD 1
Experiment4 LCD 1
Tech (ECE)
Trimester: VI Subject: MICROCONTROLLERS
Name: Krish Shah Class: A
Roll No: PA11 Batch: A2
Experiment No: 04
Name of the Experiment: Interfacing of LCD
Performed on:
Marks Teacher’s Signature with date
Submitted on:
www.mitwpu.edu.in
Program:
/*
* LCD_Interfacing.c
*
* Created on: 09-May-2022
* Author: VK409B12
*/
#include "c8051F340.h"
void DelayMs(unsigned int Ms);
void Write_Command_Lcd(unsigned char Command);
void Write_Data_Lcd(unsigned char Character);
void main()
{
XBR1 = 0x40; /* Enable Crossbar*/
P2MDOUT = 0xFF; /* P2 output port*/
P1MDOUT = 0xE0; /* P1.5,P1.6&P1.7 output pins*/
Write_Command_Lcd(0x38); /2 Lines and 5x7 matix/
DelayMs(50); /* Delay routine*/
Write_Command_Lcd(0x01); /* Clear Display Screen*/
DelayMs(50);
Write_Command_Lcd(0X0C); /* Display ON, Cursor OFF*/
DelayMs(50);
Write_Command_Lcd(0X80); /* Force cursor to beginning of 1st line*/
DelayMs(50);
Write_Data_Lcd('W’); /* Call Data routine*/
DelayMs(50); /* Delay routine*/
Write_Data_Lcd('P’);
DelayMs(50);
Write_Data_Lcd('U');
DelayMs(50);
while (1);
}
void DelayMs(unsigned int Ms)
{
unsigned int n;
www.mitwpu.edu.in
unsigned int i;
for (n=0; n < Ms; n++)
{
for (i=0; i < 65; i++);
}
}
void Write_Command_Lcd(unsigned char Command)
{
LCD_RS = 0; //Select Command Register
LCD_RW = 0;
P2 = Command;
LCD_EN = 1; // EN pin high->low
DelayMs(15);
LCD_EN = 0;
}
void Write_Data_Lcd(unsigned char Character)
{
LCD_RS = 1; //Select Date Register
LCD_RW = 0;
P2 = Character;
LCD_EN = 1; // EN pin high->low
DelayMs(15);
LCD_EN = 0;
}
SimplicityStudio screenshots:
www.mitwpu.edu.in
www.mitwpu.edu.in
www.mitwpu.edu.in
Figure 1:Hex File
Conclusion:
Study Question:
1. Explain the 4-bit mode of LCD.
2. Explain the significance of RS pin and list commands of LCD.
3. Explain buzy flag.
www.mitwpu.edu.in
www.mitwpu.edu.in
Additional link:
1. https://www.electronicshub.org/interfacing-16x2-lcd-8051/
www.mitwpu.edu.in