Tải bản đầy đủ - 0 (trang)
PHỤ LỤC : SOURCE CODE

PHỤ LỤC : SOURCE CODE

Tải bản đầy đủ - 0trang

LCD_PrintString("1");

nhappass[i] = 1;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT4) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT5) == 0) //Nhap so 2

{

LCD_PrintString("2");

nhappass[i] = 2;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT5) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT6) == 0) //Nhap so 3

{

LCD_PrintString("3");

nhappass[i] = 3;

i++;

n=0;

while ( n==0 )

20



{

if ((P1IN&COT6) == 0)

n=0;

else

n=1;

}

}

P1OUT = 0x0D; /*.................Chon hang thu 2................*/

_delay_cycles(5000);

if ((P1IN&COT4) == 0) //Nhap so 4

{

LCD_PrintString("4");

nhappass[i] = 4;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT4) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT5) == 0) //Nhap so 5

{

LCD_PrintString("5");

nhappass[i] = 5;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT5) == 0)

21



n=0;

else

n=1;

}

}

else if ((P1IN&COT6) == 0) //Nhap so 6

{

LCD_PrintString("6");

nhappass[i] = 6;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT6) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT7) == 0) //Nhan close.

{

if (*p==1)

{

if (i==0)

{

LCD_PrintString("Door Locked");

n=0;

while ( n==0 )

{

if ((P1IN&COT7) == 0)

n=0;

}

}

}

22



}

P1OUT = 0x0B; /*.................Chon hang thu 3................*/

_delay_cycles(5000);

if ((P1IN&COT4) == 0) //Nhap so 7

{

LCD_PrintString("7");

nhappass[i] = 7;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT4) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT5) == 0) //Nhap so 8

{

LCD_PrintString("8");

nhappass[i] = 8;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT5) == 0)

n=0;

else

n=1;

}

}

else if ((P1IN&COT6) == 0) //Nhap so 9

{

23



LCD_PrintString("9");

nhappass[i] = 9;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT6) == 0)

n=0;

else

n=1;

}

}

P1OUT = 0x07; /*.................Chon hang thu 4................*/

_delay_cycles(5000);

if (*p==0)

{

if ((P1IN&COT4) == 0) //Nhan nut Exit

{



LCD_Clear();

LCD_PrintString("Door Open");



n=0;

while ( n==0 )

{

if ((P1IN&COT4) == 0)

n=0;

else

{

n=1;

i=7;

*p = *p+1;

}

}

}

24



}

if ((P1IN&COT5) == 0) //Nhap so 0

{

LCD_PrintString("0");

nhappass[i] = 0;

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT5) == 0)

n=0;

else

{

n=1;

}

}

}

else if ((P1IN&COT6) == 0) //Xoa so vua nhap

{

if ( i >0 ) //Neu bang i = 1 khong xoa

{

i--;

}

n=0;

while ( n==0 )

{

if ((P1IN&COT6) == 0)

n=0;

else

n=1;

}

25



}

/*......................Chon nhan ok hay exit hoac clear......................*/

while (i==6) //Xoa so vua nhap khi i = 5.

{

P1OUT = 0x07; //chon hang thu 4

if ((P1IN&COT7) == 0) //Nhan ok

{

i++;

n=0;

while ( n==0 )

{

if ((P1IN&COT7) == 0)

n=0;

else

{

n=1;

}

}

}

else if ((P1IN&COT6) == 0) //Xoa so vua nhap

{

if ( i > 0 ) //Neu bang i = 0 khong xoa

{

i--;

}

n=0;

while ( n==0 )

{

if ((P1IN&COT6) == 0)

26



n=0;

else

n=1;

}

}

else if (*p==0)

{

if ((P1IN&COT4) == 0) //Nhan nut Exit

{



LCD_Clear();

LCD_PrintString("Door Open");



n=0;

while ( n==0 )

{

if ((P1IN&COT4) == 0)

n=0;

else

{

n=1;

i=7;

*p = *p+1;



}

}

}

}

}

/*................Ket thuc doan cho nhan ok hay exit hoac clear...............*/

}

}

/*.....................Ket thuc doan quet phim so va nhap pass................*/

/*...........................Doan so sanh pass................................*/

void sosanh (int nhappass[6],int *i,int a,int b,int c,int d,int e,int h)

27



{

if (*i==0)

{

if(nhappass[*i] == a)

{

*i = *i+1;

if(nhappass[*i] == b)

{

*i = *i+1;

if(nhappass[*i] == c)

{

*i = *i+1;

if(nhappass[*i] == d)

{

*i = *i+1;

if(nhappass[*i] == e)

{

*i = *i+1;

if(nhappass[*i] == h)

*i = *i+1;

}

}

}

}

}

}

else

*i = 7;

}

/*.........................Ket thuc doan so sanh pass.........................*/

/*............................Doan treo he thong..............................*/

void treohethong (void)

{

28



int j;

LCD_Clear();

LCD_PrintString("System LOCK");

j=0;

while (j<=60)

{

_delay_cycles(1000000);

j++;

}

LCD_Clear();

LCD_PrintString("System LOCK");

}

/*...........................Ket thuc doan treo he thong......................*/

int j=0,i,k,n,m,p,g;

int nhappass[6],passdoi[6];

int a=2,b=2,c=2,d=2,e=2,h=2;

/*.....................Doan chuong trinh chinh................................*/

void main( void )

{

WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog

DCOCTL = CALDCO_1MHZ;



// Clock=1Mhz



BCSCTL1 = CALBC1_1MHZ;

P2DIR = 0xff;

P1DIR = 0x0f; //port 1.0,1.1,1.2,1.3 ngo ra,port 1.4,1.5,1.6,1.7 ngo vao.

LCD_Init();

{

LCD_Clear();

LCD_PrintString("Welcome ");

LCD_Goto(2,0);

LCD_PrintString("System Loading"); _delay_cycles(5000000);

LCD_Clear();LCD_Goto(2,0);

LCD_PrintString("Input Pass");

LCD_Goto(1,0);

29



p=1;

quetphim(nhappass,&p);

while(1)

i=0;

sosanh(nhappass,&i,a,b,c,d,e,h);

/*...............Doan kiem tra ket qua so sanh pass..............*/

k=0;

while (k==0)

{

if ( i == 6 )//Nhap pass dung.

{



LCD_Clear();

LCD_PrintString("Door Open");



m=0; //Cho phep vong lap quet phim chuc nang hoat dong.

j=0; //Gan j=0 de dem so lan nhap pass sai trong lan nhap moi.

k=1; //Gan k=1 de thoat khoi vong lap so sanh pass.

}

else //Nhap sai pass mot lan.

{

j++;

if (j==3)//So sanh da sai du 3 lan chua.

{



LCD_Clear();

LCD_PrintString("System LOCK");



treohethong ();

j=0; //Gan j=0 dem so lan nhap pass sai trong lan nhap moi.

k=1; //Gan k=1 de thoat khoi vong lap so sanh pass.

m=1;

}

else //Nhap sai chua qua 3 lan.

{

LCD_Clear();

LCD_PrintString("1 Time");

LCD_Goto(2,0);

LCD_PrintString("Remaining");

k=1; //Gan k=1 thoat khoi doan sanh pass de nhap tiep khi j<3.

30



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

PHỤ LỤC : SOURCE CODE

Tải bản đầy đủ ngay(0 tr)

×