Documente Academic
Documente Profesional
Documente Cultură
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<reg52.h>
#include<string.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void writestring(unsigned char *disp) ;
void Return(void);
char READ_SWITCHES(void);
char get_key(void);
unsigned char passo[]={"1234"},pass[3];
//*******************
//Pin description
/*
P0 is data bus
P3.7 is RS
P3.6 is E
P1.0 to P1.3 are keypad row outputs
P1.4 to P1.7 are keypad column inputs
*/
//********************
// Define Pins
//********************
sbit RowA = P1^0;
//RowA
sbit RowB = P1^1;
//RowB
sbit RowC = P1^2;
//RowC
sbit RowD = P1^3;
//RowD
sbit C1 = P1^4;
//Column1
sbit C2 = P1^5;
//Column2
sbit C3 = P1^6;
//Column3
//sbit C4 = P1^7;
//Column4
sbit E = P3^6;
//E pin for LCD
sbit RS = P3^7;
//RS pin for LCD
bit check;
// ***********************************************************
// Main program
//
int main(void)
{
char key,i,count=0;
// key char for keeping record of pressed key
cct_init();
lcdinit();
while(1)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
10
{
writecmd(0x01);
// Clear screen
writecmd(0x80);
writestring("Enter Password");
writecmd(0xc0);
for(i=0;i<4;i++)
{
key = get_key();
// Get pressed key
pass[i]=key;
writedata('*');
delay(100);
}
pass[4]='\0';
check=strcmp(pass,passo);
if(check==0)
{
writecmd(0x01);
writestring("success");
delay(1000);
writecmd(0x01);
writestring("Lock Open");
delay(1000);
while(1);
}
else
{
if(count<3)
{
writecmd(0x01);
writecmd(0xc0);
writestring("Try Again");
delay(5000);
count++;
}
else
{
writecmd(0x01);
writecmd(0xc0);
writestring("Blocked");
while(1);
}
}
}
}
void cct_init(void)
{
P0 = 0xFF; //used as data port for LCD
P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
P2 = 0x00; //not used
0
10
1
10
2
10
3
10
4
10
5
10
6
10
7
10
8
10
9
11
0
11
1
11
2
11
3
11
4
11
5
11
6
11
7
11
8
11
9
12
0
12
1
12
2
12
3
12
4
12
5
12
6
12
7
12
8
12
9
13
0
13
1
13
2
13
3
13
4
13
5
13
6
13
7
13
8
13
9
14
0
14
1
14
2
14
3
14
4
14
5
14
6
14
7
14
8
14
9
15
0
15
char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1;
//Test Row A
//Test Row B
//Test Row C
//Test Row D
}
char get_key(void)
{
char key = 'n';
while(key=='n')
//wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again
return key;
//when key pressed then return its value
}
void writestring(unsigned char *disp)
{
int x;
for(x=0;disp[x]!=0;x++)
{
writedata(disp[x]);
}
}
1
15
2
15
3
15
4
15
5
15
6
15
7
15
8
15
9
16
0
16
1
16
2
16
3
16
4
16
5
16
6
16
7
16
8
16
9
17
0
17
1
17
2
17
3
17
4
17
5
17
6
17
7
17
8
17
9
18
0
18
1
18
2
18
3
18
4
18
5
18
6
18
7
18
8
18
9
19
0
19
1
19
2
19
3
19
4
19
5
19
6
19
7
19
8
19
9
20
0
20
1
20