Door Lock System

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

#include<reg51.

h>
#include<string.h>
sbit RS = P3^0;
sbit EN = P3^1;
sbit IN1 =P3^2;
sbit IN2 = P3^3;

// Function to provide delay

void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
for(j=0;j<255;j++);
}

//Function to send the command to LCD

void cmd(char cm)


{
P2 = cm; // Send the command to LCD
RS = 0; // Select the Command Register by pulling RS LOW
EN = 1; //Send a High-to-Low Pusle at Enable Pin
delay(1);
EN = 0;
}

// Function to send the Data to LCD

void dat(char dt)


{
P2 = dt; // Send the data to LCD
RS = 1; //Select the Data Register by pulling RS HIGH
EN = 1; //Send a High-to-Low Pusle at Enable Pin
delay(1);
EN = 0;
}

// Function to display

void display(char *lcd)


{
while(*lcd != '\0')
{
dat(*lcd);
lcd++;
}
}

// function to initialize the lcd

void lcdint()
{
cmd(0x01); //clear display
cmd(0x38); //Initialization of 16X2 LCD in 8bit mode
cmd(0x0E); //Display OFF, Cursor ON
cmd(0x80); //Move the cursor to beginning of first line
}

void main()
{
char pass[5] = "1234";
char pass2[5];
int i=0;
char *ptr;
ptr = pass2;
lcdint();
display("Password-");
pass2[4]='\0';

while(1)
{
while(i<4)
{
// Identifying Keystroke

// for 7,8,9,/

P1=0xFE;
if(P1==0xEE)
{
*(ptr+i)='7';
dat('7');
delay(200);
cmd(0x06); //to increment cursor

i++;

}
else if(P1==0xDE)
{
*(ptr+i)='8';
dat('8');
delay(200);
cmd(0x06);

i++;

}
else if(P1==0xBE)
{
*(ptr+i)='9';
dat('9');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0x7E)
{
*(ptr+i)='/';
dat('/');
delay(200);
cmd(0x06);

i++;
}

// for 4,5,6,*
P1=0xFD;
if(P1==0xED)
{
*(ptr+i)='4';
dat('4');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0xDD)
{
*(ptr+i)='5';
dat('5');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0xBD)
{
*(ptr+i)='6';
dat('6');
delay(200);
cmd(0x06);

i++;
}
else if (P1==0x7D)
{
*(ptr+i)='*';
dat('*');
delay(200);
cmd(0x06);

i++;
}

// for 1,2,3,-

P1=0xFB;
if(P1==0xEB)
{
*(ptr+i)='1';
dat('1');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0xDB)
{
*(ptr+i)='2';
dat('2');
delay(200);
cmd(0x06);
i++;
}
else if(P1==0xBB)
{
*(ptr+i)='3';
dat('3');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0x7B)
{
*(ptr+i)='-';
dat('-');
delay(200);
cmd(0x06);

i++;
}

// for C,0,=,+

P1=0xF7;
if(P1==0xE7)
{
*(ptr+i)='C';
dat('C');
delay(200);
cmd(0x06);

i++;

}
else if(P1==0xD7)
{
*(ptr+i)='0';
dat('0');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0xB7)
{
*(ptr+i)='=';
dat('=');
delay(200);
cmd(0x06);

i++;
}
else if(P1==0x77)
{
*(ptr+i)='+';
dat('+');
delay(200);
cmd(0x06);
i++;
}
}

while(i==4)
{

if ((strcmp(pass, pass2)) == 0) //strcmp() takes 2 strings and compare them


lexicographically
// if both the strings are equal it returns 0
{
cmd(0xC0); //It is also used to set the position of the cursor
but this time, the position is set to the starting position in the second line.
display("Correct");
IN1 = 1;
IN2 = 0; //P0.0(IN1) pin HIGH and P0.1(IN2) pin LOW to open
the door
delay(100);
}
else
{
cmd(0xC0);
display("Incorrect");
IN1 = 0;
IN2 = 0;
delay(100);
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy