Professional Documents
Culture Documents
be/OASLaOfTZ9Q
8051 Projects
8051
10
Microcontrollers form the most significant part of several security and surveillance systems
which plays an important role in ensuring safety of our priced possession. Here we are
about to see the Embedded design and programming of a Password based Digital locker
system using 8051 Microcontroller. Despite the simple look this system can handle
intrusions to offer high protection and also alerts the user in case anonymous person tries to
break into the system.
16 x 2 LCD:
4 x 3 KEYPAD:
43 keypad
The keypad part of this project was used to feed password input and to initialize the system.
I have used a 4 x 3 configuration keypad a total of 12 keys in it, you can increase the
number of keys by altering the program and design. Read Programming and Interfacing of
Keypad with 8051 Microcontroller to obtain complete knowledge about it.
INITIALIZATION:
This locker will not respond to any of the key press before initialization using * key.
A command Enter Password in the LCD and blink of cursor will convey that the
system is ready for password input.
PASSWORD INPUT:
The password input can be fed into the system by using keys from 1,29
As soon as you enter four characters controller will verify if the entered password
If the password matches, LCD will display as Message Locker Open and relay will
gets activated.
After the usage of the protected locker, you need to turn off the system by means of
If the password doesnt match , LCD will display a Message Wrong Password in it
If a user entered the correct password in the second attempt then the trail count will
be back to zero and then the user have to lock the system after usage after pressing #
But if the user failed to enter correct password for three continuous attempts, then
Now the Last thing after usage of the system is to turn them off using the # key.
This applies only in the case if the user entered correct password.
If the number of trial gets over the system enters into to alert mode and cannot be
turned off using # during that period of time.
#include<stdio.h>
#include<reg51.h>
#include<stdlib.h>
#include<string.h>
voidcmdwr(void);//LCDcommandwritesubroutine
voiddatwr(void);//LCDdatawritesubroutine
voiddelay(void);//Delayfunction
voidcheck(void);//Passwordcheckfunction
voidansw(void);//Trialandresultanalysisfunction
voidasterisk(void);//Asteriskkeyinputfunction
voiddebounce_delay(void);//Keypaddebouncedelayfunctiom
voidtrl_chk(void);//trialCheckfunction
voidinit(void);//systeminitialization
sbiten=P3^2;
sbitrs=P3^0;
sbitrw=P3^1;
sbitrelay=P3^4;
sbitalarm=P3^7;
codeunsignedcharmsg[14]="EnterPassword";
codeunsignedcharopen_msg[11]="LockerOpen";
codeunsignedcharlock_msg[14]="WrongPassword";
codeunsignedchararray1[5]={0x38,0x0f,0x06,0x01,0x80};
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.
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.
codeunsignedchararray2[5]={0xc0,0xc0,0xc1,0xc2,0xc3};
unsigneddatapasswd[5]={0,2,9,4,0};//Lockerpasswordinitial'0'isdummy
unsigneddatadigit[5];
unsignedchari,p,k,l,m,n,f,y;
intcount=0,num=0,trial=0;//initializingcount,trialandnumtozero
voidmain()
{
relay=0;//turningrelayoff
alarm=0;//turningalarmoff
while(1)
{
P2=0xf7;//Initializationkeyscan
i=(P2&0xf0);
{
if(i==0xe0)
{
init();
gotoLOOP;
}
}
}
LOOP:while(1)//Entirekeyscanstarts
{
P2=0xfe;
i=(P2&0xf0);
{
if(i==0xe0)
{
debounce_delay();//Delaytoovercomekeypadbounce
count++;//incrementingcount
asterisk();
digit[count]=1;//Settingkeyvalue
check();
answ();
}
elseif(i==0xd0)
{
debounce_delay();
count++;
asterisk();
digit[count]=2;
check();
answ();
}
elseif(i==0xb0)
{
debounce_delay();
count++;
asterisk();
digit[count]=3;
check();
answ();
}
}
P2=0xfd;
i=(P2&0xf0);
{
if(i==0xe0)
{
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
debounce_delay();
count++;
asterisk();
digit[count]=4;
check();
answ();
}
elseif(i==0xd0)
{
debounce_delay();
count++;
asterisk();
digit[count]=5;
check();
answ();
}
elseif(i==0xb0)
{
debounce_delay();
count++;
asterisk();
digit[count]=6;
check();
answ();
}
}
P2=0xfb;
i=(P2&0xf0);
{
if(i==0xe0)
{
debounce_delay();
count++;
asterisk();
digit[count]=7;
check();
answ();
}
elseif(i==0xd0)
{
debounce_delay();
count++;
asterisk();
digit[count]=8;
check();
answ();
}
elseif(i==0xb0)
{
debounce_delay();
count++;
asterisk();
digit[count]=9;
check();
answ();
}
}
P2=0xf7;
i=(P2&0xf0);
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
{
if(i==0xe0)
{
debounce_delay();
for(p=0;p<=4;p++)
{
P1=array1[p];
cmdwr();
delay();
}
for(m=0;m<=13;m++)
{
P1=msg[m];//Enterpasswordmessagedisplay
datwr();
delay();
}
P1=0x3c;
cmdwr();
delay();
P1=0xc0;
cmdwr();
delay();
count=num=0;
}
elseif(i==0xd0)
{
debounce_delay();
count++;
asterisk();
digit[count]=0;
check();
answ();
}
elseif(i==0xb0)
{
debounce_delay();
relay=0;
num=count=0;
P1=0x08;
cmdwr();
delay();
}
}
}
}
voiddatwr()
{
rs=1;rw=0;en=1;delay();en=0;//stepstosenddatatolcd
}
voidcmdwr()
{
rs=0;rw=0;en=1;delay();en=0;//stepstosendcommandtolcd
}
voiddelay()//softwaredelay
{
for(k=1;k<200;k++);
{
for(l=1;l<=200;l++);
}
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
}
voidcheck()
{
switch(count)
{
case1:if(digit[count]==passwd[count])
{
num=num+1;
}
break;
case2:if(digit[count]==passwd[count])
{
num=num+1;
}
break;
case3:if(digit[count]==passwd[count])
{
num=num+1;
}
break;
case4:if(digit[count]==passwd[count])
{
num=num+1;
}
break;
}
}
voidansw()
{
if(count==4)//Checkingcount
{
if(num==4)//Checking"num"valuetoverifypassword
{
relay=1;
for(p=0;p<=4;p++)
{
P1=array1[p];
cmdwr();
delay();
}
for(f=0;f<=10;f++)
{
P1=open_msg[f];//Lockeropenmsg
datwr();
delay();
}
count=num=0;
trial=0;
while(1)
{
P2=0xf7;
i=(P2&0xf0);
{
if(i==0xe0)
{
init();
break;
}
elseif(i==0xb0)
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
{
debounce_delay();
relay=0;
num=count=0;
P1=0x01;
cmdwr();
delay();
P1=0x02;
cmdwr();
delay();
}
}
}
}
else
{
relay=0;
for(p=0;p<=4;p++)
{
P1=array1[p];
cmdwr();
delay();
}
for(n=0;n<=13;n++)
{
P1=lock_msg[n];//Lockerclosedmessage
datwr();
delay();
}
trial++;
trl_chk();
while(1)
{
P2=0xf7;
i=(P2&0xf0);
{
if(i==0xe0)
{
init();
break;
}
}
}
}
}
}
voidasterisk()//Subroutinetodisplay"*"inLCD
{
P1=array2[count];
cmdwr();
P1=0x2a;
datwr();
}
voiddebounce_delay()//DebounceDelaygenerationusingtimers
{
for(y=0;y<=4;y++)
{
TMOD=0x01;
TH0=0x3C;
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
TL0=0xB0;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}
voidtrl_chk()//Functiontochecktrials
{
if(trial>2)//Verifyingnumberoftrials
{
P2=0x00;
while(1)
{
alarm=1;
}
}
}
voidinit()//Functiontoinitializesystem
{
debounce_delay();
for(p=0;p<=4;p++)
{
P1=array1[p];
cmdwr();
delay();
}
for(m=0;m<=13;m++)
{
P1=msg[m];
datwr();
delay();
}
P1=0x3c;
cmdwr();
delay();
P1=0xc0;
cmdwr();
delay();
count=num=0;
}
NOTE:
The first 0 of the array passwd is dummy, 2940 is the password for the above
system.
In case you face with multiple inputs while pressing a key increase the debounce
delay value by means of y value increment in the sub routine debounce_delay.