Digital Code Lock

July 23rd, 2009 by admin Leave a reply »

schematic

We all know about the electronic code locking security system, here is the same concept of electronic code lock using AT89S52 i.e. 8051 family of micro controller. it has a 4×3 keypad for user input of password which will be numeric and a 20×4 alphanumeric LCD is used for user interface.

There are two kind of passwords one is the user password and the other is master password. when any user try to open the lock he must enter the right password which is of 5 digits. the user will be given 3 chances to enter the correct code otherwise he will be asked for the master password which is 10 digits long.

LCD Commands for 20×4 Alphanumeric LCD are as follows:

Goto first line 0×80

Goto second line 0xC0

Goto Third line 0×94

Goto Fourth Line 0xD4

Code for this project includes Keypad interfacing and logic for password check, as well as LCD routines. Download the complete source code as well as schematic for the project

#include<at89x52.h>
#include “lcd.h”

unsigned char pwd[]={1,2,3,4},usr[4];

void delayms()
{
int i,j;
for(i=0;i<120;i++)
{
for(j=0;j<1200;j++);
}
}

unsigned char getkey()
{ unsigned char i,key=0;
for(i=0;i<4;i++)     //row scanning
{
P1=~(0×80>>i);//0111 1111
if(P1_0==0)  //col check
{key=key+0;
while(P1_0!=1);
return key;
}
else if(P1_1==0)
{key=key+1;
while(P1_1!=1);
return key;
}
else if(P1_2==0)
{key=key+2;
while(P1_2!=1);
return key;
}
key=key+3;
}
return ‘x’;
}
void getpassword()
{
unsigned char i;
lcd_com(0xc2);
for(i=0;i<4;i++)
{ usr[i]=getkey();
while(usr[i]==’x')
{usr[i]=getkey();
}

if(usr[i]==10)
{
lcd_com(0×10);
lcd_data(‘ ‘);
lcd_com(0×10);
i=i-2;
}
else
{
lcd_data(0×30+usr[i]);
}
}
}
char checkpwd()
{
unsigned char i,c=0;
for(i=0;i<4;i++)
{
if(pwd[i]==usr[i])
c++;
}
if(c==4)
return 1;
else
return 0;
}
void main()
{ unsigned char t,tries=3;
P1=0xFF;
lcd_init();
lcd_com(0x0c);
lcd_com(0×01);
lcd_puts(“*DIGITAL LOCK*”);

while((tries)&&(t!=1))
{
getpassword();
t=checkpwd();
if(t==1)
{ lcd_com(0×80);
lcd_puts(“Authorised  “);
}
else
{
lcd_com(0×80);
lcd_puts(“wrong entry   “);
delayms();
lcd_com(0×01);
tries–;
lcd_data(0×30+tries);
lcd_puts(” tries-left”);

}
}
if(t==1)
{
lcd_com(0×01);
lcd_puts(“Thankyou”);
P0=0×00;
}
else
{
lcd_com(0×01);
lcd_puts(“Intruder Detected”);
P0=0xFF;
}
while(1){

}

}

Advertisement

Comments are closed.