Académique Documents
Professionnel Documents
Culture Documents
8051 Microcontroller
Traditional lock systems using mechanical lock and key mechanism are being replaced by new
advanced techniques of locking system. These techniques are an integration of mechanical and
electronic devices and highly intelligent. One of the prominent features of these innovative lock
systems is their simplicity and high efficiency. Such an automatic lock system consists of
electronic control assembly which controls the output load through a password. This output load
can be a motor or a lamp or any other mechanical/electrical load. Here we develop an electronic
code lock system using 8051 microcontroller, which provides control to the actuating the load. It
is a simple embedded system with input from the keyboard and the output being actuated
accordingly. This system demonstrates a password based door lock system wherein once the
correct code or password is entered, the door is opened and the concerned person is allowed
access to the secured area. Again if another person arrives it will ask to enter the password. If
the password is wrong then door would remain closed, denying the access to the person.
at89c51 controller
Programming cable
43 matrix keypad
162 LCD
5V Relay
DC motor
BC 547 Transistor
33pF capacitors 2
12MHz Crystal
connecting wires
Software Requirements:
Keil compiler
Flash magic
Proteus
FINAL REPORT
ABSTRACT
LIST OF TABLES:
1. PIN DESCRIPTION OF AT89C2051
2. PORT ALTERNATE FUNCTIONS
LIST OF FIGURES:
A. BLOCK DIAGRAM
B. PIN OUT OF AT89C2051
C. BLOCK DIAGRAM OF AT89C2051
D. PCB FBRICATION
E. FLOW CHART
F. PINOUT FOR IC LM7805
G. BLOCK DIAGRAM OF IC LM7805
H. PINOUT FOR BC547
1. INTRODUCTION
Password Based Door Security System using Microcontroller is used in the
places where we need more security. It can also used to secure lockers and other
protective doors.
The system comprises a number keypad and the keypads are connected to the 8
bit microcontroller AT89C2051. This is one of the popular Microcontrollers. It
has only 20 pins and there are 15 input/output lines. The microcontroller has a
program memory of 2Kilobytes. The microcontroller continuously monitor the
keypad and if somebody enters the password it will check the entered password
with the password which was stored in the memory and if it they are same then
the microcontroller will switch on the corresponding device.
The system will allow the person who knows the password and
it will not allow who dont know the password and the system
will also show the persons who try to break the protection
barrier.
processing unit with an 8 bit Accumulator and another 8 bit B register as main
processing blocks. Other portions of the architecture include few 8 bit and 16 bit
registers and 8 bit memory locations. Each 8031 device has some amount of
data RAM built in the device for internal processing. This area is used for stack
operations and temporary storage of data. This base architecture is supported
with on chip peripheral functions like I/O ports, timers/counters, versatile serial
9
Timers/Counters
8031 has two 16 bit Timers/Counters capable of working in different modes.
Each consists of a `High' byte and a `Low' byte which can be accessed under
software. There is a mode control register and a control register to configure
these timers/counters in number of ways. These timers can be used to measure
time intervals, determine pulse widths or initiate events with one microsecond
resolution up to a maximum of 65 millisecond (corresponding to 65, 536
counts). Use software to get longer delays. Working as counter, they can
accumulate occurrences of external events (from DC to 500 KHz) with 16 bit
precision. In our project we are using 8 bit microcontroller AT89C2051, it is the
advanced 8 bit microcontroller from ATMEL, which incorporates Flash Rom,
and Timer etc.
Features of AT89C2051:
Compatible with MCS-51 Products
2 Kbytes of Reprogrammable Flash Memory
Endurance: 1,000 Write/Erase Cycles
2.7 V to 6 V Operating Range
Fully Static Operation: 0 Hz to 24 MHz
Two-Level Program Memory Lock
128 x 8-Bit Internal RAM
15 Programmable I/O Lines
Two 16-Bit Timer/Counters
Six Interrupt Sources 12
5. ALGORITM
1. START
2. initialise lcd , keypad
3. clear lcd
4. print Enter lock code on lcd
5. get 5 char long password using matrix key pad
6. if input = 12345 then
6.1 print Enter master code
6.2 get 10 char long password using matrix key pad
6.3 if input = masterlock then
6.3.1 change user password
6.3.2 go to step 4
6.4 else
6.4.1 print wrong code on lcd
6.4.2 go to step 4
7. else
7.1 if input = userlock or input = default lock then
7.1.1 unlock the lock
7.1.2 retry count = 3
7.1.3 print # to lock on lcd
7.1.4 accept input using matrix key pad
7.1.5 if input = # then lock
7.1.6 goto step 4
7.2 else
7.2.1 decrement retry count
7.2.2 print wrong code on lcd
7.2.3 if retry count = 0 then sound alarm on
7.2.4 go to step 4
8. STOP
PROGRAM
Delay program:
#include "delay.h"
void delayus(unsigned char delay)
{
while(delay--);
}
void delayms(unsigned char delay)
{
while(delay--)
delayus(149);
}
Keypad program:
#include "keypad.h"
#include "delay.h"
bit keystatus = FALSE;
void keypad_init()
{
keyport &=0x0F;
}
unsigned char getkey ()
{
unsigned char i,j,k,key=0,temp;
k=1;
for(i=0;i<4;i++)
{
keyport &=~(0x80>>i);
temp = keyport;
temp &= 0x07;
if(7-temp)
{
if(!col1)
{
key = k+0;
while(!col1);
return key;
}
if(!col2)
{
key = k+1; 24
while(!col2);
return key;
}
if(!col3)
{
key = k+2;
while(!col3);
return key;
}
j++;
}
k+=3;
keyport |= 0x80>>i;
delayms(10);
}
return FALSE;
}
unsigned char translate(unsigned char keyval)
{ if(keyval<10)
return keyval+'
else if(keyval==10)
return 'x';
else if(keyval==11)
return '0';
else if(keyval==12)
return 'e';
}
LCD program:
#include "lcd.h"
#include "delay.h"
#include <REG2051.H>
unsigned char code lockicon[]={0xe, 0xa, 0x1f, 0x1f, 0x1b, 0x1b, 0xe, 0x0};
unsigned char code unlockicon[]={0xe, 0x2, 0x1f, 0x1f, 0x1b, 0x1b, 0xe, 0x0};
unsigned char code ex[]={0x1f, 0x1b, 0x1b, 0x1b, 0x1b, 0x1f, 0x1b, 0x1f};
unsigned char code ok[]={0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0, 0x0};
void lcd_reset()
{ lcd_port = 0xFF;
delayms(20);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
delayms(10);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
delayms(1);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
delayms(1);
lcd_port = 0x02+LCD_EN;
lcd_port = 0x02;
delayms(1);
}
void lcd_init ()
{ unsigned char i;
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift.
lcd_cmd(LCD_SETCGADDR);
for(i=0;i<8;i++)
lcd_data(lockicon[i]); 27
for(i=0;i<8;i++)
lcd_data(unlockicon[i]);
for(i=0;i<8;i++)
lcd_data(ex[i]);
for(i=0;i<8;i++)
lcd_data(for(i=0;i<8;i++)
lcd_data(unlockicon[i]);
for(i=0;i<8;i++)
lcd_data(ex[i]);
for(i=0;i<8;i++)
lcd_data(ok[i]);
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}
void lcd_cmd (char cmd)
{ lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN;
lcd_port = ((cmd >> 4) & 0x0F);
lcd_port = (cmd & 0x0F)|LCD_EN;
lcd_port = (cmd & 0x0F);
delayus(200);
delayus(200);
}
void lcd_data (unsigned char dat)
{ lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);
lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); lcd_port = ((dat & 0x0F)|
LCD_RS);
delayus(200);
delayus(200);
}
void lcd_str (unsigned char *str)
{ while(*str){
lcd_data(*str++);
}
}
Lock program:
#include "keypad.h"
#include "lcd.h"
#include "delay.h"
#include "lock.h"
unsigned char code masterlock[10]="1234567890", defaultulock[5]="54321";
unsigned char userlock[5], input[10];
extern bit newlock;
bit check(unsigned char *first, unsigned char *second, unsigned char len)
{
unsigned char i=0; lcd_str("Enter new code");
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(5);
if(status == TRUE){
lcd_cmd(LCD_CLS);
lcd_data(OK);
lcd_str("lock code saved!");
newlock = TRUE;
store_code();
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
}
else if(status == RETRY)
goto retry1;
else if(status == EXIT
goto exit;
}
else{
lcd_cmd(LCD_CLS);
lcd_str("WRONG CODE!");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
}
}
else if(status == RETRY)
goto retry;
else if(status == EXIT)
goto exit;
exit:;
}
char getinput(unsigned char max)
{ unsigned char i,key; i=0;
while(1){
while(!(key=getkey()));
key = translate(key);
input[i]=key;
if(key=='x'){
if(i==0)
return EXIT;
i--;
lcd_cmd(0xC2+i);
lcd_data(' ');
lcd_cmd(0xC2+i);
}
else if(key=='e')
{ return TRUE;
}
else{
i++;
if(i>max){
lcd_cmd(LCD_CLS); lcd_data(EX);
lcd_str(" Code too Long...");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
return RETRY;
}
lcd_data('*');
}}}
void store_code(){
unsigned char i;
for(i=0;i<5;i++)
userlock[i]=input[i];
}
Main program:
#include "lcd.h"
#include "keypad.h"
#include "lock.h"
#include "delay.h"extern unsigned char input[10], userlock[5];
extern unsigned char code defaultulock[5],masterlock[10];
bit newlock=FALSE;
unsigned char retrycount=3;
void main(){
unsigned char status,i=0;
bit lockstatus;
lcd_init();
keypad_init();
while(1){
lcd_cmd(LCD_CLS);
lcd_str("Enter lock code");
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(5);
if(check(input,"12345",5)){
setulock();if(check(input,masterlock,10)){
retrycount=3;
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_str("UNBLOCKED");
lcd_data(EX);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
}
else{
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_str("WRONG CODE");
lcd_data(EX);
delayms(250);
delayms(250);
delayms(250);
delayms(goto blocked;
}
}
}
}
done:;
}
}
Resistor:
Diode is a electronic device that allows the passage of current in only one
direction. The first such devices were vacuum-tube diodes, consisting of an
evacuated glass or steel envelope containing two electrodes a cathode and an
anode. The diodes commonly used in electronic circuits are semiconductor
diodes. There are different diodes used in electronic circuits such as Junction
diode, Zener diode, Photo diodes, and tunnel diode.
Junction diodes consist of junction of two different kinds of semiconductor
material. The Zener diode is a special junction type diode, using silicon, in
which the voltage across the junction is independent of the current through the
junction.
7.5 Integrated circuits
Regulator IC (LM 7805):
The LM7805 monolithic 3-terminal positive voltage regulators
employ internal current-limiting, thermal shutdown and safearea compensation, making them essentially indestructible. If
adequate heat sinking is provided, they can deliver over 1.0A
outputcurrent. They are intended as fixed voltage regulators in
a wide range of applications including local (on-card) regulation
for elimination of noise and distribution problems associated
with single-point regulation. In addition to use as fixed voltage
regulators, these devices can be used with external
components to obtain adjustable output voltages and currents.
Considerable effort was expended to make the entire series of
regulators easy to use and minimize the number of external
components. It is not necessary to bypass the output, although
this does improve transient response. Input bypassing is
needed only if the regulator is located far from the filter
capacitor of the power supply. Features: Complete
specifications at 1A load Output voltage tolerances of 2%
at Tj = 25 Line regulation of 0.01% of VOUT/V of VIN at 1A
load Load regulation of 0.3% of VOUT/A Internal thermal
overload protection Internal short-circuit current limit
Output transistor safe area protection
*PCB FABRICATION
The first step of assembling is to produce a printed circuit
board. The fabrication of the program counter plays a crucial
role in the electronic field. The success of the circuit is also
dependent on the PCB. As far as the cost is concerned, more
than 25% of the total cost is for the PCB design and fabrication.
The board is designed using a personal computer. The layout is
drawn using the software Adobe PageMaker 6.5. The layout is
printed in a buffer sheet using a laser procedure. First, a
negative screen of the layout is prepared with the help of a
professional screen printer. Then the copper clad sheet is kept
under this screen. The screen printing ink is poured on the
screen and brushed through the top of the screen. The printed
board is kept under shade for few hours till the ink becomes
dry.
The etching medium is prepared with the un-hydrous ferric
chloride water. The printed board is kept in this solution till the
exposed copper dissolves in the solution fully. After that the
board is taken out and rinsed in flowing water under a tap. The
ink is removed with solder in order to prevent oxidation.
Another screen, which contains component side layout, is
prepared and the same is printed on the component side of the
board. A paper epoxy laminate is used as the board. Both the
component and the track layout of the peripheral PCB is given
at the end of this report.
APPLICATIONS
Our electronic door lock performed as expected. We were able
to implement all the functions specified in our proposal. The
biggest hurdle we had to overcome with this project was
interfacing the micro controller with the hardware components.
We feel that this electronic door lock is very marketable
because it is easy to use, comparatively inexpensive due to low
power consumption, and highly reliable. This door lock is
therefore particularly useful in applications such as hotel room
door locks, residential housing, and even office buildings.
11. CONCLUSION
This project is meant for security systems whose access is only for respected
authorities. Using a microcontroller the password entered is checked with the
stored password and then does the corresponding operations. Here we use a 5
digit password for better secrecy.
12. REFERENCES
Electronic circuits and devices: J.B. Gupta.
Op-amps and linear integrated circuits: Ramakanth A. Gayakward
Integrated circuits : K.R. Botkar
The 8051 microcontrollers: Muhammed Ali Mazidi