Vous êtes sur la page 1sur 14

Password based security

An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a keypad, LCD and the controller AT89C51 which belongs to the 8051 series of microcontrollers.

DIscription:A 4x3 matrix keypad and a 16x2 LCD have been used here. Keypad and LCD are very commonly used input & output devices, respectively. A four digit predefined password needs to be specified the user. This password is stored in the system. While unlocking, if the entered password from keypad matches with the stored password, then the lock opens and a message is displayed on LCD. Also an output pin is made high to be used for further purpose. The connections in the circuit are as following: port P2 of microcontroller AT89C51 is used as data input port which is connected to data pins (7-14) of LCD. P1^0, P1^1 and P1^2 pins of microcontroller are connected to control pins RS, RW and EN of LCD. Port P0 is used to take input from keypad. P0^7 has been used as lock output pin of controller. As the program starts, string Enter Password is displayed on LCD. The keypad is scanned for pressed digits one by one. Every time, row and column of the key pressed is detected and a * is displayed on LCD corresponding to the entered number. After the four digits are entered, the user is prompted to Confirm Password and again the input is taken through LCD. If the passwords do not match, a message is displayed to indicate Wrong Password; otherwise the user is prompted to unlock the device.

To unlock, user needs to Enter Password through keypad. Again the keypad is scanned for pressed keys and corresponding digits are identified. The passkey is displayed as **** on the LCD screen. After the four digits are entered, they are compared with the pre-set password. If all the four digits match with set password, LCD displays Lock Open and the lock output pin goes high. If the security code is wrong, Wrong Password is sent to be displayed on LCD. The system gets locked if more than three attempts are made with wrong password to open the electronic lock. The system needs to be reset in such a case.

Looking to buy AT89C51 Microcontroller? Visit the Store


Need Pricing? Get a Quote!
AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (PEROM) and 128 bytes of RAM. It can be erased and program to a maximum of 1000 times.

In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bidirectional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually.

Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts.

Pin Diagram:

Pin No 1 2 3 4

Function

Name P1.0 P1.1 P1.2 P1.3

8 bit input/output port (P1) pins 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Quartz crystal oscillator (up to 24 MHz) 19 20 21 22 23 24 25 26 27 28 29 Program store enable; Read from external program memory Address Latch Enable 30 Program pulse input during Flash programming External Access Enable; Vcc for internal program executions 31 Programming enable voltage; 12V (during Flash programming) 32 33 34 Low-order address bits when interfacing with external memory 8 bit input/output port (P0) pins Vpp P0.7/ AD7 P0.6/ AD6 P0.5/ AD5 Prog EA Ground (0V) Crystal 1 Ground P2.0/ A8 P2.1/ A9 8 bit input/output port (P2) pins / High-order address bits when interfacing with external memory P2.2/ A10 P2.3/ A11 P2.4/ A12 P2.5/ A13 P2.6/ A14 P2.7/ A15 PSEN ALE Reset pin; Active high Input (receiver) for serial communication Output (transmitter) for serial communication External interrupt 1 External interrupt 2 Timer1 external input Timer2 external input Write to external data memory Read from external data memory RxD TxD Int0 Int1 T0 T1 Write Read P1.4 P1.5 P1.6 P1.7 Reset P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 Crystal 2

8 bit input/output port (P3) pins

35 36 37 38 39 40 Supply voltage; 5V (up to 6.6V)

P0.4/ AD4 P0.3/ AD3 P0.2/ AD2 P0.1/ AD1 P0.0/ AD0 Vcc

LCD
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.

Pin diagram

Pin Description:

Pin No 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Function Ground (0V) Supply voltage; 5V (4.7V 5.3V) Contrast adjustment; through a variable resistor Selects command register when low; and data register when high Low to write to the register; High to read from the register Sends data to data pins when a high to low pulse is given

Name Ground Vcc VEE Register Select Read/write Enable DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 Led+ Led-

8-bit data pins

Backlight VCC (5V) Backlight Ground (0V)

LCD interfacing

Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HITACHI 44780 which provides a simple interface between the controller & an LCD.

These LCD's are very simple to interface with the controller as well as are cost effective. The most commonly used ALPHANUMERIC displays are

1x16 (Single Line & 16 characters), 2x16 (Double Line & 16 character per line), 4x20 (four lines & Twenty characters per line

Pin description of LCD: table show the pin description of LCD. 8 pins are required to send data on LCD and 3 pins are required to control the data/command and read/write operation

Pin 1 2 3 4 5 6

Symbol Vss Vdd Vo RS R/W En

Function Ground Supply Voltage Contrast Setting Register Select Read/Write Select Chip Enable Signal Data Lines Gnd for the backlight Vcc for backlight

7-14 DB0-DB7 15 16 A/Vee K

Mode of operation: there are two modes of operation 8 bit and 4 bit.

8 bit required 8 data lines to send data/command

4 bit required only 4 pins and pin D4-D7 are connected to Vcc Control pins: 3 pins RS,R/W and EN are control pins and used as

EN - the ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW signal is required to latch the data. The LCD interprets and executes our command at the instant the EN line is brought low. If you never bring EN low, your instruction will never be executed. R/W - when R/W is low , we are writing to LCD and when R/W is High we reading from LCD. Most of the times there is no need to read from the LCD so this line can directly be connected to GND thus saving one controller line. RS - When RS is low (0), the data is to be treated as a command. When RS is high (1), the data being sent is considered as text data which should be displayed on the screen. DDRAM: character displayed on LCD are the data stored on Display Data RAM [ DDRAM ] and address of DDRAM for 2x16 LCD are varies from 80h to 8Fh for first line and 0C0h to 0CFh for second line. So if we want to display 'N' on the 7th poistion of the first line then we will write it at location 87h.

To display data on LCD we first need to initialize the LCD by sending different command and then we send data to LCD Initialization: table show to different value which are need to send on LCD when control pin RS is Low [ we are sending command ] and control pin EN goes High to Low [ show that we are sending some thing to LCD ]

"*" - Not Used/Ignored. This bit can be either "1" or "0" Clear display: Send 1 to pins to clear display

Set Cursor Move Direction: ID - Increment the Cursor After Each Byte Written to Display if Set

S - Shift Display when Byte Written to Display Enable Display/Cursor

Enable Display/Cursor: D - Turn Display D=High [ Display on] and D=Low [ Display off ]
C - Turn Cursor C=High [ Cursor shown ] and c=Low [ Cursor hide ] B - Cursor Blink B=High [ Blink on ] and B=Low [ blink off ]

Move Cursor/Shift Display SC - Display Shift SC=High [ Shift on ] and SC=Low [ Shift off ]
RL - Direction of Shift RL=high [ Shift to right ] and RL=low [ shift to left ]

Set Interface Length DL - Set Data Interface DL=1 [ 8 bit mode ] and DL=0 [ 4 bit mode ]
N - Number of Display Lines N=1 [ two line display ] and N=0 [ single line display ] F - Character Font F=1 [ 5x10 font ] and F=0 [ 5x7 font ] Poll the "Busy Flag" BF - This bit is set while the LCD is processing Move Cursor to CGRAM/Display A - Address Read/Write ASCII to the Display D - Data

so we send different code to LCD to get different characteristic like Display on/off, Cursor blink on/off, Cursor move direction etc now lets write some code to initialize our LCD but before it we need two subroutine (function) to send command and data on LCD our LCD is connected to port P1 to send data Send Data on LCD:
?

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

lcd_data:

2 3 4 5 6 7 8 9

SETB RS MOV P1, A SETB EN ACALL delay CLR EN

;Telling the LCD that the data which is being send is to ;data to displayed is stored in A and now send to port P1 ;EN is High ;a short delay ;EN is low to make a high-low pulse

RET ; return to main ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Send command to LCD:


?

1 2 3 4 5 6 7 8 9

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_cmd: CLR RS MOV P1,A SETB EN ;Telling the LCD that the data is a command ; command is send to the port ; make EN high

ACALL DELAY ;a short delay CLR EN RET ;EN ;return is low to make a higt-low pulse

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Initialize LCD:

1 2 3
MOV A,#38h ;telling the LCD that we use 8 bit mode, ;2 line display and 5x7 font ;#38h because here DL=1,N=1 and F=0 ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lcd_init:

4 5 6 7 8 9 10 11 12
ACALL lcd_cmd ACALL lcd_cmd MOV A,#06h ACALL lcd_cmd MOV A,#0Eh

;in "set interface length" ;sending command to LCD ;we use Display on,Cursor on and Cursor blinking off ;#0Ch to Display on,Cursor off and Cursor blinking off ;sending command to LCD ; cursor position auto increment and move cursor to ;right #04 cursor moved to left ;sending command to LCD

13 14 15

RET ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Clear LCD: clear the lcd and move cursor to home position
?

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 3 4 5 6 7

lcd_clr: MOV A,#01h ACALL lcd_cmd RET ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ s ;clear LCD ;sending command to LCD

now lets send to text to display LCD. we are sending "ElectroNets" to display .here we use simple method but you can also use DPTR to send a string to lcd. if don't know how to use DPTR, leave a command i will add in post. ;.........................................

1 2 3 4 5 6 7 8 9 10 11

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ RW EQU P2.0 RS EQU P2.1 EN EQU P2.2 ;change pins according your design

ORG 0000H

CLR RW ACALL lcd_clr ACALL lcd_init

;because we are writing to LCD ;clear display ;initialize the LCD

12 13 14 15 16 17

MOV A,'E' ACALL lcd_data MOV A,'l' ACALL lcd_data MOV A,'e' ACALL lcd_data MOV A,'c'

;here we sending a single character at a time and then call lcd_data t ;LCD that we sending some thing to display on LCD

18 19 20 21 22 23 24 25 26

ACALL lcd_data MOV A,'t' ACALL lcd_data MOV A,'r' ACALL lcd_data MOV A,'o' ACALL lcd_data MOV A,'N' ACALL lcd_data MOV A,'e'

27 28 29 30 31 32 33 34 35 36

ACALL lcd_data MOV A,'t' ACALL lcd_data MOV A,'s' ACALL lcd_data ;...................... all the subroutine goes here

;......................

37

END

; end of code

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Vous aimerez peut-être aussi