//********************************************************************************
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:lcd 4bit interafcing with 8051
//Platform: 8051
//Software:Kiel
//********************************************************************************
Program:
#include<reg51.h>
#define lcd P1
void cmd(unsigned char);
void dat(unsigned char);
void Delay_ms(unsigned char);
void main()
{
unsigned char i;
unsigned char tr[]="PALAK";
cmd(0x01); //Clear Lcd
cmd(0x02); //4 Bit Specification
cmd(0x28); //4 Bit specification
cmd(0x0c);
cmd(0x80); //Cursor starting point
cmd(0X06);
TMOD=0x20; //8 Bit Auto Reload Mode; Timer 1;
TH1=0xfd; //9600 Boud Rate;
SCON=0x50; //Serial Mode 1; REN=1;
TR1=1; //Timer Run;
while(1)
{
for(j=0;j<5;j++)
{
SBUF=tr[j];
while(TI==0);
TI=0;
}
while(1);
}
i=0;
while(tr[i]!='\0')
{
dat(tr[i]);
i++;
}
}
void cmd(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & (0xF0));
lcd |=(2<<0);
Delay_ms(2);
lcd=lcd & 0xFC;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(2<<0);
Delay_ms(20);
lcd=lcd & 0xFC;
Delay_ms(20);
}
void dat(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & 0xF0);
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
}
void Delay_ms(unsigned char p)
{
unsigned int i,j;
for(i=0;i<p;i++)
{
for(j=0;j<20;j++);
}
}
Simulation Result:
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:lcd 4bit interafcing with 8051
//Platform: 8051
//Software:Kiel
//********************************************************************************
Program:
#include<reg51.h>
#define lcd P1
void cmd(unsigned char);
void dat(unsigned char);
void Delay_ms(unsigned char);
void main()
{
unsigned char i;
unsigned char tr[]="PALAK";
cmd(0x01); //Clear Lcd
cmd(0x02); //4 Bit Specification
cmd(0x28); //4 Bit specification
cmd(0x0c);
cmd(0x80); //Cursor starting point
cmd(0X06);
TMOD=0x20; //8 Bit Auto Reload Mode; Timer 1;
TH1=0xfd; //9600 Boud Rate;
SCON=0x50; //Serial Mode 1; REN=1;
TR1=1; //Timer Run;
while(1)
{
for(j=0;j<5;j++)
{
SBUF=tr[j];
while(TI==0);
TI=0;
}
while(1);
}
i=0;
while(tr[i]!='\0')
{
dat(tr[i]);
i++;
}
}
void cmd(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & (0xF0));
lcd |=(2<<0);
Delay_ms(2);
lcd=lcd & 0xFC;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(2<<0);
Delay_ms(20);
lcd=lcd & 0xFC;
Delay_ms(20);
}
void dat(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & 0xF0);
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
}
void Delay_ms(unsigned char p)
{
unsigned int i,j;
for(i=0;i<p;i++)
{
for(j=0;j<20;j++);
}
}
Simulation Result:
No comments:
Post a Comment