Вы находитесь на странице: 1из 17

#include<reg51.

h>
void lcd_int();
void busycheck();
void delay();
void delay1();
void delay2();
void get_key_read();
void change_password();
void user_change_password();
void display_lcd(char *ptr);
void enter_password(char ch);
void wrong_password();
void press1_or_2();
void open_door();
void stepper_motor_control();
void wrong_password_ex();
strcompare(char *ptr,char *ptr1);
void strcopy(char *ptr,char *ptr1);
char xdata *CON;
char xdata *pa;
char xdata *pb;
char xdata *pc;
char xdata *CON1;
char xdata *pa1;
char xdata *pb1;
char xdata *pc1;

char xdata *IOCNT;


char xdata *DCNT;
xdata char s_arr[]={0x09,0x05,0x06,0x0a};
xdata char s_arr1[]={0x0a,0x06,0x05,0x09};
xdata char array1[]="

System

";

xdata char array2[]=" Vi Security ";


xdata char arr[]="Password:";
xdata char arr1[]=" Check your ";
xdata char arr2[]=" Pass Word ";
xdata char arr3[]=" Opening Door ";
xdata char arr4[]=" Closing Door ";
xdata char arr5[]=" Access Denied ";
xdata char arr6[]="1: Open Door ";
xdata char arr7[]="2:changepassword";
xdata char arr8[]=" Press 1 or 2 ";
xdata char s_p_word[]="00000";
xdata char p_word[6];
int i=0,cmp=0,count=0,count1=0;
char ch;
void main()
{

CON = 0xff0f;
pa = 0xff0c;
pb = 0xff0d;
pc = 0xff0e;

//key board interfacing via 8255_1

*CON=0x83;
of port c as a input port

//control register assign port b and lower byte

*pa = 0x0f;
*pb = 0x00;
*pc = 0x00;

IOCNT=0xffc0;

//Lcd interfacing via IO port

DCNT=0xffc4;

lcd_int();
while(1)
{
back:
get_key_read();

//key read from security system

cmp=strcompare(s_p_word,p_word);

//compare password

if(cmp==0)
{

change_password();
if(ch=='1')
{

display_lcd(arr3);

//stepper motor control

stepper_motor_control();
}
else
{

user_change_password();
goto back;
}
count=0;
}

else
{
count++;
if(!(count<3))
{
*CON=0x82;

//Control resistor assign portC

is a output port
display_lcd(arr5);
*pc=0x01;

//access disconnect
//Port C assign Busser

while(1);
}
else
{
wrong_password();
delay1();
}
}
}
}

void get_key_read()

//read key subroutine

{
display_lcd(arr);
while(i<5)
{
*pa=0x00;
while((*pb&0x0f)==0x0f);
*pa=0x0e;
if(!((*pb & 0x0f)==0x0f))
{
switch(*pb & 0x0f)
{
case 0x0e:p_word[i]='0';
break;
case 0x0d:p_word[i]='1';
break;
case 0x0b:p_word[i]='2';
break;
case 0x7:p_word[i]='3';
break;
}
}
else
{
*pa=0x0d;
if(!((*pb & 0x0f)==0x0f))
{

switch(*pb & 0x0f)


{
case 0x0e:p_word[i]='4';

break;
case 0x0d:p_word[i]='5';

break;
case 0x0b:p_word[i]='6';
break;
case 0x07:p_word[i]='7';

break;
}

}
else
{
*pa=0x0b;
if(!((*pb & 0x0f)==0x0f))
{

switch(*pb & 0x0f)


{
case 0x0e:p_word[i]='8';
break;

case 0x0d:p_word[i]='9';
break;
case 0x0b:p_word[i]='a';
break;
case 0x07:p_word[i]='b';
break;
}

}
else
{
*pa=0x07;
if(!((*pb & 0x0f)==0x0f))
{
switch(*pb & 0x0f)
{
case 0x0e:p_word[i]='c';
break;
case 0x0d:p_word[i]='d';
break;
case 0x0b:p_word[i]='e';
break;
case 0x07:p_word[i]='f';
break;

}
}
}
}
if(!(count1==1))
enter_password('*');
else
enter_password(p_word[i]);
i++;
delay2();
}
p_word[i]='\0';
i=0;
}

void stepper_motor_control()
{
int i,j,k;
CON1=0xff13;
pa1=0xff10;
pb1=0xff11;
pc1=0xff12;
*CON1=0x80;
*pa1=0x00;
*pb1=0x00;
*pc1=0x00;

//steppermotor interfacing via 8255_2

for(i=0,j=0;j<=45;j++,i++)
{

if((j>10)&&(*pc==0x00))
check when ever open the door

//internel switch continiously

{
break;
}
i=i & 3;

// door open routine

delay2();
*pa1=s_arr[i];

}
display_lcd(arr4);
for(i=0,k=0;k<=j;k++,i++)
{
i=i & 3;
delay2();
*pa1=s_arr1[i];

//door close routine

void user_change_password()
routine

//user mannually changed password in this

{
count1++;
get_key_read();
strcopy(s_p_word,p_word);
count1=0;

void change_password()
{
int i;
busycheck();
display_lcd(arr6);
for(i=0;arr7[i]!='\0';i++)
{
busycheck();
*IOCNT=0x00;
*DCNT=0xc0+i;

busycheck();
*IOCNT=0x01;
*DCNT=arr7[i];
delay();
}

//starting location of display

press1_or_2();
}
void press1_or_2()
{
*pa=0x00;

while((*pb&0x0f)==0x0f);
*pa=0x0e;
if(!((*pb & 0x0f)==0x0f))
{
switch(*pb & 0x0f)
{
case 0x0d:ch='1';
break;
selection
case 0x0b:ch='2';
break;
default:
goto jumb;

}
}
else
{
jumb:
display_lcd(arr8);
delay1();

//key read for option

change_password();
}
}
void enter_password(char ch)
{
delay();
busycheck();
*IOCNT=0x00;
*DCNT=0x89+i;

busycheck();
*IOCNT=0x01;
*DCNT=ch;

void display_lcd(char *ptr)


{
int i;
delay1();

busycheck();
*IOCNT=0x00;
*DCNT=0x01;
for(i=0;*ptr!='\0';i++)
{

busycheck();
*IOCNT=0x00;
*DCNT=0x80+i;

busycheck();
*IOCNT=0x01;
*DCNT=*ptr;
ptr++;
}

}
void wrong_password()
{
int i;
delay();
display_lcd(arr1);

for(i=0;arr2[i]!='\0';i++)
{

busycheck();
*IOCNT=0x00;
*DCNT=0xC0+i;

busycheck();

*IOCNT=0x01;
*DCNT=arr2[i];
}
}
void delay()
{
int i,j;
for(i=0;i<0xfff;i++);
for(j=0;j<0xfff;j++);
}
void delay1()
{
int i,j;
for(i=0;i<0xfff;i++)
for(j=0;j<0x55;j++);

}
void delay2()
{
int j,m;
for(m=0;m<=0xff;m++)
for(j=0;j<=0xff;j++);
}
void busycheck()
{
delay();

*IOCNT=0x02;
while((*DCNT&0x80)!=0);

//lcd busy check

*IOCNT=0x00;
}

void lcd_int()
{
int i;
busycheck();
*IOCNT=0x00;

//5*7 lcd init

*DCNT=0x38;

busycheck();
*IOCNT=0x00;

//clear display

*DCNT=0x01;

busycheck();
*IOCNT=0x00;

//starting location of display

*DCNT=0x80;

busycheck();
*IOCNT=0x00;
*DCNT=0x04;

busycheck();
*IOCNT=0x00;

//set cursor move direction

*DCNT=0x0e;
for(i=0;array2[i]!='\0';i++)
{
busycheck();
*IOCNT=0x00;

//starting location of display

*DCNT=0x80+i;

busycheck();
*IOCNT=0x01;
*DCNT=array2[i];
}

for(i=0;array1[i]!='\0';i++)
{
busycheck();
*IOCNT=0x00;
*DCNT=0xc0+i;

busycheck();
*IOCNT=0x01;
*DCNT=array1[i];
delay();
}
delay1();
}

//starting location of display

void strcopy(char *ptr,char *ptr1)


{
while(*ptr1!='\0')
{
*ptr=*ptr1;
ptr++;
ptr1++;
}
*ptr='\0';
}
strcompare(char *ptr,char *ptr1)
{
while(*ptr!='\0')
{
if(*ptr!=*ptr1)
{
return(-1);
}
ptr++;
ptr1++;
}
if(*ptr!=*ptr1)
return(-1);
return(0);
}