Sie sind auf Seite 1von 18

Abstract

The microcontroller based Door locker is an access control


system that allows only authorized persons to access a
restricted area. The system is fully controlled by the 8 bit
microcontroller AT89s52 which has 8Kbytes of Flash memory
for the program memory. The password is stored in the
EEPOROM ic AT24C04 so that the password can be modified at
any time. The system has a Keypad by which the password can
be entered . When the entered password equals with the
password stored in the memory then a control signal is given for
the door to be opened and a visual indication is provided in the
lcd display opened.The user is given three attempts to enter the
password after which the system locks itself up requiring a
hardware reset

Circuit components

AT89s52 microcontroller
LCD display
4*3 keypad
EEPROM AT24c04
7805 voltage regulator
8051 programmer
LEDs,resistors,connection wires

AT89S52 Microcontroller
The AT89S52 is an 8 bit microcontroller and belongs to Atmels 8051
family, it is a low-power, high-performance CMOS 8-bit microcontroller
with 8K bytes of in-system programmable Flash memory and is
compatible with the industrystandard 80C51 instruction set and pinout.The on chip flash memory
allows the chip to be programmed by an in system programmer

LCD display
LCD (Liquid Crystal Display) screen is an electronic display module and
find a wide range of applications. A 16x2 LCD display is very basic
module and is very commonly used in various devices and circuits. These
modules are preferred over seven segments and other multi
segment LEDs. The reasons being: LCDs are economical; easily
programmable; have no limitation of displaying special & even custom
characters (unlike in seven segments), animations and so on.
A 16x2 LCD means it can display 16 characters per line and there are 2
such lines. In this LCD each character is displayed in 5x7 pixel matrix

4*3 Keypad

Keypads are widely used input devices being used in various electronics
and embedded projects. They are used to take inputs in the form
of numbers and alphabets, and feed the same into system for further
processing. To avoid using up too many pins of the microcontroller, the
keyboard is connected using an interfacing technique that connects the
keys in a 4*3 matrix, shorting all the rows and all columns together

EEPROM AT24C04
AT24C04 is a two wire 4Kbits serial EEPROM by Atmel. The memory is
organized in 256 words of single byte each arranged in 32 pages of 16
bytes each. AT24C04 is two-wire serially programmable i.e., for
programming, the data and control signals are provided serially along
with clock signals from the other wire. The read-write operations are
accomplished by sending a set of control signals including the address
and/or data bits. The control signals must be accompanied with proper
clock signals.

8051 programmer

A USB ASP programmer is used for in system programming of the


microcontroller.The programmer has been specifically loaded with the
firmware required for 8051 programming and it uses the SPI protocol for
programming flashing

Block schematic
Indicator LEDS

P1_0-P1_6

AT89S52

AT24C04

P0

P2_6,P2_7
P2_0-P2_5

4*3 matrix keypad


LCD Module

Program Code
// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
sbit sda at P2_6_bit;
sbit scl at P2_7_bit;

sbit servo at P0_0_bit;


sbit tled at P0_1_bit;

sbit rled at P0_4_bit;

sbit gled at P0_5_bit;


//keypad

sbit Rw1 at P1_0_bit;


sbit Rw2 at P1_1_bit;
sbit Rw3 at P1_2_bit;
sbit Rw4 at P1_3_bit;
sbit C1 at P1_4_bit;
sbit C2 at P1_5_bit;
sbit C3 at P1_6_bit;
//

bit ack;

unsigned char read,i,iter;


unsigned char d[8];

unsigned int c=0,d_state;


char pkey;

unsigned char cdata[8],np[8]={'1','2','3','4','5','6','7','8'};

char auth=0,authadmn=0;

void Timer1_interrupt() iv IVT_ADDR_ET1 ilevel 0 ics ICS_AUTO {


EA_bit = 0;

TR1_bit=0;

TH1=0xFF;
TL1=0xD1;
//P0=0xFF;
c++;

if(c<=40)

servo=1;

else if(c<=401)

servo=0;

else if(c>=402)
c=0;

EA_bit=1;

TR1_bit=1;

void Timer0_interrupt() iv IVT_ADDR_ET0 ilevel 0 ics ICS_AUTO {


EA_bit = 0;

TR0_bit=0;

TH0=0xF0;
TL0=0x00;
//P0=~P0;
c++;

//if(c%2==0)
P0=~P0;

EA_bit=1;

TR0_bit=1;

void ackn()
{

scl=1;

asm nop;
asm nop;
scl=0;
}

void start()
{

sda=1;
scl=1;

asm nop;
asm nop;
sda=0;

asm nop;
scl=0;
}

void stop()
{

sda=0;
scl=1;

asm nop;
asm nop;
sda=1;

asm nop;
scl=0;
}

void send_byte(unsigned char value)


{

unsigned int i;

unsigned char send;


send=value;

for(i=0;i<8;i++)
{

sda=send/128;

send=send<<1;
scl=1;

asm nop;
asm nop;
scl=0;

asm nop;
ack=sda;
sda=0;

unsigned char read_byte()


{

unsigned int i;
sda=1;

read=0;

for(i=0;i<8;i++)
{

read=read<<1;
scl=1;

asm nop;
asm nop;

if(sda==1)
read++;
scl=0;

sda=0;

return read;

void save_pwd()
{

start();

send_byte(0xA0);
ackn();

send_byte(0x00);//word address
ackn();

send_byte(np[0]); //data
ackn();

send_byte(np[1]);
ackn();

send_byte(np[2]);
ackn();

send_byte(np[3]);
ackn();

send_byte(np[4]);
ackn();

send_byte(np[5]);
ackn();

send_byte(np[6]);
ackn();

send_byte(np[7]);
ackn();
stop();

if(ack==0)
{

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,3,"pwd svd");

// Lcd_Out(1,3,"71325602");
Delay_ms(500);

ackn();

void read_pwd(){
start();

send_byte(0xA0);
ackn();

send_byte(0x00);
ackn();
start();

send_byte(0xA1);
ackn();

d[0]=read_byte();
ackn();

d[1]=read_byte();
ackn();

d[2]=read_byte();
ackn();

d[3]=read_byte();
ackn();

d[4]=read_byte();
ackn();

d[5]=read_byte();
ackn();

d[6]=read_byte();
ackn();

d[7]=read_byte();
ackn();
stop();

Lcd_Cmd(_LCD_CLEAR);

// Lcd_Out(1,3,d);

//Delay_ms(5000);
}

char txt3[] = "Hello ";

unsigned char txt4[] = "world!!";


char getpwd();

char Read_Keypad()
{

C1=1;
C2=1;
C3=1;

Rw1=0;
Rw2=1;
Rw3=1;
Rw4=1;

if(C1==0){Delay_ms(100);while(C1==0);return '1';}
if(C2==0){Delay_ms(100);while(C2==0);return '2';}
if(C3==0){Delay_ms(100);while(C3==0);return '3';}
Rw1=1;
Rw2=0;
Rw3=1;
Rw4=1;

if(C1==0){Delay_ms(100);while(C1==0);return '4';}
if(C2==0){Delay_ms(100);while(C2==0);return '5';}
if(C3==0){Delay_ms(100);while(C3==0);return '6';}

Rw1=1;
Rw2=1;
Rw3=0;
Rw4=1;

if(C1==0){Delay_ms(100);while(C1==0);return '7';}
if(C2==0){Delay_ms(100);while(C2==0);return '8';}
if(C3==0){Delay_ms(100);while(C3==0);return '9';}
Rw1=1;
Rw2=1;
Rw3=1;
Rw4=0;

if(C1==0){Delay_ms(100);while(C1==0);return '*';}

if(C2==0){Delay_ms(100);while(C2==0);return '0';}
if(C3==0){Delay_ms(100);while(C3==0);return '#';}

return 0;

// to store a new 8 digit password to memory


void readnpwd()
{

iter=0;

while(iter<8){

while(!(pkey=Read_Keypad()));

if(iter==0)

Lcd_cmd(_LCD_CLEAR);

Lcd_chr(1,iter+1,'*');
np[iter]=pkey;
iter++;
}

Delay_ms(1000);

save_pwd();

Lcd_cmd(_LCD_CLEAR);
}

Lcd_Out(1,1,"Password reset");

char adminmode()
{

Lcd_cmd(_LCD_CLEAR);

Lcd_Out(1,1,"Enter password");

Lcd_Out(2,1,"for admin mode");


//authadmn=getpwd();
if(authadmn==1)
{

//enter new password


readnpwd();

return 1;

getpwd() // read user password


{

iter=0;

while(iter<8){

while(!(pkey=Read_Keypad()));

if(iter==0)
{

Lcd_cmd(_LCD_CLEAR);

Lcd_chr(1,iter+1,'*');
cdata[iter]=pkey;
iter++;
}

iter=0;

while(iter<=7)
{

if(d[iter]!=cdata[iter])
{

Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"incorrect");
rled=0;

gled=1;

Delay_ms(1000);
tled=1;
break;

if(iter==7)
{

Lcd_cmd(_LCD_CLEAR);

Lcd_Out(1,1,"Access Granted !!");

rled=1;

gled=0;

Delay_ms(100);

tled=0;
break;

iter++;

unsigned char count=0;


void main()
{

rled=0;

gled=1;

do
{

tled=0;

read_pwd();

Delay_ms(1000);

//print current password


Lcd_Out(1,1,d);

Delay_ms(1000);
tled=1;

Lcd_Init();

// Initialize Lcd

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,"Digital");

Lcd_Out(2,5,"Door Lock");
Delay_ms(1000);

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1,1,"Enter password");

// Clear display

// Cursor off

// Write text in first row


// Write text in second row

Lcd_Out(2,1, "to open");

getpwd();

while(!(pkey=Read_Keypad()));
count++;

}while(count<4);

//Lcd_Cmd(_LCD_CLEAR);

// Lcd_Out(1,2,"No more tries");

while(1)
{rled=0;
gled=0;

Delay_ms(1000);
rled=1;gled=1;

Delay_ms(1000);
}

References
www.mikroe.com/downloads/get/30/mikroc_pic_pro_manual_v101.p
df
http://www.atmel.com/devices/at89s52.aspx
www.atmel.com/Images/doc0180.pdf

http://www.engineersgarage.com/microcontroller/8051projects/elec
tronic-code-lock-with-password-using-at89c51-circuit

Das könnte Ihnen auch gefallen