8051-P89V51RD2 */
#include <reg51.h>
#include <string.h>
sbit rs = P2^7; // declare P2.7 as rs pin
sbit en = P2^5; // declare p2.5 as enable pin
sbit rw = P2^6; // declare p2.6 as read/write pin
sbit b = P0^7; // busy flag
sbit port = P1^2; // connected to IR sensor
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void writecmd(unsigned char a)
{
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P0 = a; // send command character
en = 1; // strob LCD
en = 0;
}
void writedat(unsigned char b)
{
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P0 = b; // send data character
en = 1; // strob LCD
en = 0;
}
void busy()
{
en = 0; // disable display
P0 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
{
en=0; // strob LCD till P0.7 is 1
en=1;
}
en=0;
}
void send(unsigned char d)
{
while(!TI);
TI=0;
SBUF=d;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<=l;i++)
{
writedat(*s); // write every char one by one
s++;
}
}
main()
{
P0=0x00; // P0 and P0 as output ports
P2=0x00;
port=0;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
TI=1;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01);
writecmd(0x01);
send('0');
writestr("Not Occupied");
while(port==0);
writecmd(0x01);
send('1');
writestr("Occupied");
while(port==1); // continuous loop
}
THANK YOU FOR VISITING..!!
PLEASE COMMENT
#include <reg51.h>
#include <string.h>
sbit rs = P2^7; // declare P2.7 as rs pin
sbit en = P2^5; // declare p2.5 as enable pin
sbit rw = P2^6; // declare p2.6 as read/write pin
sbit b = P0^7; // busy flag
sbit port = P1^2; // connected to IR sensor
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void writecmd(unsigned char a)
{
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P0 = a; // send command character
en = 1; // strob LCD
en = 0;
}
void writedat(unsigned char b)
{
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P0 = b; // send data character
en = 1; // strob LCD
en = 0;
}
void busy()
{
en = 0; // disable display
P0 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
{
en=0; // strob LCD till P0.7 is 1
en=1;
}
en=0;
}
void send(unsigned char d)
{
while(!TI);
TI=0;
SBUF=d;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<=l;i++)
{
writedat(*s); // write every char one by one
s++;
}
}
main()
{
P0=0x00; // P0 and P0 as output ports
P2=0x00;
port=0;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
TI=1;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01);
writecmd(0x01);
send('0');
writestr("Not Occupied");
while(port==0);
writecmd(0x01);
send('1');
writestr("Occupied");
while(port==1); // continuous loop
}
THANK YOU FOR VISITING..!!
PLEASE COMMENT
No comments:
Post a Comment