You are on page 1of 14

SALAUDEEN ILIASU OLAYIWOLA

ADI2
ELECTRONIC CODE LOCK REPORT

SCHEMATIC DIAGRAM FROM PROTEUS

C1
U1
1

22nF 19 39
XTAL1 P0.0/AD0
X1 P0.1/AD1
38
CRYSTAL 37
C2 P0.2/AD2
18 36
XTAL2 P0.3/AD3
2

35
P0.4/AD4
34
P0.5/AD5
22nF 33
P0.6/AD6
9 32
RST P0.7/AD7
21 LCD1
P2.0/A8 +12v LM016L
22
P2.1/A9
23
P2.2/A10
29 24
PSEN P2.3/A11
30 25
ALE P2.4/A12 RV1
31 26
EA P2.5/A13
27
P2.6/A14
28
P2.7/A15
93%

VDD
VSS

VEE

1 10
RW
RS

D0
D1
D2
D3
D4
D5
D6
D7
P1.0 P3.0/RXD
E
2 11
P1.1 P3.1/TXD
3 12
P1.2 P3.2/INT0
1
2
3

4
5
6

7
8
9
10
11
12
13
14
4 13 10k
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
P1.5 P3.5/T1
7 16
P1.6 P3.6/WR
8 17
P1.7 P3.7/RD
GND
80C51

A
1 2 3 A
B
4 5 6 B
TITLE: DATE:
C
7 8 9 C CODE_DOOR_LOCK
07/06/2017
D
* 0 # D BY:
SALAUDEEN ILIASU
1 2 3 4
ELECTRONIC CODE LOCK
This is a microcontroller-based system using AT89C51AC2, a 16x2 standard LCD
and 4x4 matrix display.
This task is sub-divided into three parts; first is testing the LCD to print Hello
World!, secondly testing the keypads with LEDs and finally combining both parts
together to make an electronic code lock.
TESTING THE LCD TO PRINT Hello World!
In this task, the LCD data pins are connected to port 0 of the 8051; below is a picture
of the system.
The LCD displays Hello World! as soon as the power supply is connected. The
characters appears one after the other.

Figure 1 LCD test "Hello World!"

The code for this task will also later be attached to the document.
CODE
#include<reg51.h>
#define lcd_data_pins P0
#define null 0
#define clear_screen 0x01
#define line2pos5 0xC5
sbit rs=P2^0;
sbit rw=P2^2;
sbit e=P2^1;
bit cmd=0;
bit dat=1;
bit write=0;
bit high=1;
bit low=0;
code unsigned char lcd_init[]={0x38,0x0C,0x01,0x81,null};
code unsigned char message_1[]="Hello";
code unsigned char message_2[]="World!";
void lcd_string_send(unsigned char *ptr,bit register_select);
void lcd_char_send(unsigned char value,bit register_select);
void delay_s(unsigned char itime);
void delay_l(unsigned char itime);
void main(void)
{
lcd_string_send(lcd_init,cmd);
lcd_string_send(message_1,dat);
lcd_char_send(line2pos5,cmd);
lcd_string_send(message_2,dat);
//stop here!!!, used for debugging purposes.
while(1){};
//continue code here!!!
while(1)
{
}
}
//send a series of characters to lcd, stored in an array
void lcd_string_send(unsigned char *ptr,bit register_select)
{
while(*ptr != null)
{
lcd_char_send(*ptr,register_select);
ptr++;
}
}
//send individual characters to lcd
void lcd_char_send(unsigned char value,bit register_select)
{
lcd_data_pins=value;
rs=register_select;
rw=write;
e=high;
delay_s(100);
e=low;
delay_l(5);
}
//short delay
void delay_s(unsigned char itime)
{
unsigned char outer,inner;
for(outer=0;outer<itime;outer++)
for(inner=0;inner<255;inner++);
}
//long delay
void delay_l(unsigned char itime)
{
unsigned char outer,center,inner;
for(outer=0;outer<itime;outer++)
for(center=0;center<50;center++)
for(inner=0;inner<255;inner++);
}
TESTING THE KEYPAD WITH LEDS
Hexadecimal value equivalent to ASCII numbers of Key pressed is displayed on
LEDs connected to Port 0 as shown in the figures below. The keypad is connected to
Port 1 and LEDs to Port 0.

Figure 2 Kpd with Leds

Figure 3 Kpd with leds


Figure 4 Kpd with leds

Figure 5 Kpd with leds

CODE FOR THIS PROGRAM


#include<reg51.h>
//Define ports for easier reading
#define LEDs P0
#define keypd P1
//Prototype Functions
void MSDelay(unsigned int itime);
unsigned char key(void);
//Keyboard Array - Physical Map
// [y],[x]
unsigned char keypad[4][4] = {'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'*','0','#','D'};
//Main Function
void main(void)
{
unsigned char entry;
while(1)
{
//get key pressed
entry=key();
//complement
entry=~entry;
//display key pressed
P0=entry;
//stop here
//while(1){};
}
}
//keyboard routine.
unsigned char key()
{
unsigned char entry;
unsigned char colloc,rowloc;
//make P1 upper nibble an i/p
keypd=0xF0;
do
{
//ground ALL rows @ once
keypd=0xF0;
//read the columns
colloc = keypd;
//mask used bits lower nibble
colloc &= 0xF0;
}
//check until ALL keys released
while (colloc != 0xF0);
do
{
do
{
//call delay
MSDelay(20);
//see if any key is pressed
colloc = keypd;
//mask unused bits lower nibble
colloc &= 0xF0;
}

//keep checking for keypress


while (colloc == 0xF0);
//call delay for debounce
MSDelay(20);
//read columns
colloc = keypd;
//mask unused bits
colloc &= 0xF0;
}
//wait for keypress
while (colloc == 0xF0);
while (1) {
//ground row 0
keypd=0xFE;
//read columns
colloc=keypd;
//mask unused bits
colloc &= 0xF0;
//column detected
if (colloc != 0xF0) {
//save row location
rowloc=0;
//exit while loop
break;
}
//ground row 1
keypd=0xFD;
//read columns
colloc=keypd;
//mask unused bits
colloc &= 0xF0;
//column detected
if (colloc != 0xF0) {
//save row location
rowloc=1;
//exit while loop
break;
}
//ground row 2
keypd=0xFB;
//read columns
colloc=keypd;
//mask unused bits
colloc &= 0xF0;
//column detected
if (colloc != 0xF0) {
//save row location
rowloc=2;
//exit while loop
break;
}
//ground row 3

keypd=0xF7;
//read columns
colloc=keypd;
//mask unused bits
colloc &= 0xF0;
//column detected
if (colloc != 0xF0)
{
//save row location
rowloc=3;
//exit while loop
break;
}
}
//Check column and return result
while(1)
{
if (colloc == 0xE0)
{
entry=(keypad[rowloc][0]);
break;
}
else if (colloc == 0xD0)
{
entry=(keypad[rowloc][1]);
break;
}
else if (colloc == 0xB0)
{
entry=(keypad[rowloc][2]);
break;
}
else
{
entry=(keypad[rowloc][3]);
break;
}
}
return (entry);
}
void MSDelay(unsigned int itime)
{
unsigned int x,y;
for (x=0;x<itime;x++)
for (y=0;y<190;y++);
}
ELECTRONIC CODE LOCK
This system allows the user to enter an 8-digit long password. It grants access to the
user only if the password entered matches the predefined password else it declines.
In this project, the LCD data pins (D0D7) are connected to Port 0, the control pins
(RS, R/W, E) to Port 2 and the Keypad to Port 1 of the microcontroller. Also, a 10K
potentiometer is connected to the LCD to vary the brightness of the screen.
The microcontroller is operated on +5V DC power supply and a frequency of
18.432Hz in this project. The LCD takes a voltage of 4.55V
PROCESSES
1. When the power supply is given to the microcontroller, the LCD initially
displays Welcome back!, after a long delay it then prints Enter Password:
as shown in Fig. 2 below
2. The user then enters an 8-digits password which is displayed by * to protect
the privacy of the password;
3. If the password entered matches the predefined password, the LCD displays
Correct Password, then Access Granted! after some delay.
4. If the password entered does not match, the LCD displays Incorrect
Password!, then Access Denied! and then TRY AGAIN! after some delay.
5. And then the process repeats itself from the beginning in a loop.
HARDWARE DIAGRAM OF THE SYSTEM

Figure 6 Hardware diagram of system


FLOWCHART OF THE SYSTEM
LCD
MAIN A displays
B
Incorrect
Password!
LCD
LCD displays
displays
Welcome Back!
Correct
Password Delay_L

Delay_L
LCD
Delay_L
displays
Access
LCD displays Enter Denied!
Password: LCD displays
Access
Granted!
User enters keys one Delay_L
after the other
RETURN
LCD
Each key entered is stored displays
TRY
AGAIN!

LCD displays * for


each key entered
RETURN

Is key > NO
7-digit?

YES

Check if password match

NO
Matched B
?

YES

A
DELAY_L

Initialise
variable i at 0

Initialise
variable j at 0

Initialise
variable k at 0

Increment variable k

Is YES
k<255?

NO

Increment variable j

YES
Is
j<50?

NO

Increment variable i

Is
i<itime?

RETURN

You might also like