Pic Based Lock
Pic Based Lock
MICROCONTROLLER
Muhanad Hayder Mohammed
Lecturer in Computer Science Department, University of Kerbala Iraq
[email protected]
Abstract: The proposed system implements an computer designated to perform some specific tasks.
electronic embedded lock that provides a great benefit A Microcontroller program (firmware) is the one,
over a traditional lock, which uses only a manual key. which decides what functionality the microcontroller
If in case, the key is lost or stolen then anyone can provides to a user. A program that has the ability to
open the lock using the key. On the other hand, losing run on a microcontroller without the need of an
a long and complex password or getting it stolen is operating system is called as a firmware. That means,
harder as compared to a traditional key. Further, a a firmware has the privilege to access the hardware
combination of both, the manual key with a directly. This paper tries to explain an electronic lock
computerized password makes the system more firmware in detail. The basic idea of microcontroller is
secure. A longer password will reduce the possibilities to collect all the input and output peripherals in one
of getting the code broken and opening the lock. Our simple circuit, which represent the microcontroller
system comprises of a keypad and HD44780 20x2 instead of the large and sophisticated computer with
LCD along with a PIC16f628a microcontroller. The microprocessor and large numbers of peripherals [1].
firmware controls these components in such a way
that interaction with keypad is very easy and smooth. The firmware directly deals with peripherals and
The LCD provides user with messages and Input / Output ports to give complete functionality of
notifications to inform about the current system state. microcontroller.
User can perform operations such as opening and
closing the lock, changing the current password in the II. MICROPROCESSOR vs MICROCONTROLLER
microcontroller EEPROM and clearing a single digit Microprocessor differs from a microcontroller in
while entering the password when wrong digit entered many aspects. First and the most important aspect is
(back space). The proposed system’s firmware is its architecture. In order for a microprocessor to
developed using assembly language with MPLAB function properly, other components such as memory,
development environment. It is tested and peripherals and input output ports must be connected
implemented at the actual hardware level with proper to it. In short, we can say that a microprocessor is the
functioning of the system and it is completely bug free. heart of the computer and it works a group with other
peripherals / parts of the computer system. On the
Keywords: Electronic lock, embedded system, PIC other hand, a microcontroller is designed to be
microcontroller. comprised as a single unit which can perform
I. INTRODUCTION independently. No other external component is needed
for its application because all necessary peripherals
Today, we are living in the in the of embedded and ports are already built into it. Ultimately, it saves
systems surrounded by devices that based on the the time and space needed to construct devices [2].
embedded systems like cars, washing machine
microwave-oven, medical equipment's etc. III. SYSTEM IMPLEMENTATION
An embedded system is a computer system The system is implemented using assembly
designed for specific control functions often with real- language. The purpose of using this language is to get
time computing constraints. It is embedded as part of a a better picture and understanding of the PIC
complete device which often including hardware and architecture. Another positive aspect of using
mechanical parts. By contrast, a general-purpose assembly language is that it gives very wide and
computer, such as a personal computer (PC), is flexible way to interact with microcontrollers even
designed to be flexible to meet a wide range of end- though its implementation is harder than BASIC or C
user needs. Embedded systems control many devices languages, which are also used as a language for
in common use today [1]. programming microcontrollers. There are mainly two
One of prominent example of an embedded system parts of the system implementations:
is a microcontroller, which is a small and tiny
A. Keypad Implementation then both the pin voltage would drop to zero. This fact
could be used for designing the keypad.
The system dedicates PORTB for keypad
As mentioned above, PORTB is reserved for the
implementation in which 4 pins are reserved for
keypad and the most significant 4 bits are used for
columns and the remaining 4 pins for rows. Hence, the
column indexing, which are set as input port (for input
system uses these 8 pins for construction of 16 keys
port, we must set TRISB register to high [3]) to check
matrix, which makes an efficient use of the limited
whether they have dropped to 0 voltage when they are
ports provided in PIC16F628A. Following is the Table
attached with the selected row after pressing the key.
(1) PORTB pins assignments for keypad.
On the other hand, the least significant 4 bits of
Table1: PORTB pins assignments for keypad PORTB are set to output, and are used for row
indexing. Since they are the output ports, they can be
RB4(column0) RB5(column 1) RB6(column 2) RB7(column 3) set to high (1) or low (0) by the firmware. By setting
each row to zero for every key scan, the system can
RB0(row0) 1 2 3 A =Back space check each column, to see if any one of them is set to
RB1(row1) 4 5 6 B= lock the system
0. If so, this means that one key of that row has been
pressed. This process is repeated for all rows to check
RB2(row2) 7 8 9 C= Modify pass. all the keys. The functions responsible for scanning
RB3(row3) * 0 # D=Enter key are row_scan and col_scan.
1.1 Row scan
There is an important precaution which must be
taken while implementing the keypad because, the This function sets every row to zero at a time and
keypad processing rely on a mechanical process calls col_scan function to check if any column pins
(pressing and releasing keys). This phenomenon drop to zero voltage. This function then increments the
generates a spark, which influences the electrical key variable for each row assignments, to index the
properties of pin while pressing and releasing the key, row.
which causes the pin status to be unstable and can’t be
recognized properly whether it is 0 or 1. So, to 1.2 Col_scan
overcome this, a delay must be provided to give This function scans every column pin to check if
enough time for the pin status to be stable and can be any one of them is set to zero, if so then it calls
read correctly, this time could be 20ms or more. find_key function and finds the key value throw the
index constructed using the variable key and the hard
1. Key Scanning
coded value getting from working register w throw
The keypad design is influenced by electrical col_scan Function. Figure (1) show the keypad
phenomena, which states that, if we short circuit two structure connected to PIC 16F628A microcontroller
pins, one with zero and the other with high voltage, and LCD pins assignments.
Figure2: Message prompt to user to enter the Following are the steps performed by
password ReadEEPROM:
1. Initialize count with value 10.
2. Assign start address of EEPROM to specific
pointer.
3. Make FSR point to start address of array, which
will contain the value of EEPROM.
4. Increment FSR.
5. Read value of one location from EEPROM and
write it in the array.
6. Increment the pointer that point to EEPROM.
7. Decrement count. If equal to zero, it mean the
EEPROM password has been read completely then
return. Otherwise, go to step 4.
The other important function is WriteEEPROM Figure 4: Complete hardware components of the
function, which writes the new password to EEPROM system
when the user wants to change the password. Writing to
the EEPROM is critical operation which should not be It is evident from the figure, that there are only a few
performed accidentally [3], because the results would electronic components involved in the working of this
be permanent, unless and until we re-write the same system. This is really a great benefit of using an
location of EEPROM. For this reason, two values AAh embedded system, which makes the hardware
and 55h must be written to EECON2 register one after architecture very simple, but the complexity ultimately
another to be sure the program want to really write to moves to the firmware itself according to the concepts
EEPROM. of software and hardware boundary.
VI. REFERENCES
[1] Milan, Verle, “PIC Microcontrollers”,
mikroElektronika; 1st edition, 2008.
[2] Nebojsa, Matic, ”PIC Microcontrollers on line”,
MikroElektronika, 2000.
[3] Microchip, “PIC16F628x Data Sheet” Microchip.
How to cite
Muhanad Hayder Mohammed, "Secure Electronic Lock using PIC 16F628A Microcontroller". International Journal
of Research in Computer Science, 2 (5): pp. 43-47, September 2012. doi:10.7815/ijorcs.25.2012.047