You are on page 1of 49

PASSWORD SECURED APPLIANCES CONTROL SYSTEM USING MICROCONTROLLER

A MINI PROJECT REPORT


Submitted in partial fulfillment of the requirements for the Award of the Degree Of

BACHELOR OF TECHNOLOGY
in

ELECTRONICS AND COMMUNICATION ENGINEERING


By Mr. B. Dinesh Reddy Mr. Aditya Rao Devaraj Mr. Abhinay Karthik Mr. Praveen Kumar Mr. A. S. Ramesh (07C31A0425) (07C31A0408) (07C31A0405) (07C31A0464) (07C31A0402)

Under the Guidance of

Mr. P. Kiran Kumar


Assoc.Prof.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

BALAJI INSTITUTE OF TECHNOLOGY AND SCIENCE


(Affiliated to JNTU, Hyderabad) NARSAMPET, WARANGAL 506 331

2010 11
1

BALAJI INSTITUTE OF TECHNOLOGY AND SCIENCE


NARSAMPET, WARANGAL 506 331
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

CERTIFICATE
This is to certify that this Project Work entitled PASSWORD SECURED APPLIANCES CONTROL SYSTEM USING MICROCONTROLLER is a bonafide work carried out by Mr. B. Dinesh Reddy (07C31A0425), Mr. Aditya Rao Devaraj (07C31A0408), Mr. Abhinay Karthik (07C31A0405), Mr.Praveen Kumar (07C31A0464), Mr.A.S.Ramesh (07C31A0402), in partial fulfillment of the requirements for the award of the degree of Bachelor of Technology from JNTU, Hyderabad during the period 2010-11 under our guidance and supervision.

Internal Guide

Head of the Dept.

Principal

Mr. P. Kiran Kumar


Assoc. Prof. Dept. of ECE BITS, Narsampet

Prof. S. Umamaheshwar
Professor & Head Dept. of ECE BITS, Narsampet

Prof. V. Vikram Reddy


Principal, BITS, Narsampet

EXTERNAL EXAMINER
2

DECLARATION
We, Mr. B. Dinesh Reddy (07C31A0425), Mr. Aditya Rao Devaraj (07C31A0408), Mr. Abhinay Karthik(07C31A0405), Mr. Praveen Kumar (07C31A0464), Mr. A. S. Ramesh (07C31A0402), here by declare that the project entitled PASSWORD SECURED APPLIANCES CONTROL SYSTEM USING MICROCONTROLLER, submitted in the partial fulfillment of the requirements for the award of Bachelor of Technology in Electronics and Communication Engineering, to Balaji Institute of Technology & Science, Narsampet, affiliated to JNTU, Hyderabad is a authentic work and has not been submitted to any other university or institution for award of the degree.

Mr. B. Dinesh Reddy Mr. Aditya Rao Devaraj Mr. Abhinay Karthik Mr. Praveen Kumar Mr. A.S. Ramesh

(07C31A0425) (07C31A0408) (07C31A0405) (07C31A0464) (07C31A0402)

ACKNOWLEDGEMENTS
It is a great pleasure to express our deepest sense of gratitude and indebtedness, to our Internal guide Mr. P. Kiran Kumar, Assoc. Prof., Dept. of ECE, BITS College Narsampet, for having been a source of constant inspiration, precious guidance and generous assistance during the project work. We deem it as a privilege to have worked under his able guidance. Without his close monitoring and valuable suggestions this work wouldnt have taken this shape. We feel that this help is un-substitutable and unforgettable.

We wish to express our sincere thanks to Prof. V. Vikram Reddy, Principal, BITS, Narsampet for providing the college facilities for the completion of the project. We are profoundly thankful to Prof. S. Umamaheshwar, Prof., & Head, Dept. of ECE, for his cooperation and encouragement. We are greatly thankful to our Project coordinators Mr. P. Kiran Kumar, Assoc. Prof. & Mr. V. Rama Krishna Reddy, Asst. Prof., Dept. of ECE, BITS, Narsampet for their support throughout our project.

We are thankful to the Mr. P. Ram Chandar Rao, Teaching Asst., Dept. of ECE, BITS, Narsampet for his Technical Support to carryout our project.

Finally, we thank all the faculty members, supporting staff of ECE Dept. and friends for their kind co-operation and valuable help for completing the project.

Mr. B. Dinesh Reddy Mr. Aditya Rao Devaraj Mr. Abhinay Karthik Mr. Praveen Kumar Mr. A. S. Ramesh
4

(07C31A0425) (07C31A0408) (07C31A0405) (07C31A0464) (07C31A0402)

ABSTRACT
Security is prime concern in our day-to-day life. Everyone wants to be as much as secure as to be possible. An access control systems forms a vital link in a security chain. The Microcontroller based digital lock presented here is an access control system that allows only authorized persons to access a restricted area. This system is best suitable for corporate offices, Banks, ATMs and Home security. The system comprises a small electronic unit with a numeric keypad, which is fixed outside the entry door to control a solenoid-operated lock with the help of a relay to switch on a Computer (or to run stepper motor). When an authorized person enters predetermined user ID and password via the keypad, the relay turns on (or stepper motor is operated). When the code has been incorrectly entered three times in a row, the code lock will switch to block mode. This function thwarts any attempt by hackers to quickly try a large number of codes in a sequence. If the user forgets his password, the code lock can be accessed by a unique 10 digit administrator password. The secret code can be changed any time after entering the current code (Master code). An LED is provided for acknowledgment of the key impression. Whenever a key is pressed on the numeric key pad, the system acknowledges the impression by a short sharp glow of the LED. This project uses regulated 5V, 500mA power supply. 7805 three terminal voltage regulator is used for voltage regulation. Bridge type full wave rectifier is used to rectify the ac output of secondary of 230/12V step down transformer.

CONTENTS
Chapter No.
CHAPTER 1 CHAPTER 2

Description
INTRODUCTION BLOCK DIAGRAM
2.1 Block Diagram Description 2.1.1 Power Supply 2.1.2 Transformer 2.1.3 Rectifier 2.1.4 Filter 2.1.5 Voltage Regulator 2.1.6 Microcontrollers 2.1.6.1. Features Of P89V51RD2 2.1.6.2. Pin Diagram 2.1.6.3. Pin Description

Page No.
9 10
11 11 11 11 12 12 12 13 16 17

CHAPTER 3 CHAPTER 4

PROGRAMMING THE FLASH KEY PAD


4.1 Interfacing Keypad

20 24
24

CHAPTER 5 CHAPTER 6

TRANSISTOR DRIVER CIRCUIT LIQUID CRYSTAL DISPLAY


6.1 Interfacing Liquid Crystal Display

27 28
29

CHAPTER 7

SOFTWARES USED
7.1 7.2 7.3 Keil u Vision Flash Magic Working procedure

34
34 34 34

CHAPTER 8

CODE

37

LIST OF FIGURES
S.No.
1 2 3 4 5 6 7 8 9 10

Fig. No.
Fig.1 Fig. 2 Fig.3 Fig.4 Fig.5 Fig.6 Fig.7 Fig.8 Fig.9 Fig.10

Description
Block Diagram Power Supply Microcontroller Architecture Block Diagram Of P89V51RD2 Pin Diagram Telephone Keypad Transistor Driver Circuit Procedure of 8-bit Initialisation LCD Interfacing with the microcontroller Schematic Diagram

Page No.
10 11 13 15 16 24 27 33 33 36

LIST OF TABLES
S.No.
1 2 3 4

Table No.
Table -1 Table-2 Table-3 Table-4

Description
Port 3 Alternate Functions Flash Programming Modes LCD Pin Functions LCD Basic Commands

Page No.
19 22 29 31

CHAPTER 1 INTRODUCTION

An embedded system is a combination of software and hardware to perform a dedicated task.

Some of the main devices used in embedded products are Microprocessors and Microcontrollers.

Microprocessors are commonly referred to as general purpose processors as they simply accept the inputs, process it and give the output.

In contrast, a Microcontroller not only accepts the data as inputs but also manipulates it, interfaces the data with various devices, controls the data and thus finally gives the result. The Project Password secured Appliances Control System is an excellent project that provides security in every way. This project is very useful in places where security is must.

CHAPTER 2 BLOCK DIAGRAM

Fig.1

Block Diagram 10

2.1.

BLOCK DIAGRAM DESCRIPTION

2.1.1. POWER SUPPLY


The input to the circuit is applied from the regulated power supply. The a.c. input i.e., 230V from the mains supply is step down by the transformer to 12V and is fed to a rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order to get a pure d.c voltage, the output voltage from the rectifier is fed to a filter to remove any a.c components present even after rectification. Now, this voltage is given to a voltage regulator to obtain a pure constant dc voltage.

230V AC 50Hz

D.C Output

Step down transformer Fig. 2

Bridge Rectifier Power Supply

Filter

Regulator

2.1.2. TRANSFORMER
Usually, DC voltages are required to operate various electronic equipment and these voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c input available at the mains supply i.e., 230V is to be brought down to the required voltage level. This is done by a transformer. Thus, a step down transformer is employed to decrease the voltage to a required level.

2.1.3. RECTIFIER
The output from the transformer is fed to the rectifier. It converts A.C. into pulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge rectifier is used because of its merits like good stability and full wave rectification. 11

2.1.4. FILTER
Capacitive filter is used in this project. It removes the ripples from the output of rectifier and smoothens the D.C. Output received from this filter is constant until the mains voltage and load is maintained constant. However, if either of the two is varied, D.C. voltage received at this point changes. Therefore a regulator is applied at the output stage.

2.1.5. VOLTAGE REGULATOR


As the name itself implies, it regulates the input applied to it. A voltage regulator is an electrical regulator designed to automatically maintain a constant voltage level. In this project, power supply of 5V and 12V are required. In order to obtain these voltage levels, 7805 and 7812 voltage regulators are to be used. The first number 78 represents positive supply and the numbers 05, 12 represent the required output voltage levels.

2.1.6. MICROCONTROLLERS
Microprocessors and microcontrollers are widely used in embedded systems products. Microcontroller is a programmable device. A microcontroller has a CPU in addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a single chip. The fixed amount of on-chip ROM, RAM and number of I/O ports in microcontrollers makes them ideal for many applications in which cost and space are critical. The Intel 8051 is a Harvard architecture, single chip microcontroller (C) which was developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and early 1990s, but today it has largely been superseded by a vast range of enhanced devices with 8051-compatible processor cores that are manufactured by more than 20 independent manufacturers including Philips, Atmel, Infineon Technologies and Maxim Integrated Products. 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU. 8051 is available in different memory types such as EEPROM, UV-EPROM, Flash and NVRAM. 12

The present project is implemented on Keil Uvision. In order to program the device, Flash Magic tool has been used to burn (dump) the program onto the Microcontroller.

Fig.3

Microcontroller Architecture

The features, pin description of the microcontroller and the software tools used are discussed in the following sections.

2.1.6.1.

FEATURES OF P89V51RD2

GENERAL DESCRIPTION
The P89V51RD2 is an 80C51 microcontroller with 64 kB Flash and 1024 bytes of data RAM. A key feature of the P89V51RD2 is its X2 mode option. The design engineer can choose to run application with the conventional 80C51 clock rate (12 clocks per machine cycle) or select the X2 mode (6 clocks per machine cycle) to achieve twice throughput at the same clock frequency by half. 13

The flash program memory supports both parallel programming and in serial In System Programming (ISP). Parallel programming mode offers gang programming at high speed, reducing programming costs and time to market. ISP allows a device to be reprogrammed in the end product under software control. The capability to field / update the application firmware makes a wide range of application possible. The P89V51RD2 is also In Application Programmable (IAP), allowing the flash program memory to be reconfigured even while the application is running.

FEATURES
80C51Central Processing Unit. 5V Operating voltage from 0 to 40MHz. 64kB of on chip Flash Program memory with ISP (In System Programming) and IAP (In Application Programming). Supports 12-clock (default) or 6-clock mode selection via software or ISP. SPI (Serial Peripheral Counter Array) with PWM and Capture/Compare functions. Four 8-bit I/O ports with three high current Port 1 pins (16mA each). Three 16-bit Timers/Counters. Two 16-bit Timer/Counters. Programmable Watch Dog Timer (WDT). Eight interrupt sources with four priority levels. Second DPTR register. Low EMI mode (ALE inhibit). TTL and CMOS compatible logic levels. Brown out detection. Low power modes -1.Power down mode with external interrupt wakeup & 2.Idle mode. PDIP40, PLCC44 and TQFP44 packages.

14

\ Fig.4 Block Diagram Of P89V51RD2

15

2.1.6.2.

PIN DIAGRAM

Fig.5 Pin Diagram


16

2.1.6.3.

PIN DESCRIPTION

Vcc-Pin 40 provides supply voltage to the chip. The voltage source is +5V. GND-Pin 20 is the ground. XTAL1 and XTAL2 XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator, as shown in Figure 11. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should be left unconnected while XTAL1 is driven, as shown in the below figure. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.

Fig: Oscillator Connections

C1, C2 = 30 pF 10 pF for Crystals

= 40 pF 10 pF for Ceramic Resonators Fig: External Clock Drive Configuration

17

RESET-Pin9 is the reset pin. It is an input and is active high. Upon applying a high pulse to this pin, the microcontroller will reset and terminate all the activities. This is often referred to as a power-on reset. EA (External access)-Pin 31 is EA. It is an active low signal. It is an input pin and must be connected to either Vcc or GND but it cannot be left unconnected. The 8051 family members all come with on-chip ROM to store programs. In such cases, the EA pin is connected to Vcc. If the code is stored on an external ROM, the EA pin must be connected to GND to indicate that the code is stored externally. PSEN (Program store enable)-This is an output pin. ALE (Address latch enable)-This is an output pin and is active high. Ports 0, 1, 2 and 3-The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon RESET are configured as input, since P0-P3 have value FFH on them. Port 0(P0)-Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for demultiplexing address and data with the help of an internal latch. When there is no external memory connection, the pins of P0 must be connected to a 10K-ohm pull-up resistor. This is due to the fact that P0 is an open drain. With external pullup resistors connected to P0, it can be used as a simple I/O, just like P1 and P2. But the ports P1, P2 and P3 do not need any pull-up resistors since they already have pull-up resistors internally. Upon reset, ports P1, P2 and P3 are configured as input ports. Port 1 and Port 2-With no external memory connection, both P1 and P2 are used as simple I/O. With external memory connections, port 2 must be used along with P0 to provide the 16bit address for the external memory. Port 2 is designated as A8-A15 indicating its dual function. While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8A15 of the address.

18

Port 3-Port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input or output. P3 does not need any pull-up resistors, the same as port 1 and port 2. Port 3 has an additional function of providing some extremely important signals such as interrupts.

Table: Port 3 Alternate Functions Machine cycle for the 8051 The CPU takes a certain number of clock cycles to execute an instruction. In the 8051 family, these clock cycles are referred to as machine cycles. The length of the machine cycle depends on the frequency of the crystal oscillator. The crystal oscillator, along with on-chip circuitry, provides the clock source for the 8051 CPU. The frequency can vary from 4 MHz to 30 MHz, depending upon the chip rating and manufacturer. But the exact frequency of 11.0592 MHz crystal oscillator is used to make the 8051 based system compatible with the serial port of the IBM PC. In the original version of 8051, one machine cycle lasts 12 oscillator periods. Therefore, to calculate the machine cycle for the 8051, the calculation is made as 1/12 of the crystal frequency and its inverse is taken. The assembly language program is written and this program has to be dumped into the microcontroller for the hardware kit to function according to the software. The program dumped in the microcontroller is stored in the Flash memory in the microcontroller. Before that, this Flash memory has to be programmed and is discussed in the next section.

19

CHAPTER 3 PROGRAMMING THE FLASH

PROGRAMMING THE FLASH


The P89V51RD2 is normally shipped with the on-chip Flash memory array in the erased state (that is, contents = FFH) and ready to be programmed. The programming interface accepts either a high-voltage (12-volt) or a low-voltage (VCC) program enable signal. The low-voltage programming mode provides a convenient way to program the P89V51RD2 inside the users system, while the high-voltage programming mode is compatible with conventional third party Flash or EPROM programmers. The P89V51RD2 is shipped with either the high-voltage or low-voltage programming mode enabled. The respective top-side marking and device signature codes are listed in the following table.

The P89V51RD2 code memory array is programmed byte-byte in either programming mode. To program any nonblank byte in the on-chip Flash Memory, the entire memory must be erased using the Chip Erase Mode.

PROGRAMMING ALGORITHM
Before programming the P89V51RD2, the address, data and control signals should be set up according to the Flash programming mode table. To program the P89V51RD2, the following steps should be considered: 1. Input the desired memory location on the address lines. 2. Input the appropriate data byte on the data lines. 3. Activate the correct combination of control signals. 4. Raise EA/VPP to 12V for the high-voltage programming mode. 5. Pulse ALE/PROG once to program a byte in the Flash array or the lock bits. The bytewrite cycle is self-timed and typically takes no more than 1.5 ms. Repeat steps 1 through 5, changing the address and data for the entire array or until the end of the object file is reached.

20

DATA POLLING
The P89V51RD2 features Data Polling to indicate the end of a write cycle. During a write cycle, an attempted read of the last byte written will result in the complement of the written datum on PO.7. Once the write cycle has been completed, true data are valid on all outputs, and the next cycle may begin. Data Polling may begin any time after a write cycle has been initiated.

READY/BUSY
The progress of byte programming can also be monitored by the RDY/BSY output signal. P3.4 is pulled low after ALE goes high during programming to indicate BUSY. P3.4 is pulled high again when programming is done to indicate READY.

CHIP ERASE
The entire Flash array is erased electrically by using the proper combination of control signals and by holding ALE/PROG low for 10 ms. The code array is written with all 1s. The chip erase operation must be executed before the code memory can be re programmed.

READING THE SIGNATURE BYTES


The signature bytes are read by the same procedure as a normal verification of locations 030H, 031H, and 032H, except that P3.6 and P3.7 must be pulled to a logic low. The values returned are as follows.

(030H) = 1EH indicates manufactured by Atmel (031H) = 51H indicates 89C51 (032H) = FFH indicates 12V programming (032H) = 05H indicates 5V programming

PROGRAMMING INTERFACE
Every code byte in the Flash array can be written and the entire array can be erased by using the appropriate combination of control signals. The write operation cycle is self timed and once initiated, will automatically time itself to completion. All major programming vendors offer worldwide support for the Atmel microcontroller series.

21

Fig: Flash Programming Modes

EEPROM
In the design of all microprocessors-based systems, semiconductor memories are used as primary storage for code and data. Semiconductor memories are connected directly to the CPU and they are the memory that the CPU first asks for information (code and data). For this reason, semiconductor memories are sometimes referred to as primary memory.

IMPORTANT TERMINOLOGY COMMON TO ALL SEMICONDUCTOR MEMORIES MEMORY CAPACITY


The number of bits that a semiconductor memory chip can store is called chip capacity. It can be in units of Kilobits, Megabits and so on. This must be distinguished from the storage capacity of computer system. While the memory capacity of a memory IC chip is always given in bits, the memory capacity of a computer system is given in bytes.

MEMORY ORGANIZATION

22

Memory chips are organized into a number of locations within the IC. Each location can hold 1 bit, 4 bits, 8 bits or even 16 bits, depending on how it is designed internally. The number of bits that each location within the memory chip can hold is always equal to the number of data pins on the chip. i.e., the total number of bits that a memory chip can store is equal to the number of locations times the number of data bits per location.

SPEED
One of the most important characteristics of a memory chip is the speed at which its data can be accessed. The speed of the memory chip is commonly referred to as its access time. The access time of memory chip varies from a few nanoseconds to hundreds of nanoseconds, depending on the IC technology used in the design and fabrication process. The different types of memories are RAM, ROM, EPROM and EEPROM. RAM and ROM are inbuilt in the microprocessor. This project requires the data such as the user identification number and password to be stored permanently. Thus this data has to be stored in such a location where it cannot be erased when power fails and also the data should be allowed to make changes in it without the system interface i.e., there should be a provision in such a way that the data should be accessed (or modified) while it is in system board but not external erasure and programming. The flash memory inbuilt in the microcontroller can erase the entire contents in less than a second and the erasure method is electrical. But the major drawback of Flash memory is that when flash memorys contents are erased, the entire device will be erased but not a desired section or byte. For this purpose, we prefer EEPROM in our project.

EEPROM (ELECTRICALLY ERASABLE PROGRAMMABLE READ ONLY MEMORY)


EEPROM has several advantages over other memory devices, such as the fact that its method of erasure is electrical and therefore instant. In addition, in EEPROM one can select which byte to be erased, in contrast to flash , in which the entire contents of ROM are erased. The main advantage of EEPROM is that one can program and erase its contents while it is in system board. It does not require physical removal of the memory chip from its socket. In general, the cost per bit for EEPROM is much higher when compared to other devices. 23

CHAPTER 4 KEYPAD
KEYPAD
Keypads and LCDs are the most widely used input/output devices of the 8051 and a basic understanding of them is essential. The keypads are mainly three types: 1. 4*3 keypad 2. 4*4 keypad 3. 4*8 keypad.

The keypad used in this project is 4*3 keypad.

Fig.6

Telephone Keypad

INTERFACING THE KEYPAD TO 8051


At the lowest level, keyboards are organized in a matrix of rows and columns. The CPU accesses both rows and columns through ports. Therefore, with two 8-bit ports, an 8*8 matrix of keys can be connected to a microprocessor. When a key is pressed, a row and a column make a contact, otherwise there is no connection between rows and columns. A single microcontroller (consisting of a microprocessor, RAM, EPROM and several ports all on a single chip) takes care of hardware and software interfacing of the keypad. In such 24

systems, it is the function of programs stored in EPROM of the microcontroller to scan the keys continuously, identify which one has been activated and present it to the motherboard.

Fig: 4*3 Matrix Keypad Connections to Ports

SCANNING AND IDENTIFYING KEY


The rows are connected to an output port and the columns are connected to an input port. If no key has been pressed, reading the input port will yield 1s for all columns since they are all connected to high (Vcc). If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides the path to ground. It is the function of the microcontroller to scan the keypad continuously to detect and identify the key pressed.

GROUNDING ROWS AND READING THE COLUMNS


To detect a pressed key, the microcontroller grounds all rows by providing 0 (zero) to the output latch, then it reads the columns. If the data read from the columns is D2-D0 =111, no key has been pressed and the process continues until a key press is detected. However, if one of the column bits has a zero, this means that a key press has occurred i.e., for example, if 25

D2-D0=110, this means that a key in the D0 column has been pressed. After a key press is detected, the microcontroller will go through a process of identifying the key. Starting with the top row, the microcontroller grounds it by providing a low to row D0 only and then it reads the columns. If the data read is all 1s, no key in that row is activated and the process is moved to the next row. It grounds the next row, reads the columns and checks for any zero. This process continues until the row is identified. After identification of the row in which the key has been pressed, the next task is to find out which column the pressed key belongs to. Now this will be easy since the microcontroller knows at any time which row and column are being accessed.

26

CHAPTER 5 TRANSISTOR DRIVER CIRCUIT

TRANSISTOR DRIVER CIRCUIT


Digital systems and microcontroller pins lack sufficient current to drive the circuits like LED circuits and relay circuits. While these circuits need around 10milli amps to be energized, the microcontrollers pin can provide a maximum of 1-2milli amps current. For this reason, a driver such as a power transistor is placed in between the microcontroller and the LED. Vcc

P89V51RD2 LED P1.0

GROUND

Fig.7

Transistor Driver Circuit

OPERATION OF THE CIRCUIT


The input to the base of the transistor is applied from the microcontroller port pin P1.0. The transistor will be switched on when the base to emitter voltage is greater than 0.7V (cut-in voltage). Thus when the voltage applied to the pin P1.0 is high i.e., P1.0=1 (>0.7V), the transistor will be switched on and thus the LED will be activated and produces a glow. When the voltage at the pin P1.0 is low i.e., P1.0=0 (<0.7V) the transistor will be in off state and the LED will be off. Thus the transistor acts like a current driver to operate the LED accordingly. 27

CHAPTER 6 LIQUID CRYASTAL DISPLAY


LIQUID CRYSTAL DISPLAY
LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing LEDs (seven segment LEDs or other multi segment LEDs) because of the following reasons: 1. The declining prices of LCDs. 2. The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are limited to numbers and a few characters. 3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying the data. 4. Ease of programming for characters and graphics. These components are specialized for being used with the microcontrollers, which means that they cannot be activated by standard IC circuits. They are used for writing different messages on a miniature LCD.

A model described here is for its low price and great possibilities most frequently used in practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in two lines with 16 characters each . It displays all the alphabets, Greek letters, punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols that user makes up on its own. Automatic shifting message on display (shift left and right), appearance of the pointer, backlight etc. are considered as useful characteristics.

28

PIN FUNCTIONS
There are pins along one side of the small printed board used for connection to the microcontroller. There are total of 14 pins marked with numbers (16 in case the background light is built in). Their function is described in the table below:

Function Ground Power supply Contrast

Pin Number 1 2 3

Name Vss Vdd Vee

Logic State 0 1

Description 0V +5V 0 Vdd D0 D7 are interpreted as commands D0 D7 are interpreted as data Write data (from controller to

RS

Control of operating

R/W

0 1

LCD) Read data (from LCD to controller)

0 6 E 1

Access to LCD disabled Normal operating

From 1 to Data/commands are transferred to 0 LCD Bit 0 LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 MSB

7 8 9 10 Data / commands 11 12 13 14

D0 D1 D2 D3 D4 D5 D6 D7

0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 29

LCD SCREEN
LCD screen consists of two lines with 16 characters each. Each character consists of 5x7 dot matrix. Contrast on display depends on the power supply voltage and whether messages are displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied on pin marked as Vee. Trimmer potentiometer is usually used for that purpose. Some versions of displays have built in backlight (blue or green diodes). When used during operating, a resistor for current limitation should be used (like with any LE diode).

LCD BASIC COMMANDS


All data transferred to LCD through outputs D0-D7 will be interpreted as commands or as data, which depends on logic state on pin RS: RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in processor addresses built in map of characters and displays corresponding symbols. Displaying position is determined by DDRAM address. This address is either previously defined or the address of previously transferred character is automatically incremented. RS = 0 - Bits D0 - D7 are commands which determine display mode. List of commands which LCD recognizes are given in the table below:

30

Command Clear display Cursor home Entry mode set Display on/off control Cursor/Display Shift Function set Set CGRAM address Set DDRAM address Read BUSY flag (BF) Write to CGRAM or DDRAM Read from CGRAM or DDRAM right 0 = Decrement (by 1) S 1 = Display shift on 0 = Display shift off D 1 = Display on 0 = Display off U 1 = Cursor on 0 = Cursor off B 1 = Cursor blink on 0 = Cursor blink off

RS RW D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 D 0 1

Execution Time I/D 1=

1 1.64mS x 1.64mS

Incr eme nt (by 1)

I/D S 40uS U B 40uS x 40uS x 40uS 40uS 40uS -

D/C R/L x F x

0 0 1 DL N

0 1 CGRAM address 1 DDRAM address BF DDRAM address

D7 D6 D5 D4 D3 D2 D1 D0 40uS

R/L 1=

D7 D6 D5 D4 D3 D2 D1 D0 40uS

Shif t

0 = Shift left DL 1 = 8-bit interface 0 = 4-bit interface N 1 = Display in two lines 0 = Display in one line F 1 = Character format 5x10 dots 0 = Character format 5x7 dots D/C 1 = Display shift 0 = Cursor shift

31

LCD INITIALISATION
Once the power supply is turned on, LCD is automatically cleared. This process lasts for approximately 15mS. After that, display is ready to operate. The mode of operating is set by default. This means that: 1. Display is cleared 2. Mode DL = 1 Communication through 8-bit interface N = 0 Messages are displayed in one line F = 0 Character font 5 x 8 dots

3. Display/Cursor on/off D = 0 Display off U = 0 Cursor off B = 0 Cursor blink off 4. Character entry ID = 1 Addresses on display are automatically incremented by 1. S = 0 Display shift off

Automatic reset is mainly performed without any problems. Mainly but not always! If for any reason power supply voltage does not reach full value in the course of 10mS, display will start perform completely unpredictably. If voltage supply unit can not meet this condition or if it is needed to provide completely safe operating, the process of initialization by which a new reset enabling display to operate normally must be applied. Algorithm according to the initialization is being performed depends on whether connection to the microcontroller is through 4- or 8-bit interface. All left over to be done after that is to give basic commands and of course- to display messages.

32

Fig: Procedure on 8-bit initialization.

LCD INTERFACING WITH THE MICROCONTROLLER

P2.0 P2.1 P2.2

4 (RS) 5 (R/W) 6(EN)

1 2 3

LCD P89V51RD2

P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7

D0 D1 D2 D3 D4 D5 D6 D7 33

15 16

CHAPTER 7 SOFTWARES USED

KEIL COMPILER
Keil compiler is a software used where the machine language code is written and compiled. After compilation, the machine source code is converted into hex code which is to be dumped into the microcontroller for further processing. Keil compiler also supports C language code.

FLASH MAGIC
Flash-Magic is the Software which accepts any file like hex, assembly language, C, C++, JAVA class files. Once the machine code is converted into hex code, that hex code has to be dumped into the microcontroller and this is done by the Flash-Magic. Flash-Magic is a programmer which itself contains a microcontroller in it other than the one which is to be programmed. This microcontroller has a program in it written in such a way that it accepts the hex file from the keil compiler and dumps this hex file into the microcontroller which is to be programmed. As the Flash-Magic programmer kit requires power supply to be operated, this power supply is given from the power supply circuit designed above. It should be noted that this programmer kit contains a power supply section in the board itself but in order to switch on that power supply, a source is required. Thus this is accomplished from the power supply board with an output of 12volts.

WORKING PROCEDURE
The Project Password based Computer control system using P89V51RD2 Microcontroller is an exclusive project that provides security at Corporate Offices, Banks, ATM centers, offices and homes. Security is of primary concern and in this busy, competitive world, human cannot find ways to provide security to his confidential belongings manually. Instead, he finds an alternative which can provide a full fledged security as well as automized. This project has been developed on this motto.

34

In this project every user, a part of an organization, is given an unique user ID and password. The passwords of all the users of that particular organization will be stored in EEPROM present in the system board because the data in EEPROM can be changed any number of times without the physical removal of the memory chip from its socket. This system will be fixed at the main door of the restricted area. Whenever the user tries to enter into the organization, this system asks the user to enter his user id. This message Enter USER ID will be displayed on the LCD. Then the user has to enter his identification number then, The microcontroller accepts this data and compares this user id which is already stores in the EEPROM. If the user id is not matched with any of the stored user ids, the microcontroller will not proceed for further details but displays a message Invalid USER ID. If this user id is matched with any one of the already stored user ids, then the system asks the user to enter his password. After he enters his password, the microcontroller once again compares the entered password with the already passwords in the EEPROM. If this password matches with any one of the passwords stored, the microcontroller supllies the power to the computer by enabling the relay for the person to enter into the restricted area and the message PROCESSING will be displayed on the LCD display. But if the entered password does not match with the already stored passwords, the message Password failed. Enter ID will be displayed on the LCD and the computer does not on. If the password is entered wrongly for 3 times continuously, then the total system will be blocked. The system can come to normal condition only after pressing the RESET switch. Initially the system is given with default passwords as shown below.

User ID 101 102 103 104

Password 555 556 557 558

If the user forgot his password then he should consult administrator. Then the administrator enters a 10 digit code which is admin PSWD. Then the forgotten password is displayed on LCD. Default password for administrator is 1234567890. # key should be entered after completion of entering ID or password. This key acts like a ENTER key.

35

Fig: SCHEMATIC DIAGRAM

36

CHAPTER 8 CODE

FAILCOUNT KEYCOUNT TIME TEMP PWDFIND COMPARED PCOUNT1 PASSWORD1 PCOUNT2 PASSWORD2 PCOUNT3 PASSWORD3 PCOUNT4 PASSWORD4 ORG 00H

DATA 22H DATA 25H ;TO STORE THE NO. KEYS ENTERD FOR EACH

DATA 26H DATA 27H

;TEMP VARIABLE ;TO FIND WHICH PASSWORD SHOULD BE

DATA 28H

;TO STORE THE NO.OF DIGITS OF

DATA 29H

;TO STORE THE NO.OF DIGITS OF

DATA 2AH

;TO STORE THE NO.OF DIGITS OF

DATA 2BH

;TO STORE THE NO.OF DIGITS OF

MOV P3,#00000111B COLUMNS MOV R1,#50H LOCATION ;MOV R0,#0 CLR P2.7 MOV FAILCOUNT,#0 ;LCD INTIALIZATION MOV DPTR,#COMM XX: CLR A MOVC A,@A+DPTR JZ START1 ACALL COMMAND ACALL DELAY INC DPTR

;MAKE P3.0-P3.2 AS INPUT PINS FOR

;SCANNED KEY IS STORED IN THIS

; LED OFF

37

SJMP XX START1: MOV DPTR,#MSGA ACALL DISPLAY1 ACALL DELAY ACALL DELAY ACALL DELAY MOV A,#0C0H ACALL COMMAND ACALL DELAY MOV DPTR,#MSGB ACALL DISPLAY1 ACALL DELAY ACALL DELAY ACALL DELAY MOV DPTR,#MSG ACALL DISPLAY ACALL DELAY START2: CLR P2.7 MOV DPTR,#MSG1 ;ASKING FOR ID ACALL DISPLAY ACALL DELAY ACALL KEYSCAN ACALL DELAY ACALL COMPARISON ACALL DELAY SJMP START2 ;ID COMPARISION ;ENTER THE ID ;DISPLAY "SECURITY SYSTEM" ;DISPLAY "BITS"

/*@@@@@@@ KEYSCAN SUBROUTINE @@@@@@@@@@@@@@@*/ KEYSCAN: LOCATION MOV A,#0C3H ;ENTERD KEYS ARE DISPLAYED FROM 4TH LOCATION OF 2ND LINE LCALL COMMAND LCALL DELAY MOV KEYCOUNT,#0 38 MOV R1,#50H ;SCANNED KEY IS STORED IN THIS

NEXTKEY:

MOV P0,#0F0H MOV A,P3

;GROUND ALL ROWS INTIALLY ;READ ALL COLMNS;ENSURE ALL KEYS

OPEN ANL A, #00000111B CJNE A,#00000111B,NEXTKEY K2: ACALL DELAY MOV A,P3 OPEN ANL A, #00000111B CJNE A,#00000111B,OVER SJMP K2 OVER: ACALL DELAY MOV A,P3 ANL A, #00000111B CJNE A,#00000111B,OVER1 SJMP K2 OVER1: MOV P0,#00001110B MOV A,P3 ANL A, #00000111B CJNE A,#00000111B,ROW_0 MOV P0,#00001101B MOV A,P3 ANL A, #00000111B CJNE A,#00000111B,ROW_1 MOV P0,#00001011B MOV A,P3 ANL A, #00000111B CJNE A,#00000111B,ROW_2 MOV P0,#00000111B MOV A,P3 ANL A, #00000111B CJNE A,#00000111B,ROW_3 LJMP K2 ROW_0: MOV DPTR,#KCODE0 SJMP FIND 39 ;GROUND ROW 3 ;READ ALL COLMNS ;GROUND ROW 2 ;READ ALL COLMNS ;GROUND ROW 1 ;READ ALL COLMNS ;GROUND ROW 0 ;READ ALL COLMNS ;READ ALL COLMNS ;READ ALL COLMNS;ENSURE ALL KEYS

ROW_1:

MOV DPTR,#KCODE1 SJMP FIND

ROW_2:

MOV DPTR,#KCODE2 SJMP FIND

ROW_3: FIND:

MOV DPTR,#KCODE3 RRC A JNC MATCH INC DPTR SJMP FIND

MATCH:

SETB P2.7 ACALL DELAY ;IF KEY IS DETECTED THEN GIVE A BEEP

SOUND ACALL DELAY CLR P2.7 CLR A MOVC A,@A+DPTR MOV @R1,A CJNE A,#23H,NK PRESSED RET NK: PRESSED KEY ACALL DELAY INC KEYCOUNT INC R1 SJMP NEXTKEY COMPARISON: MOV A,KEYCOUNT CJNE A,#3,FFAIL CHECKID1: MOV A,#'1' CJNE A, 50H, CHECKID2 MOV A,#'0' CJNE A,51H,CHECKID2 MOV A,#'1' CJNE A,52H,CHECKID2 40 ;COMPARE WITH ID1 ACALL DATAWRT ;DISPLAY THE ;STOP THE KEYSCANNING WHEN '#' IS

SJMP PWDCHECK1 PASSWORD CHECKID2: MOV A,#'1' CJNE A,50H,CHECKID3 MOV A,#'0' CJNE A,51H,CHECKID3 MOV A,#'2' CJNE A,52H,CHECKID3 SJMP PWDCHECK2 ;COMPARE WITH ID3 CHECKID3: MOV A,#'1'

;IF ID MATCHED GO FOR ITS

;COMPARE WITH ID2

;COMPARE WITH ID3

CJNE A,50H,CHECKID4 MOV A,#'0' CJNE A,51H,CHECKID4 MOV A,#'3' CJNE A,52H,CHECKID4 SJMP PWDCHECK3 ;COMPARE WITH ID4 CHECKID4: MOV A,#'1' CJNE A,50H,FFAIL MOV A,#'0' CJNE A,51H,FFAIL MOV A,#'4' CJNE A,52H,FFAIL LJMP PWDCHECK4 FFAIL: PWDCHECK1: LJMP FAIL MOV PWDFIND,#10000001B ;TO SET 8th,1st BIT ;COMPARE WITH ID4

THIS LOGIC IS USED TO KNOW WHICH ID'S PASSWORD SHOULD BE COMPARED MOV DPTR,#MSG2 ACALL DISPLAY ACALL KEYSCAN ACALL DELAY MOV A,KEYCOUNT CJNE A,#10,PD1 ;IF NO.OF KEYS ENTERD ;ENTER PASSWORD ;ASK FOR PASSWORD

ARE 10 THEN GO COMPARE WITH ADMINPASSWORD 41

LJMP ADMIN_PSWD PD1: MOV PCOUNT1,KEYCOUNT ;LOAD THE NO.OF DIGITS

OF PASSWORD1 IN PCOUNT1 ACALL NEXT WANTS TO CHANGE PASSWORD OR NOT LJMP START2 PWDCHECK2: MOV PWDFIND,#01000010B MOV DPTR,#MSG2 ACALL DISPLAY ACALL KEYSCAN ACALL DELAY MOV A,KEYCOUNT CJNE A,#10,PD1 LJMP ADMIN_PSWD PD11: MOV PCOUNT2,KEYCOUNT ACALL NEXT LJMP START2 PWDCHECK3: MOV PWDFIND,#00100100B MOV DPTR,#MSG2 ACALL DISPLAY ACALL KEYSCAN ACALL DELAY MOV A,KEYCOUNT CJNE A,#10,PD111 LJMP ADMIN_PSWD PD111: MOV PCOUNT3,KEYCOUNT ACALL NEXT LJMP START2 PWDCHECK4: MOV PWDFIND,#00011000B MOV DPTR,#MSG2 ACALL DISPLAY ACALL KEYSCAN ACALL DELAY MOV A,KEYCOUNT CJNE A,#10,PD1111 42 ;TO SET 5th,4th BIT ;TO SET 6th,3rd BIT ;TO SET 7th AND 2nd BIT ;CHECK WHETHER USER

LJMP ADMIN_PSWD PD1111: MOV PCOUNT4,KEYCOUNT ACALL NEXT LJMP START2 NEXT: MOV A,KEYCOUNT CJNE A,#3,INTIALCHECK MOV A,#'1' CJNE A,50H,INTIALCHECK CJNE A,51H,INTIALCHECK CJNE A,52H,INTIALCHECK INTIALCHECK: ACALL CHECKPWD ACALL DELAY LJMP SUCCESS CHECKPWD: JB PWDFIND.7,PSWD1 JB PWDFIND.6,PSWD2 JB PWDFIND.5,PSWD3 JB PWDFIND.4,PSWD4 LJMP START2 PSWD1: MOV A,PCOUNT1 MOV A,#'5' CJNE A,50H,K MOV A,#'5' CJNE A,51H,K MOV A,#'5' CJNE A,52H,K LJMP SUCCESS K: PSWD2: LJMP FAIL MOV A,PCOUNT2 MOV A,#'5' CJNE A,50H,AA MOV A,#'5' CJNE A,51H,AA MOV A,#'6' CJNE A,52H,AA LJMP SUCCESS 43 ;COMPARE WITH ID2 ;COMPARE WITH ID1

AA: PSWD3:

LJMP FAIL MOV A,PCOUNT3 MOV A,#'5' CJNE A,50H,KK MOV A,#'5' CJNE A,51H,KK MOV A,#'7' CJNE A,52H,KK LJMP SUCCESS ;COMPARE WITH ID3

KK: PSWD4:

LJMP FAIL MOV A,PCOUNT4 MOV A,#'5' CJNE A,50H,KKK MOV A,#'5' CJNE A,51H,KKK MOV A,#'8' CJNE A,52H,KKK LJMP SUCCESS ;COMPARE WITH ID4

KKK:

LJMP FAIL RET

KJ: ADMIN_PSWD:

LJMP FAIL MOV A,#'1' CJNE A,50H,KJ MOV A,#'2' CJNE A,51H,KJ MOV A,#'3' CJNE A,52H,KJ MOV A,#'4' CJNE A,53H,KJ MOV A,#'5' CJNE A,54H,KJ MOV A,#'6' CJNE A,55H,KJ MOV A,#'7' CJNE A,56H,KJ 44 ;COMPARE WITH ID ADMIN_PSWD

MOV A,#'8' CJNE A,57H,KJ MOV A,#'9' CJNE A,58H,KJ MOV A,#'0' CJNE A,59H,KJ ;IF ADMIN PASSWORD IS MATCHED THEN DISPLAY THE RESPECTIVE USER'S PASSWORD MOV DPTR,#MSG5 ACALL DISPLAY JB PWDFIND.0,DISP_PWD1 JB PWDFIND.1,DISP_PWD2 JB PWDFIND.2,DISP_PWD3 JB PWDFIND.3,DISP_PWD4 DISP_PWD1: MOV A,#0C0H ACALL COMMAND ACALL DELAY MOV DPTR,#PWD1 MATCHED THEN PC STARTS ACALL DISPLAY ACALL L_DELAY SJMP DO_AGAIN ;DISPLAY PASSWORD2 DISP_PWD2: MOV A,#0C0H ACALL COMMAND ACALL DELAY MOV DPTR,#PWD2 MATCHED THEN PC STARTS ACALL DISPLAY ACALL L_DELAY SJMP DO_AGAIN ;DISPLAY PASSWORD3 DISP_PWD3: MOV A,#0C0H ACALL COMMAND ACALL DELAY 45 ;IF THE ID & PSWD ARE ;IF THE ID & PSWD ARE

MOV DPTR,#PWD3 MATCHED THEN PC STARTS ACALL DISPLAY ACALL L_DELAY SJMP DO_AGAIN ;DISPLAY PASSWORD4 DISP_PWD4: MOV A,#0C0H ACALL COMMAND ACALL DELAY MOV DPTR,#PWD4 MATCHED THEN PC STARTS ACALL DISPLAY ACALL L_DELAY DO_AGAIN: SUCCESS: LJMP START2 MOV FAILCOUNT,#0 MOV DPTR,#MSG3 ACALL DISPLAY ACALL DEVICE LJMP START2 FAIL: MOV DPTR,#MSG4 ACALL DISPLAY INC FAILCOUNT MOV A,#3 CJNE A,FAILCOUNT,TRY1 MOV FAILCOUNT,#0 MOV DPTR,#MSG10 ACALL DISPLAY SETB P2.7 SJMP $ TRY1: SETB P2.7 ACALL DLAYms ACALL DLAYms CLR P2.7 ACALL DELAY ACALL DELAY 46

;IF THE ID & PSWD ARE

;IF THE ID & PSWD ARE

SETB P2.7 ACALL DLAYms ACALL DLAYms CLR P2.7 ACALL DELAY ACALL DELAY SETB P2.7 ACALL DLAYms ACALL DLAYms LJMP START2 DEVICE : MOV DPTR,#MSG7 ACALL DISPLAY ACALL DELAY DD: SETB P2.7 CLR P2.0 SJMP DD RET

/* LCD DISPLAY SUBROUTINE */ DISPLAY: MOV A,#01H ACALL COMMAND ACALL DELAY DISPLAY1: CLR A MOVC A,@A+DPTR JZ XYZ ACALL DATAWRT ACALL DELAY INC DPTR SJMP DISPLAY1 XYZ: MOV A,#0C4H ACALL COMMAND ACALL DELAY RET ;SEND COMMANDS TO LCD COMMAND: MOV P1,A 47

CLR P3.3 CLR P3.4 SETB P3.5 ACALL DELAY CLR P3.5 RET ;SEND DATA TO LCD DATAWRT: MOV P1,A SETB P3.3 CLR P3.4 SETB P3.5 ACALL DELAY CLR P3.5 RET DELAY: HERE1: HERE: MOV R6,#200 MOV R7,#100 DJNZ R7,HERE DJNZ R6,HERE1 RET DLAYms: MOV R6,#100 MOV B,#00 MS1: DJNZ B,$ DJNZ B,$ DJNZ R6,MS1 RET L_DELAY: LLL: MOV R7,#0AH LCALL DLAYms DJNZ R7,LLL RET COMM: DB 38H,0EH,01H,06H,84H,00H

ID1: ID2: ID3: ID4:

DB "101",0 DB "102",0 DB "103",0 DB "104",0 48

PWD1: PWD2: PWD3: PWD4: ADMINPWD: MSGA: MSGB: MSG: MSG1: MSG2: MSG3: MSG4: MSG5: MSG6: MSG7: MSG8: MSG9: MSG10: MSG11:

DB "555",0 DB "556",0 DB "557",0 DB "558",0 DB "1234567890",0 DB "BITS",0 DB "ECE-A,IV YEAR...",0 DB "SECURITY SYSTEM",0 DB "ENTER ID",0 DB "ENTER PASSWORD",0 DB "SUCCESS",0 DB "FAIL",0 DB "YOUR PSWD IS ",0 DB "MAX LENTH OVER ",0 DB "SYSTEM ON.. ",0 DB "SYSTEM OFF.. ",0 DB "INVALID PSWD ",0 DB " SYSTEM BLOCKED ",0 DB " BITS... ",0

KCODE0: KCODE1: KCODE2: KCODE3: END

DB '1','2','3' DB '4','5','6' DB '7','8','9' DB '*','0','#'

49

You might also like