0% found this document useful (0 votes)
55 views

Automatic Door System Using Password and Rfid Card

This system provides users with two options to unlock the door: entering a password or scanning a card. If the correct password is entered, the system will give users the option to change the password. However, users are only allowed a maximum of three attempts to enter the password or scan the card. If this limit is exceeded, the system will activate an alarm to alert the possibility of a thief attempting to break in.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Automatic Door System Using Password and Rfid Card

This system provides users with two options to unlock the door: entering a password or scanning a card. If the correct password is entered, the system will give users the option to change the password. However, users are only allowed a maximum of three attempts to enter the password or scan the card. If this limit is exceeded, the system will activate an alarm to alert the possibility of a thief attempting to break in.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

CONTENTS

CATEGORY OF FIGURE.............................................................................................IV

CATEGORY OF TABLE................................................................................................V

LIST OF ACRONYMS...................................................................................................VI

CHAPTER 1. OVERVIEW OF TOPIC..........................................................................1

1.1 INTRODUCTION TO THE TOPIC........................................................................................1


1.2 RESEARCH SUBJECTS..................................................................................................1
1.3 RESEARCH SCOPE.......................................................................................................1
1.4 EXPECTED RESULTS....................................................................................................1

CHAPTER 2. THEORETICAL BASIC..........................................................................3

2.1 MICROCONTROLLERS.................................................................................................3
2.2 RFID APPLICATION.............................................................................................13
2.3 KEYPAD (3X4)..........................................................................................................15
2.4 LIQUID-CRYSTAL DISPLAY (LCD)...........................................................................16
2.5 ELECTROMAGNETIC DOOR LOCK..............................................................................18

CHAPTER 3. BLOCK DIAGRAM AND CONTROL ALGORITHMS....................20

3.1 BLOCK DIAGRAM..........................................................................................................20


3.2 CONTROL ALGORITHMS...............................................................................................21

CHAPTER 4. CIRCUIT DESIGN AND MODEL CONSTRUCTION......................22

4.1 CIRCUIT DESIGN......................................................................................................22


4.1.1 Principle diagram.................................................................................................22
4.1.2 PCB layout............................................................................................................23
4.1.3 Actual circuit.........................................................................................................24
4.2.2 Complete project...................................................................................................25

CHAPTER 5. EXPERIMENT........................................................................................26
5.1 EXPERIMENTAL PROGRESS.......................................................................................26
5.2 EXPERIMENTAL RESULTS..........................................................................................26

CHAPTER 6. OUTCOME..............................................................................................34

6.1 ADVANTAGES...............................................................................................................34
6.2 DISADVANTAGES..........................................................................................................34
6.3 DEVELOPMENT.............................................................................................................35

PROGRAM 36
CATEGORY OF FIGURE

1- Pic 16F877a---------------------------------------------------------------------------------4
2- PIC16F877A General Structure----------------------------------------------------------5
3- RDM 6300---------------------------------------------------------------------------------14
4- Matrix keypad-----------------------------------------------------------------------------15
5- LCD 1602A------------------------------------------------------------------------------- 16
6- ASCII CODE TABLE FOR LCD------------------------------------------------------17
7- Electromagnetic door lock---------------------------------------------------------------18
8- Principle diagram on Proteus-----------------------------------------------------------22
9- PCB layout-------------------------------------------------------------------------------- 23
10- Actual circuit---------------------------------------------------------------------------- 23
11- Actual circuit---------------------------------------------------------------------------- 24
12- Complete mod---------------------------------------------------------------------------24
13-Main screen-------------------------------------------------------------------------------25
14- Enter the pass----------------------------------------------------------------------------26
15- Correct pass------------------------------------------------------------------------------26
16- Correct card------------------------------------------------------------------------------27
17- Incorrect pass----------------------------------------------------------------------------27
18- Incorrect card----------------------------------------------------------------------------28
19- Incorrectly more than 3 times---------------------------------------------------------29
20- Menu monitor----------------------------------------------------------------------------29
21- Change password------------------------------------------------------------------------29
CATEGORY OF TABLE

Table 1- Table pin of pic 16F877a..............................................................................5


LIST OF ACRONYMS

RFID: Radio Frequency Identification


PIC: Programmable Intelligent Computer
LCD: Liquid crystal display
PCB: Printed Circuit Board
PROJECT OF EMPLOYED SYSTEMS
Page 1/18

CHAPTER 1. OVERVIEW OF TOPIC

1.1 Introduction to the topic

This system provides users with two options to unlock the door: entering a
password or scanning a card. If the correct password is entered, the system will give
users the option to change the password. However, users are only allowed a
maximum of three attempts to enter the password or scan the card. If this limit is
exceeded, the system will activate an alarm to alert the possibility of a thief
attempting to break in.Research purposes
Utilizing the knowledge gained from the study of microcontrollers, I aim to develop
an automatic door opening system that incorporates both a password and magnetic
card function. The purpose of this system is to enhance safety and security measures
for door access.

1.2 Research subjects

Microcontroller PIC 16F877A, LCD 1602A, ELECTROMAGNETIC DOOR


LOCK, RDM 6300, MATRIX KEYPAD.

1.3 Research scope

Smart magnetic door with accurate processing and good security, ensuring safety
for households, offices or factories.

1.4 Expected results

The door access system mandates that users either input a password or scan a
magnetic card. Upon completing these actions, the LCD display will present one of
two statuses. If the user enters the correct password and successfully scans the card,
the LCD will exhibit a correct status message. However, if incorrect information is
entered or scanned, the LCD will show an error message and trigger the buzzer. If
PROJECT OF EMPLOYED SYSTEMS
Page 2/18

the number of allowed access attempts exceeds the maximum limit, an alarm siren
will blare. This automatic door opening system also facilitates the password change
function, providing users with an option to update their password as desired.
PROJECT OF EMPLOYED SYSTEMS
Page 3/18

CHAPTER 2. THEORETICAL BASIC

2.1 Microcontrollers

Microcontroller is a computer integrated on a chip, it is often used to control


electronic devices. A microcontroller, in essence, is a system consisting of a
microprocessor with sufficient performance and low cost (different from general-
purpose microprocessors used in computers) combined with peripheral blocks such
as a microprocessor. memory, input/output modules, digital-to-analog and analog-
to-digital conversion modules, etc. In computers, modules are usually built by chips
and external circuits.

Microcontrollers are commonly used to build embedded systems. It is also used in


electrical and electronic equipment such as washing machines, microwave ovens,
telephones, DVD players, multimedia equipment or automated production lines, etc.

The processor in this system is 16F877A.

PIC16F877A is a 40-pin PIC Microcontroller and is used mostly in embedded


projects and applications. It has five ports starting from port A to port E. It has three
timers of which two are 8-bit timers and one is 16-bit timers. It supports many
communication protocols such as serial protocol, parallel protocol, I2C protocol.
The PIC16F877A supports both hardware pin interrupts and timer interrupts.
PROJECT OF EMPLOYED SYSTEMS
Page 4/18

Figure 2.1- Pic 16F877a


PROJECT OF EMPLOYED SYSTEMS
Page 5/18

Figure 2.2- PIC16F877A General Structure

Table 1- Table pin of pic 16F877a

Pin Name Function

- / MCLR: Active low


reset
1 /MCLR/VPP
- VPP: programmable
voltage input

– RA0: input/output

2 RA0/AN0 number

– AN0 : analog input

– RA1: output/import

3 RA1/AN1 numbers

– AN1 : analog input

4 RA2/AN2/VREF-/CVREF – RA2: output/import


PROJECT OF EMPLOYED SYSTEMS
Page 6/18

numbers

– AN 2: analog input

– ON-: standard (low)


voltage input of the A/D
unit

– RA3: output/import
numbers

– AN3 : analog input


5 RA3/AN3/VREF+
– VREF+ : standard
(high) voltage input of
A/D . unit

– RA4: output/import
numbers

– TOCKI : external clock


6 RA4/TOCKI/C1OUT
input for timer0

– C1 OUT : 1 .
comparator output

7 RA5/AN4//SS /C2OUT – RA5: output/import


numbers

– AN4 : 4 . analog input

– SS : auxiliary SPI
selection input

– C2 OUT : 2 .
PROJECT OF EMPLOYED SYSTEMS
Page 7/18

comparator output

– RE0 : input and output


numbers

8 RE0//RD/AN5 – RD : control reading at


parallel branch port

– AN5 : analog input

– RE1 : output/import
numbers

9 RE1//WR/AN6 – WR : control writing at


parallel branch port

– AN6 : analog input

– RE2: export/import
numbers

– CS : Control selection
10 RE2//CS/AN7
chip at parallel branch
port

– AN7: analog input

11 VDD Power pin of PIC

12 VSS Ground pin

13 OSC1/CLKI External clock or quartz


oscillator input.

– OSC1 : quartz oscillator


input or external clock.
Schmit trigger input
PROJECT OF EMPLOYED SYSTEMS
Page 8/18

when configured in RC
mode; another way of
CMOS.

– CLKI: external pulse


source input. Always
associated with OSC1
functionality.

Clock or quartz oscillator


input

– OSC2 : Quartz
oscillator output. Connect
to quartz or resonator.
14 OSC2/CLKO
– CLKO: in RC mode,
the output of OSC2,
equals the frequency of
OSC1 and indicates the
speed of the instruction
cycle.

– RC0 : input/output
number

– T1OCO : 1 . Timer
15 RC0/T1 OCO/T1CKI
oscillator input

– T1CKI : Timer 1 .
external clock input

16 RC1/T1OSI/CCP2 – RC1 : output/import


PROJECT OF EMPLOYED SYSTEMS
Page 9/18

numbers

– T1OSI: Timer 1 .
oscillator input

– CCP2 : Capture 2 input,


compare 2 output, PWM2
. output

– RC2: output/import
numbers

17 RC2/CCP1 – CCP1 : Capture 1 input,


compare 1 output, PWM1
. output

– RC3: output/import
numbers

– SCK : synchronous
serial clock input/output
18 RC3/SCK/SCL
of SPI . mode

– SCL: synchronous
serial clock input/output
of I2C mode

– RD0: output/import
numbers
19 RD0/PSP0
– PSP0 : parallel branch
port data

20 RD1/PSP1 – RD1: output/import


PROJECT OF EMPLOYED SYSTEMS
Page 10/18

numbers

– PSP1 : parallel branch


port data

– RD2: output/import
numbers
21 RD2/PSP2
– PSP2 : parallel branch
port data

– RD3: output/import
numbers
22 RD3/PSP3
– PSP3: parallel branch
port data

– RC4: output/import
numbers

23 RC4/SDI/SDA – SDI: data to SPI

– SDA: export/import
data to I2C

– RC5: output/import

24 RC5/SDO numbers

– SDO: SPI output data

25 RC6/TX/CK – RC6: output/import


numbers

– TX: asynchronous
transmission USART
PROJECT OF EMPLOYED SYSTEMS
Page 11/18

– CK : USART
synchronous pulse

– RC7: output/import
numbers

– RX : get disagreement
26 RC7/RX/DT
USART

– DT : USART
synchronous data

– RD4: output/import
numbers
27 RD4/PSP
– PSP4: parallel branch
port data

– RD5: output/import
numbers
28 RD5/PSP5
– PSP5: parallel branch
port data

– RD6: output/import
numbers
29 RD6/PSP6
– PSP6: parallel branch
port data

– RD7: output/import
numbers
30 RD7/PSP7
– PSP7: parallel branch
port data
PROJECT OF EMPLOYED SYSTEMS
Page 12/18

31 VSS Ground pin

32 VDD Power pin of PIC

– RB0: output/import

33 RB0/INT numbers

– INT : external interrupt

34 RB1 Export/import number

35 RB2 Export/import number

– RB3: output/import
numbers
36 RB3
– ICPS . low voltage
programming enable pin

– Export/import numbers
37 RB4
– PortB interrupt

– Export/import numbers
38 RB5
– PortB interrupt

– RB6: output/import
numbers

– PGC : ICSP
39 RB6/PGC
programming clock and
differential circuit

– PortB interrupt

40 RB7/PGD – RB7: output/import


PROJECT OF EMPLOYED SYSTEMS
Page 13/18

numbers

– PGD: differential
circuit and ICSP
programming data

– PortB interrupt

2.2 RFID APPLICATION

RFID, short for Radio Frequency Identification, uses electromagnetic fields to


automatically identify and track objects equipped with special tags. Such
technology consists of an RFID tag, reader, and radio transmitter. Triggered by an
electromagnetic pulse, the queried RFID tag responds with a unique numeric value,
allowing objects, such as goods or equipment, to be tracked. Simply put, RFID is an
automated identification method that uses data storage devices and remote
communication.

An RFID tag comprises three integral components, including a chip that stores and
processes informational data, modulation and demodulation of radio frequency
signals, an antenna for signal reception and transmission, and a substrate. The RFID
tag's data is stored in EEPROM memory.

RFID tags come in three variations- passive, active, and battery-powered passive
tags. Active tags have a power source and can send data. Passive tags are usually
cheaper since they derive energy to power the IC from radio waves. RFID tags can
be read-only with a serial number, or read/write enabled, permitting the user to
write special data to the tag. Programmable tags can be written once and read
multiple times, while blank tags can be written with an electronic product code by
the user.
PROJECT OF EMPLOYED SYSTEMS
Page 14/18

When queried, RFID tags respond with their identifier (ID) information as well as
additional product or manufacturing data. Due to each RFID tag possessing a
unique serial number, an RFID system is designed to read multiple tags at once,
providing they are within the RFID reader's range.

Compact in its design, the RDM6300 RF 125kHz UART RFID transceiver module
is equipped with an RFID antenna, as well as transmission and reception circuits
utilizing the UART communication standard, set at a fixed Baudrate parameter of
9600, N, 8, 1. The accompanying RFID code will appear in the form of 10-digit
ASCII code, requiring users to select this specific encoding method in order to
accurately perceive the card code.

Figure 2.3- RDM 6300

2.3 Keypad (3x4)

A key matrix is a grouping of buttons arranged in a grid pattern that feature rows
and columns for connectivity. The total number of available buttons is determined
by multiplying the number of rows by the number of columns. In contrast, to
command twelve buttons, we typically need sixteen General Purpose Input/Ouput
PROJECT OF EMPLOYED SYSTEMS
Page 15/18

(GPIO) pins. However, by applying matrix keys, it's only necessary to utilize eight
GPIO pins instead.

Figure 2.4- Matrix keypad


PROJECT OF EMPLOYED SYSTEMS
Page 16/18

2.4 Liquid-Crystal Display (LCD)

Figure 2.5- LCD 1602A

The LCD 1602A Blue is a 1602 character LCD module with a blue backlight. It
uses a Hitachi HD44780 driver chip to display alphanumeric characters and
symbols. The module has 16 pins, with pin 1 being the Ground and pin 2 being the
Power supply voltage. Pin 3 indicates the Contrast adjustment, while pins 4-6 and
11-14 relate to data input and output (D4-D7) and control signals (RS, RW, E),
respectively. Pins 15 and 16 are designated for the backlight.

The module is commonly used in microcontroller projects for displaying


information such as text, numbers, and symbols. It operates on a supply voltage of
4.5V - 5.5V DC and can display 4 lines with a maximum of 20 characters per line.
It has an operating temperature range of -20°C to 70°C
PROJECT OF EMPLOYED SYSTEMS
Page 17/18

The LCD 1602A module is widely used in various applications such as vending
machines, ATMs, medical devices, and appliances for displaying system status and
data.

Figure 2.6- ASCII CODE TABLE FOR LCD


PROJECT OF EMPLOYED SYSTEMS
Page 18/18

2.5 Electromagnetic door lock

Figure 2.7- Electromagnetic door lock


An electromagnetic door lock is a type of lock mechanism that uses an electric
current to generate a magnetic field, which attracts a locking bolt and secures the
door or gate. Also known as magnetic locks, these devices are widely used in
commercial and industrial settings, as they provide a high level of security and ease-
of-use.
PROJECT OF EMPLOYED SYSTEMS
Page 19/18

The lock mechanism consists of two main components: the locking assembly and
the electromagnet. The locking assembly is installed on the door frame, and the
electromagnet is installed on the door itself. When an electric current is passed
through the electromagnet, it creates a powerful magnetic field that attracts the
locking bolt to the lock assembly, effectively securing the door.

One of the benefits of electromagnetic locks is that they are fail-safe, meaning they
will unlock automatically in the event of a power failure or emergency. They also
offer a high level of security, as they cannot be picked or tampered with easily. In
addition, they are easy to install and maintain, making them a popular choice for
many businesses and industries.

Electromagnetic door lock nees 12 Volt and 0.4 Ampere to work.


PROJECT OF EMPLOYED SYSTEMS
Page 20/18

CHAPTER 3. BLOCK DIAGRAM AND CONTROL ALGORITHMS

3.1 Block diagram

KEY PAD POWER 5V RDM 6300

PIC 16F877A
BUZZER

ELECTROMAGNETIC DOOR LOCK

POWER 12V
PROJECT OF EMPLOYED SYSTEMS
Page 21/18

3.2 Control Algorithms

START

INITIALIZATION
OF SYSTEM

INPUT PASSWORD CARD SCAN

CHECK PASS CORRECT CHECK CARD

ELECTROMAGNETIC
DOOR LOCK

INCORRECT INCORRECT
BUZZER

END
PROJECT OF EMPLOYED SYSTEMS
Page 22/18

CHAPTER 4. CIRCUIT DESIGN AND MODEL CONSTRUCTION

4.1 CIRCUIT DESIGN

4.1.1 Principle diagram

Figure 4.1 - Principle diagram on Proteus


PROJECT OF EMPLOYED SYSTEMS
Page 23/18

4.1.2 PCB layout

Figure 4.2- PCB layout

4.1.3 Actual circuit

Figure 4.3 - Actual circuit


PROJECT OF EMPLOYED SYSTEMS
Page 24/18

Figure 4.4 - Actual circuit

4.2.2 Complete project

Figure 4.5 - Complete mode


PROJECT OF EMPLOYED SYSTEMS
Page 25/18

CHAPTER 5. EXPERIMENT

5.1 Experimental progress

Step 1: Supply power to the circuit.


Step 2: Enter password or scan card.
Step 3: If correct, then the electromagnetic door lock is open.
Step 4: If password or RFID card incorrect, then the buzzer is active.
Step 6: After entering the correct password, then press "*" to relock.

5.2 Experimental results

Figure 5.1 8-Main screen


The monitor when system start, press “#” to enter menu or press any button except
“#” and “*” to enter password.
PROJECT OF EMPLOYED SYSTEMS
Page 26/18

Figure 5.2 - Enter the pass

The default password will be 6 numbers, it is: “111111”. When we in enter the
password program, we can't access by RFID.

Figure 5.3 - Correct pass


PROJECT OF EMPLOYED SYSTEMS
Page 27/18

When the password is correct, the LCD will be displayed. At this time the door will
be opened right then and don’t relock. If we want to relock, press “*”.

Figure 5.4 - Correct card

If we don't use a password to open the door, we can use a RFID card to do it
instead.
PROJECT OF EMPLOYED SYSTEMS
Page 28/18

Figure 5.5 - Incorrect pass

Figure 5.6 - Incorrect card


When we input wrong password and wrong card, the system will report an error and
reduce access to the system. When we try to access by wrong password or card 3
PROJECT OF EMPLOYED SYSTEMS
Page 29/18

times, buzzer will be Sound out.

Figure 5.6 - Incorrectly more than 3 times

When wrong 3 times, the system will automatically lock and alert the user.

Figure 5.8 - Menu monitor


PROJECT OF EMPLOYED SYSTEMS
Page 30/18

When we want to enter menu, press “#” after start system.

Figure 5.9 9- Change password

Press 1 to change password, first, enter current password, then input new password

Press 2 to add new card, first, enter current password, then touch new card.
PROJECT OF EMPLOYED SYSTEMS
Page 31/18

CHAPTER 6. OUTCOME

6.1 Advantages

Fasted security: The door locking system using PIC 16F877A provides enhanced
security compared to traditional lock systems, as it requires a specific code to
unlock the door. This code can only be accessed by authorized personnel.
Easy to use: The door locking system using PIC 16F877A is easy to use and can be
operated by anyone without requiring any special skills or training.
Saves time: The door locking system using PIC 16F877A saves time by eliminating
the need for traditional keys, which can be lost or misplaced. This searching the
time-consuming process of searching for or replacing lost keys.
Cost-effective: The door locking system using PIC 16F877A is cost-effective
compared to other high-security systems. It requires minimal maintenance and can
be easily installed.
Integration with other systems: The PIC 16F877A microcontroller used in the door
locking system can be easily integrated with other systems such as CCTV cameras,
alarms, and other security systems to create a comprehensive security system.

6.2 Disadvantages

Vulnerable to hacking: Electronic door locking systems, including those using PIC
16F877A, are vulnerable to hacking by individuals with the appropriate skills and
knowledge. If the system is not secured correctly, hackers can gain access to the
door code and override the system.
Power failure: A door locking system using PIC 16F877A relies on a continuous
power supply. In the event of a power failure, the system will not function, and
manual override or backup systems may be required to unlock the door.
PROJECT OF EMPLOYED SYSTEMS
Page 32/18

Maintenance: Electronic door locking systems require regular maintenance to


ensure they function correctly. This often involves replacing batteries or
components, which can be time-consuming and expensive.
Technical knowledge: The installation and maintenance of a door locking system
using PIC 16F877A require technical knowledge and expertise. Training and
support may be required for individuals to operate and maintain the system
effectively.
Initial setup: The initial setup of the system can be complex and may require
specialist knowledge or consulting services. This can add to the cost of the system.
Compatibility issues: The door locking system using PIC 16F877A may not be
compatible with all doors or locking mechanisms. Additional modifications or
components may be required to ensure the system functions correctly.

6.3 Development

In order to mitigate power failures following an unexpected issue, the system will
be reinforced with additional backup power. This modification enhances the
system's flexibility, ensuring a hassle-free user experience during outages.
PROJECT OF EMPLOYED SYSTEMS
Page 33/18

Program

Control program in C language


#include <16F877A.h>
#fuses NOWDT, PUT, HS, NOPROTECT, NOLVP
#device ADC=10
#use delay(crystal=8000000)

#define LCD_RS_PIN PIN_D0


#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D7
#define LCD_DATA5 PIN_D6
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D4

// dinh nghia ten cac phim bam


#define KEY0 0
#define KEY1 1
#define KEY2 2
#define KEY3 3
#define KEY4 4
#define KEY5 5
#define KEY6 6
#define KEY7 7
#define KEY8 8
#define KEY9 9
#define KEYSTAR 10
#define KEYHASH 11
#define NOKEY 12

#define KC1 PIN_B2


#define KC2 PIN_B1
#define KC3 PIN_B0
#define KR1 PIN_B4
#define KR2 PIN_B5
#define KR3 PIN_B6
PROJECT OF EMPLOYED SYSTEMS
Page 34/18

#define KR4 PIN_B7

// khai bao dinh nghia cac trang thai mach


#define STAMAIN 0
#define STAINPUTPASS 1
#define STAUNLOCK 2
#define STACHANGEPASS 3
#define STAMENU1 4
#define STAADDRFID 5

#include <main.h>
#include <lcd.c>
#use rs232(UART1,baud=9600,parity=N,bits=8,stream=UART_PORT,errors)

int8 CurrentState=STAMAIN; // Bien luu trang thai cua mach hien tai
int8 NextState=STAMAIN; // Bien luu trang thai cua mach tiep theo

int8 CurrentKey; //bien luu gia tri phim bam


int8 CurrentCodeIndex; //vi tri so hien tai
int8 CurrentPass[6]; // bien luu ma hien tai

int8 AdminPass[6]={1,2,3,4,5,6};
char RFIDAdmin[10]={'a','b','c','d','e','f','g','h','i','k'};

int8 WrongPassCount=0;
int8 WrongRFIDCount=0;

char UARTBuffer[70];
int8 ByteCount=0;
int8 RFIDResult=0; //=0 khong co the, =1 the hop le admin , =2 the khong hop le

void WritePassEEPROM()
{
write_eeprom(0, AdminPass[0]);
PROJECT OF EMPLOYED SYSTEMS
Page 35/18

write_eeprom(1, AdminPass[1]);
write_eeprom(2, AdminPass[2]);
write_eeprom(3, AdminPass[3]);
write_eeprom(4, AdminPass[4]);
write_eeprom(5, AdminPass[5]);
}

void WriteRFID()
{
write_eeprom(15, RFIDAdmin[0]);
write_eeprom(16, RFIDAdmin[1]);
write_eeprom(17, RFIDAdmin[2]);
write_eeprom(18, RFIDAdmin[3]);
write_eeprom(19, RFIDAdmin[4]);
write_eeprom(20, RFIDAdmin[5]);
write_eeprom(21, RFIDAdmin[6]);
write_eeprom(22, RFIDAdmin[7]);
write_eeprom(23, RFIDAdmin[8]);
write_eeprom(24, RFIDAdmin[9]);

}
void ReadRFID()
{
RFIDAdmin[0]=read_eeprom(15);
RFIDAdmin[1]=read_eeprom(16);
RFIDAdmin[2]=read_eeprom(17);
RFIDAdmin[3]=read_eeprom(18);
RFIDAdmin[4]=read_eeprom(19);
RFIDAdmin[5]=read_eeprom(20);
RFIDAdmin[6]=read_eeprom(21);
RFIDAdmin[7]=read_eeprom(22);
RFIDAdmin[8]=read_eeprom(23);
RFIDAdmin[9]=read_eeprom(24);

void ReadPassfromEEPROM()
PROJECT OF EMPLOYED SYSTEMS
Page 36/18

int8 EEPROMData;
// doc pass phu 1
EEPROMData=read_eeprom(0);
if(EEPROMData==0xFF) // ROM trang khong co du lieu
{
WritePassEEPROM();// ghi gia tri mac dinh vao eeprom
}
else // neu rom co du lieu thi doc ma mat ma luu vao mang
{

AdminPass[0]=read_eeprom(0);
AdminPass[1]=read_eeprom(1);
AdminPass[2]=read_eeprom(2);
AdminPass[3]=read_eeprom(3);
AdminPass[4]=read_eeprom(4);
AdminPass[5]=read_eeprom(5);
}

int8 ScanKeyboard(void)
{
output_low(KC1);
if(!input(KR1))
{
while(!input(KR1));
delay_ms(10);
return KEY1;
}

if(!input(KR2))
{
while(!input(KR2));
PROJECT OF EMPLOYED SYSTEMS
Page 37/18

delay_ms(10);
return KEY4;
}

if(!input(KR3))
{
while(!input(KR3));
delay_ms(10);
return KEY7;
}

if(!input(KR4))
{
while(!input(KR4));
delay_ms(10);
return KEYSTAR;
}

output_high(KC1);
output_low(KC2);

if(!input(KR1))
{
while(!input(KR1));
delay_ms(10);
return KEY2;
}

if(!input(KR2))
{
while(!input(KR2));
delay_ms(10);
return KEY5;
}

if(!input(KR3))
{
while(!input(KR3));
PROJECT OF EMPLOYED SYSTEMS
Page 38/18

delay_ms(10);
return KEY8;
}

if(!input(KR4))
{
while(!input(KR4));
delay_ms(10);
return KEY0;
}

output_high(KC2);
output_low(KC3);

if(!input(KR1))
{
while(!input(KR1));
delay_ms(10);
return KEY3;
}

if(!input(KR2))
{
while(!input(KR2));
delay_ms(10);
return KEY6;
}

if(!input(KR3))
{
while(!input(KR3));
delay_ms(10);
return KEY9;
}

if(!input(KR4))
{
while(!input(KR4));
PROJECT OF EMPLOYED SYSTEMS
Page 39/18

delay_ms(10);
return KEYHASH;
}

output_high(KC3);
return NOKEY;

void OnBuzzer()
{
output_high(PIN_C2);// Mo Loa
}

void OffBuzzer()
{
output_Low(PIN_C2);// tat Loa
}

void Beep(int BeepCount) // phat tieng pip theo so lan


{
int i;
for(i=0;i<BeepCount;i++)
{
OnBuzzer();
delay_ms(200);
OffBuzzer();
delay_ms(200);
}
}

void LockGate()//khoa cua


{
Output_low(PIN_C1);
}
PROJECT OF EMPLOYED SYSTEMS
Page 40/18

void UnLockGate() // mo hoa


{
Output_high(PIN_C1);
}

int8 CheckPass() // ham kiem tra mat ma, ket qua tra ve 0 - mat ma sai, tra ve 1 mat ma dung
{

int i;
for(i=0;i<6;i++) // kiem tra pass add min
{
if(CurrentPass[i]!=AdminPass[i]) // neu phat hien 1 mat ma sai thi thoat vong lam
{
return 0;
}
}

return 1;

void ResetInput() // ham reset du lieu dang nhap


{
CurrentCodeIndex=0;
CurrentPass[0]=0xFF;
CurrentPass[1]=0xFF;
CurrentPass[2]=0xFF;
CurrentPass[3]=0xFF;
CurrentPass[4]=0xFF;
CurrentPass[5]=0xFF;
}

void DisplayMain()
{
lcd_putc("\f");
lcd_putc("KHOA MAT MA-RFID");
lcd_gotoxy(1, 2);
PROJECT OF EMPLOYED SYSTEMS
Page 41/18

lcd_putc(" BAM # vao Menu ");


}

void DisplayInputPass()
{
lcd_putc("\f");
lcd_putc(" NHAP MAT MA");
lcd_gotoxy(1, 2);

void DisplayMenu1()
{
lcd_putc("\f");
lcd_putc("1.DOI PASS");
lcd_gotoxy(1, 2);
lcd_putc("2.DOI THE RFID");
}

void DisplayChangePass()
{
lcd_putc("\f");
lcd_putc("NHAP PASS MOI");
lcd_gotoxy(1, 2);
}

void DisplayAddRFID()
{
lcd_putc("\f");
lcd_putc("CHAM THE RFID MOI");
lcd_gotoxy(1, 2);
}

void ClearUARTBuffer()
{
PROJECT OF EMPLOYED SYSTEMS
Page 42/18

ByteCount=0;
}

void ProcessRFID()
{
int8 i;

RFIDResult=1; // gia su la the dung


for(i=3;i<11;i++) // check tu byte thu 3 vi 3 byte dau ngau nhien loi du lieu
{
if(UARTBuffer[i]!=RFIDAdmin[i-1]) // neu kiem tra khong dung 1 ky tu thi set the khong dung
{
RFIDResult=2; // the khong hop le
}
}

delay_ms(100);
ClearUARTBuffer();

#INT_RDA
void RDA_isr(void)
{
char c = getc();
UARTBuffer[ByteCount]=c;
ByteCount++;
if(ByteCount==13)
{
ByteCount=0;
ProcessRFID();
}
else if(ByteCount>69)
PROJECT OF EMPLOYED SYSTEMS
Page 43/18

{
ByteCount=0;
}
}

void main()
{

int8 CheckPassResult;

SET_TRIS_D(0x00);
SET_TRIS_C(0x80); // uart
Set_tris_B(0xF0);// cai dat port B 0-3 output, 4-7 input
port_B_pullups(0xFF);
output_high(KC1);// dua dua cac chan cot phim len cao
output_high(KC2);
output_high(KC3);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

lcd_init(); // khoi tao LCD


DisplayMain();
ResetInput();
OffBuzzer();
LockGate();
ReadPassfromEEPROM();
ReadRFID();
CurrentState=STAMAIN;
RFIDResult=0;

while(true)
{
if(WrongPassCount>=3||WrongRFIDCount>=3)
{
OnBuzzer(); // bat coi keu lien tuc khi nhap sai qua 3 lan
}
PROJECT OF EMPLOYED SYSTEMS
Page 44/18

// phan kiem tra the tu


if(RFIDResult!=0) // neu co the tu duoc cham thi UART tu ngat và RFIDResult se cap nhat ket qua
{
if(CurrentState==STAMAIN) // neu dang o che do cho co the cham vao
{
if(RFIDResult==1) // co the admin hoac the phu cham vao thi mo khoa
{
WrongRFIDCount=0; // xoa so lan sai
lcd_gotoxy(1, 2);
lcd_putc(" XIN MOI VAO! ");
UnLockGate();
Beep(1); // beep loa 1 tieng
delay_ms(1000);
CurrentState=STAUNLOCK;
}
else
{

lcd_gotoxy(1, 2);
lcd_putc("THE KHONG HOP LE");
Beep(3); // beep loa 3 tieng
if(WrongRFIDCount<3) WrongRFIDCount++;
if(WrongRFIDCount==3)
{
lcd_gotoxy(1, 2);
lcd_putc(" BAO DONG!! ");
}
delay_ms(1000);
DisplayMain();
}
}
else if(CurrentState==STAADDRFID) // dang them the
{
lcd_gotoxy(1, 2);
lcd_putc("DA THEM THE RFID");
Beep(1); // beep loa 1 tieng
RFIDAdmin[0]=UARTBuffer[1];
RFIDAdmin[1]=UARTBuffer[2];
PROJECT OF EMPLOYED SYSTEMS
Page 45/18

RFIDAdmin[2]=UARTBuffer[3];
RFIDAdmin[3]=UARTBuffer[4];
RFIDAdmin[4]=UARTBuffer[5];
RFIDAdmin[5]=UARTBuffer[6];
RFIDAdmin[6]=UARTBuffer[7];
RFIDAdmin[7]=UARTBuffer[8];
RFIDAdmin[8]=UARTBuffer[9];
RFIDAdmin[9]=UARTBuffer[10];
WriteRFID();
delay_ms(1000);
CurrentState=STAMAIN;
DisplayMain();
}

RFIDResult=0; // sau khi xu ly thong tin RFID thi reset bien de cho the tiep theo
}

// phan kim tra phim bam va mat ma


CurrentKey=Scankeyboard(); // doc ban phim
if(CurrentKey!=NOKEY) // neu phim tra ve khac NOKEY ( tuc la co bam phim)
{
switch(CurrentKey) // kiem tra xem la phim gi
{
case KEY0: // Neu la ca phim so
case KEY1:
case KEY2:
case KEY3:
case KEY4:
case KEY5:
case KEY6:
case KEY7:
case KEY8:
case KEY9:
{
if(CurrentState==STAMAIN) // neu dang o che do cho hoac che do nhap pass thi cho phep nhap
{
PROJECT OF EMPLOYED SYSTEMS
Page 46/18

CurrentState=STAINPUTPASS; // cai trang tahi hien tai la nhap pass


NextState=STAUNLOCK;
DisplayInputPass();

}
else if(CurrentState==STAINPUTPASS||CurrentState==STACHANGEPASS)
{
if(CurrentCodeIndex<6) //neu nhap chua du 6 ky tu
{
CurrentPass[CurrentCodeIndex]=CurrentKey; // luu so vua bam vao mang
lcd_putc('*'); // hien thi dau sao cho phim da bam
CurrentCodeIndex++;// chuyen sang vi tri tiep theo
}
}
else if(CurrentState==STAMENU1&&CurrentKey==KEY1)
{
CurrentState=STAINPUTPASS; // cai trang tahi hien tai la nhap pass
NextState=STACHANGEPASS;
DisplayInputPass();
}
else if(CurrentState==STAMENU1&&CurrentKey==KEY2)
{
CurrentState=STAINPUTPASS; // cai trang tahi hien tai la nhap pass
NextState=STAADDRFID;
DisplayInputPass();

break;
}

case KEYHASH:// Neu bam phim thang


{
if(CurrentState==STAMAIN) // neu dang nhap pass de mo
{
CurrentState=STAMENU1;
DisplayMenu1();
PROJECT OF EMPLOYED SYSTEMS
Page 47/18

}
else if(CurrentState==STAINPUTPASS&&NextState==STAUNLOCK) // neu dang nhap pass de
mo
{
CheckPassResult=CheckPass(); // kiem tra mat ma nhap vao
if(CheckPassResult==0) //neu sai pass thi thong bao
{
lcd_gotoxy(1, 2);
lcd_putc(" SAI MAT MA! ");
Beep(3); // beep loa 3 tieng
delay_ms(1000);
ResetInput(); // xoa du lieu da nhap
DisplayInputPass();
if(WrongPassCount<3) WrongPassCount++;
if(WrongPassCount==3)
{
lcd_gotoxy(1, 2);
lcd_putc(" BAO DONG!! ");
delay_ms(1000);
DisplayInputPass();
}
}
else
{
WrongPassCount=0; // xoa so lan sai
WrongRFIDCount=0; // xoa so lan sai
lcd_gotoxy(1, 2);
lcd_putc(" XIN MOI VAO! ");
UnLockGate();
Beep(1); // beep loa 1 tieng
delay_ms(1000);
ResetInput(); // xoa du lieu da nhap
CurrentState=STAUNLOCK;
}
}
else if(CurrentState==STAINPUTPASS&&NextState==STACHANGEPASS)
{
CheckPassResult=CheckPass(); // kiem tra mat ma nhap vao
PROJECT OF EMPLOYED SYSTEMS
Page 48/18

if(CheckPassResult==1) //neu nhap dung pass addmin


{
DisplayChangePass();
Beep(1); // beep loa 1 tieng
ResetInput(); // xoa du lieu da nhap
CurrentState=STACHANGEPASS; // tro ve man hinh change pass
}
else
{

lcd_gotoxy(1, 2);
lcd_putc(" SAI MAT MA! ");
Beep(3); // beep loa 3 tieng
delay_ms(1000);
ResetInput(); // xoa du lieu da nhap
DisplayInputPass();
}

}
else if(CurrentState==STAINPUTPASS&&NextState==STAADDRFID)
{
CheckPassResult=CheckPass(); // kiem tra mat ma nhap vao
if(CheckPassResult==1) //neu nhap dung pass addmin
{
DisplayAddRFID();
Beep(1); // beep loa 1 tieng
ResetInput(); // xoa du lieu da nhap
CurrentState=STAADDRFID; // tro ve man hinh them the
}
else
{

lcd_gotoxy(1, 2);
lcd_putc(" SAI MAT MA! ");
Beep(3); // beep loa 3 tieng
delay_ms(1000);
ResetInput(); // xoa du lieu da nhap
DisplayInputPass();
PROJECT OF EMPLOYED SYSTEMS
Page 49/18

}
else if(CurrentState==STACHANGEPASS)
{
if(CurrentCodeIndex<6) //neu nhap chua du 6 ky tu
{
lcd_gotoxy(1, 2);
lcd_putc("CHUA DU 6 KY TU!");
Beep(3); // beep loa 3 tieng
delay_ms(1000);
ResetInput(); // xoa du lieu da nhap
DisplayChangePass();
}
else
{
AdminPass[0]=CurrentPass[0];
AdminPass[1]=CurrentPass[1];
AdminPass[2]=CurrentPass[2];
AdminPass[3]=CurrentPass[3];
AdminPass[4]=CurrentPass[4];
AdminPass[5]=CurrentPass[5];
WritePassEEPROM();
lcd_gotoxy(1, 2);
lcd_putc(" DA LUU MA MOI! ");
Beep(2);
delay_ms(1000);
CurrentState=STAMAIN;
ResetInput(); // xoa du lieu da nhap
DisplayMain();
}
}

break;
}
case KEYSTAR:// Neu bam phim sao
{
if(CurrentState==STAUNLOCK)
PROJECT OF EMPLOYED SYSTEMS
Page 50/18

{
LockGate();
Beep(2);
CurrentState=STAMAIN;
ResetInput(); // xoa du lieu da nhap
DisplayMain();
}
else if(CurrentState==STAINPUTPASS||CurrentState==STAMENU1||
CurrentState==STAADDRFID)
{
ResetInput(); // xoa du lieu da nhap
CurrentState=STAMAIN;
DisplayMain();
}
else if(CurrentState==STACHANGEPASS)
{
Beep(2);
CurrentState=STAMAIN;
ResetInput(); // xoa du lieu da nhap
DisplayMain();
}
break;
}

}
}

}
}

You might also like