ece 625 final project - digital door lock system
TRANSCRIPT
December 17, 2011 ECE 625 FINAL PROJECT REPORT
CALIFORNIA STATE UNIVERSITY, NORTHRIDGE
DEPARTMENT OF ELECTRICAL & COMPUTER ENGINEERING
MICROPROCESSOR APPLICATION IN ENGINEERING(ECE 625)
PROJECT REPORT ON
DIGITAL DOOR LOCK SYSTEM
PROFESSOR: SHAHNAM MIRZAEI
BY
SAMEER PANDIT (104249481)
BALU BHARGAV MEDAPI (104251743)California State University, Northridge | 1
December 17, 2011 ECE 625 FINAL PROJECT REPORT
TABLE OF CONTENTS
ABSTRACT………………………………………………………………………………...4
BLOCK DIAGRAM………………………………………………………………………. 5
PROBLEM DESCRIPTION………………………………………………………………. 5
THEORY OF OPERATION………………………………………………………………. 6
THE MICROCONTROLLER MC9S12DG256…………………………………………....7
LCD DISPLAY……………………………………………………………………………. 10
KEYPAD MODULE………………………………………………………………………. 11
TESTING STRATEGY…………………………………………………………………….13
FLOWCHART……………………………………………………………………………...19
PROGRAM…………………………………………………………………………………20
ADVANTAGES…………………………………………………………………………… 37
DICUSSION……………………………………………………………………………….. 37
CONCLUSION……………………………………………………………………………. 37
California State University, Northridge | 2
December 17, 2011 ECE 625 FINAL PROJECT REPORT
FIGURES
(FIG 1.1) GENERAL BLOCK DIAGRAM………………………………………………. 5
(FIG 1.2) THE MC9S12DG256 MICROCONTROLLER…………………………………7
(FIG 1.3) THE MC9S12DG256 MCU BLOCK DIAGRAM…………………………….. 8
(FIG 1.4) THE MC9S12DG256 PIN ASSIGNMENT……………………………………. 9
(FIG 1.5) LCD DISPLAY…………………………………………………………………. 10
(FIG 1.6) KEYPAD UNIT………………………………………………………………….11
(FIG 1.7) THE PROGRAM FLOW……………………………………………………….. 13
(FIG 1.8) FLOWCHART OF THE PROJECT……………………………………………..19
California State University, Northridge | 3
December 17, 2011 ECE 625 FINAL PROJECT REPORT
ABSTRACT
In this age of digital technology, every device and operation has become digital based. Security systems have got a major space in our lives and we find them in almost every place we visit these days. Our project “DIGITAL DOOR LOCK SYSTEM” is a module which is used to provide a digital key that should be used for accessing a safe and also has the capability to display messages on liquid crystal display. The digital door locking system created by us does not need a key to unlock a door. Instead, we use a keypad to unlock the door.
The working of this door locking system is very simple. Only an authenticated person is allowed to unlock the door with the help of a unique code.
One of the major application is it is used in banks, offices, jails and also in many places where a security lock is required. The project is completely designed using a Dragon-12 Plus kit.
California State University, Northridge | 4
December 17, 2011 ECE 625 FINAL PROJECT REPORT
BLOCK DIAGRAM
General block diagram (Fig 1.1)
PROBLEM DESCRIPTION
The main objective of this project is to pre-program the microcontroller to store two keys which are used to authenticate a system as a normal user and an administrator, also program the LED module to display messages when the system is used, using “MC9S12DG256” micro controller. Finally we display the messages on the liquid crystal display (LCD) and also function the LEDs according to input given to the keypad & testing the designed system for reliability.
California State University, Northridge | 5
December 17, 2011 ECE 625 FINAL PROJECT REPORT
THEORY OF OPERATION
The project is mainly used to design a system that can provide a secure key to access a system. The different modules used in this project are the MC9S12DG256, key pad module and LCD display. The microcontroller stores 2 authentic keys which are secured keys for access. The 2 keys are, a normal and an administrator keys. In this way a secured gate way is provided. The main part of our project is to use these keys for authentication and reject other keys which are not fed into the system. The final part of the project is display the related messages on the LCD display. In order to achieve this we use the PORT K and PORT B as output ports which are connected to the LCD display and the LEDs. Another important feature of our project is we also programmed the microcontroller to display messages on the LCD display apart from the usual security operation. The messaged displayed on the LCD display are:
1. “WELCOME” – When any one of the key is put in correctly.
2. “SYSTEM LOCKED” – When 3 incorrect attempts are made while putting in the key.
The description of each module used in our project is given below.
California State University, Northridge | 6
December 17, 2011 ECE 625 FINAL PROJECT REPORT
THE MICROCONTROLLER (MC9S12DG256)
The MC9S12DG256 microcontroller kit that we used for this project is as shown below. The main features of the board that we are using are circled in red.
The MC9S12DG256 Microcontroller (Fig 1.2)
The MC9S12DG256 microcontroller consists of a powerful 16-bit CPU (central processing unit), 256K bytes of flash memory, 12K bytes of RAM, 4K bytes of EEPROM and many on-chip peripherals. The main features of the MC9S12DG256 are: • Powerful 16-bit CPU • 256K bytes of flash memory
California State University, Northridge | 7
December 17, 2011 ECE 625 FINAL PROJECT REPORT
• 12K bytes of RAM • 4K bytes of EEPROM • SCI ports • SPI ports • CAN 2.0 ports • I2C interface • 8-ch 16-bit timers • 8-ch 8-bit or 4-ch 16 bit PWM • 16-channel 10-bit A/D converter • Fast 25 MHz bus speed via on-chip Phase Lock Loop • BDM for in-circuit programming and debugging • 112-pin LQFP package offers up to 91 I/O in a small footprint The block diagram and pin assignments are as shown in the figures below.
California State University, Northridge | 8
December 17, 2011 ECE 625 FINAL PROJECT REPORT
MC9S12DG256 MCU block diagram (Fig 1.3)
California State University, Northridge | 9
December 17, 2011 ECE 625 FINAL PROJECT REPORT
MC9S12DG256 Pin Assignment (Fig 1.4)
California State University, Northridge | 10
December 17, 2011 ECE 625 FINAL PROJECT REPORT
LCD DISPLAY
A model used 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 character 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.
LCD Display in MC9S12DG256 (Fig 1.5)
California State University, Northridge | 11
December 17, 2011 ECE 625 FINAL PROJECT REPORT
KEYPAD MODULE
Port A is an 8-bit bi-directional port. Its primary usage is for a 4X4 keypad. If the port is not used for the keypad, it can be used as a general-purpose I/O. The schematic for the keypad connections is shown below:
Keypad Unit in MC9S12DG256 (Fig 1.6)
Keypad connections: PA0 connects COL0 of the keypad PA1 connects COL1 of the keypadPA2 connects COL2 of the keypadPA3 connects COL3 of the keypad PA4 connects ROW0 of the keypad PA5 connects ROW1 of the keypad PA6 connects ROW2 of the keypad PA7 connects ROW3 of the keypad
Keypad scan routine sets PA3 low and PA0, PA1, PA2 high, then tests PA4-PA7. If no key is down, PA4-PA7 remains high. If PA7 = low, the key 15 is down. If PA6 = low, the key 14 is down. If PA5 = low, the key 13 is down. If PA4 = low, the key 12 is down.
California State University, Northridge | 12
December 17, 2011 ECE 625 FINAL PROJECT REPORT
Keypad scan routine sets PA2 low and PA0, PA1, PA3 high, then tests PA4-PA7.If no key is down, PA4-PA7 remains high. If PA7 = low, the key 11 is down. If PA6 = low, the key 10 is down. If PA5 = low, the key 9 is down. If PA4 = low, the key 8 is down.
Keypad scan routine sets PA1 low and PA0, PA2, PA3 high, then tests PA4-PA7.If no key is down, PA4-PA7 remains high. If PA7 = low, the key 7 is down. If PA6 = low, the key 6 is down. If PA5 = low, the key 5 is down. If PA4 = low, the key 4 is down.
Keypad scan routine sets PA0 low and PA1, PA2, PA3 high, then tests PA4-PA7.If no key is down, PA4-PA7 remains high. If PA7 = low, the key 3 is down. If PA6 = low, the key 2 is down. If PA5 = low, the key 1 is down. If PA4 = low, the key 0 is down.
California State University, Northridge | 13
December 17, 2011 ECE 625 FINAL PROJECT REPORT
TESTING STRATEGY
The program is dumped into the microcontroller using the code warrior software that was given to us along with the kit.
The Program Flow (Fig 1.7)
The various steps to load/burn the code into the kit are as shown in the next page.
California State University, Northridge | 14
December 17, 2011 ECE 625 FINAL PROJECT REPORT
Note: The figures in the steps have not been mentioned in the table of contents as they have been displayed just as examples.
STEP 1: Code Warrior Development Tool
STEP 2: Example of File Menu
California State University, Northridge | 15
December 17, 2011 ECE 625 FINAL PROJECT REPORT
STEP 3: Startup Dialog
STEP 4: Creation of new project
California State University, Northridge | 16
December 17, 2011 ECE 625 FINAL PROJECT REPORT
STEP 5: Project created from template
Step 6: Change Full chip simulation to HCS12 Serial Monitor
California State University, Northridge | 17
December 17, 2011 ECE 625 FINAL PROJECT REPORT
Step 7: Compile project
Step 8: If needed, setup the port to COM1, and set Derivative to MC9S12DG256B
California State University, Northridge | 18
December 17, 2011 ECE 625 FINAL PROJECT REPORT
9
STEP 9: Debug the program. True time Simulator & Real time Debugger tool will start
California State University, Northridge | 19
December 17, 2011 ECE 625 FINAL PROJECT REPORT
STEP 10: Start/Continue (F5)
FLOW CHART
California State University, Northridge | 20
START
INITIALIZE KEYPAD
INTIALIZE LIQUID CRYSTAL
DISPLAY
CRYSTAL DISPLAY
CODE DETECTE
D 4 TIMES?
December 17, 2011 ECE 625 FINAL PROJECT REPORT
Flowchart of the project (Fig 1.8)
PROGRAM
#include <hidef.h> /* common defines and macros */#include "derivative.h" /* derivative-specific definitions */#include<string.h> #define LCD_DATA PORTK#define LCD_CTRL PORTK#define RS 0x01#define EN 0x02#define MAX 4
unsigned int i,j,k,inc,count, equal;unsigned int len,len1,len2,len3;unsigned char temp[4];
California State University, Northridge | 21
INCREMENT COUNT
DISPLAY APPROPRIATE MESSAGE ON THE LCD
NO
YES
December 17, 2011 ECE 625 FINAL PROJECT REPORT
unsigned char temp1[4]={"0625"};unsigned int value; unsigned int array[4];
unsigned char strings[]={"Password:"};unsigned char string1[]={"Welcome "};unsigned char string2[]={"INCORRECT CODE"};unsigned char string3[]={"SYSTEM LOCKED"};
void COMWRT4(unsigned char);void DATWRT4(unsigned char);void DATWRT4delay(unsigned char);void DATWRT5(unsigned int);void MSDelay(unsigned int);void defaultdisplay(void);void printstring1(void);void printstring2(void);void setLCD(void);void lockedstate(void);void funlockedstate(void);void keypadinput(void);
const unsigned char keypad[4][4] ={'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};unsigned char column,row;
/**************MAIN*******************************/void main(void){ unsigned int value; unsigned int array[4];
California State University, Northridge | 22
December 17, 2011 ECE 625 FINAL PROJECT REPORT
unsigned char temp[4]= {"1234"}; unsigned int equal=1; count = -1;k=1;inc = 0; len = strlen(strings); len1 = strlen(string1); len2 = strlen(string2); len3 = strlen(string3); DDRA = 0x0F; //OPEN MAIN DDRB = 0xFF; //MAKE PORTB OUTPUT DDRK = 0xFF; DDRJ |=0x02; PTJ &=~0x02; //ACTIVATE LED ARRAY ON PORT B DDRP |=0x0F; // PTP |=0x0F; //TURN OFF 7SEG LED DDRA = 0x0F; //MAKE ROWS INPUT AND COLUMNS OUTPUT defaultdisplay(); loop:while(1) { //OPEN WHILE(1) keypadinput();
while(1) { //OPEN while(1) PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x01; //COLUMN 0 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 0 column = 0; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN
California State University, Northridge | 23
December 17, 2011 ECE 625 FINAL PROJECT REPORT
PORTA |= 0x02; //COLUMN 1 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 1 column = 1; break; //BREAK OUT OF while(1) }
PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x04; //COLUMN 2 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 2 column = 2; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x08; //COLUMN 3 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 3 column = 3; break; //BREAK OUT OF while(1) } row = 0; //KEY NOT FOUND break; //step out of while(1) loop to not get stuck }//end while(1)
if(row == 0x10) { PORTB=keypad[0][column]; count++; //OUTPUT TO PORTB LED } else if(row == 0x20){ PORTB=keypad[1][column]; count++;
California State University, Northridge | 24
December 17, 2011 ECE 625 FINAL PROJECT REPORT
} else if(row == 0x40){ PORTB=keypad[2][column]; count++; } else if(row == 0x80){ PORTB=keypad[3][column]; count++; }
do{ MSDelay(15); PORTA = PORTA | 0x0F; //COLUMNS SET HIGH row = PORTA & 0xF0; //READ ROWS }while(row != 0x00); //MAKE SURE BUTTON IS NOT STILL HELD
value = (PORTB & 0xFF); array[count]= value; setLCD(); for(j=0;j<=count;j++) { if(MAX == j) { break; } else { DATWRT5(array[j]); MSDelay(1); } }
California State University, Northridge | 25
December 17, 2011 ECE 625 FINAL PROJECT REPORT
if(count==(MAX-1)) { for(i=0;i<4;i++) { if((temp[i]) != (array[i])) { equal = 0; } } if(equal==1) { printstring1(); MSDelay(1); for(i=0;i<10;i++) { PORTB = 0xAA; MSDelay(100); PORTB = 0x55; MSDelay(100); } break; } else { printstring2(); inc ++; if(inc==(MAX-1)) { lockedstate(); MSDelay(1); funlockedstate(); MSDelay(1); break; } defaultdisplay(); count = -1; equal = 1; goto loop;
California State University, Northridge | 26
December 17, 2011 ECE 625 FINAL PROJECT REPORT
} } } //End of if }// While close //} //MAIN close void printstring2() { COMWRT4(0x33); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x32); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x28); //Function set to four bit data length //2 line, 5 x 7 dot format MSDelay(1); COMWRT4(0x06); //entry mode set, increment, no shift MSDelay(1); COMWRT4(0x0E); //Display set, disp on, cursor on, blink off MSDelay(1); COMWRT4(0x01); //Clear display MSDelay(1); COMWRT4(0x80); //set start posistion, home position MSDelay(1); for(j=0;j<len2;j++) { DATWRT4delay(string2[j]); MSDelay(1); } } void lockedstate()
California State University, Northridge | 27
December 17, 2011 ECE 625 FINAL PROJECT REPORT
{ COMWRT4(0x33); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x32); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x28); //Function set to four bit data length //2 line, 5 x 7 dot format MSDelay(1); COMWRT4(0x06); //entry mode set, increment, no shift MSDelay(1); COMWRT4(0x0E); //Display set, disp on, cursor on, blink off MSDelay(1); COMWRT4(0x01); //Clear display MSDelay(1); COMWRT4(0x80); //set start posistion, home position MSDelay(1); for(j=0;j<len3;j++) { DATWRT4delay(string3[j]); MSDelay(1); } } void printstring1() { COMWRT4(0x33); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x32); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x28); //Function set to four bit data length //2 line, 5 x 7 dot format MSDelay(1); COMWRT4(0x06); //entry mode set, increment, no shift MSDelay(1); COMWRT4(0x0E); //Display set, disp on, cursor on, blink off MSDelay(1);
California State University, Northridge | 28
December 17, 2011 ECE 625 FINAL PROJECT REPORT
COMWRT4(0x01); //Clear display MSDelay(1); COMWRT4(0x80); //set start posistion, home position MSDelay(1); for(j=0;j<len1;j++) { DATWRT4delay(string1[j]); MSDelay(1); } }
void COMWRT4(unsigned char command) { unsigned char x; x = (command & 0xF0) >> 2; //shift high nibble to center of byte for Pk5-Pk2 LCD_DATA =LCD_DATA & ~0x3C; //clear bits Pk5-Pk2 LCD_DATA = LCD_DATA | x; //sends high nibble to PORTK MSDelay(1); LCD_CTRL = LCD_CTRL & ~RS; //set RS to command (RS=0) MSDelay(1); LCD_CTRL = LCD_CTRL | EN; //rais enable MSDelay(2); LCD_CTRL = LCD_CTRL & ~EN; //Drop enable to capture command MSDelay(1); //wait x = (command & 0x0F)<< 2; // shift low nibble to center of byte for Pk5-Pk2 LCD_DATA =LCD_DATA & ~0x3C; //clear bits Pk5-Pk2 LCD_DATA =LCD_DATA | x; //send low nibble to PORTK LCD_CTRL = LCD_CTRL | EN; //rais enable MSDelay(2); LCD_CTRL = LCD_CTRL & ~EN; //drop enable to capture command MSDelay(1); }
California State University, Northridge | 29
December 17, 2011 ECE 625 FINAL PROJECT REPORT
void DATWRT4(unsigned char data) { unsigned char x; x = (data & 0xF0) >> 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; MSDelay(1); LCD_CTRL = LCD_CTRL | RS; MSDelay(1); LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(1); x = (data & 0x0F)<< 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(1); } void DATWRT4delay(unsigned char data) { unsigned char x; x = (data & 0xF0) >> 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; MSDelay(1);
California State University, Northridge | 30
December 17, 2011 ECE 625 FINAL PROJECT REPORT
LCD_CTRL = LCD_CTRL | RS; MSDelay(1); LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(5); x = (data & 0x0F)<< 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(15); } void DATWRT5(unsigned int data) { unsigned char x; x = (data & 0xF0) >> 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; MSDelay(1); LCD_CTRL = LCD_CTRL | RS; MSDelay(1); LCD_CTRL = LCD_CTRL | EN; MSDelay(1); LCD_CTRL = LCD_CTRL & ~EN; MSDelay(2); x = (data & 0x0F)<< 2; LCD_DATA =LCD_DATA & ~0x3C; LCD_DATA = LCD_DATA | x; LCD_CTRL = LCD_CTRL | EN; MSDelay(1);
California State University, Northridge | 31
December 17, 2011 ECE 625 FINAL PROJECT REPORT
LCD_CTRL = LCD_CTRL & ~EN; MSDelay(1); }
void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i<itime;i++) for(j=0;j<4000;j++); }
void defaultdisplay(){ COMWRT4(0x33); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x32); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x28); //Function set to four bit data length //2 line, 5 x 7 dot format MSDelay(1); COMWRT4(0x06); //entry mode set, increment, no shift MSDelay(1); COMWRT4(0x0E); //Display set, disp on, cursor on, blink off MSDelay(1); COMWRT4(0x01); //Clear display MSDelay(1);
COMWRT4(0x80); //set start posistion, home position MSDelay(1); for(j=0;j<len;j++) { DATWRT4delay(strings[j]); MSDelay(1);
California State University, Northridge | 32
December 17, 2011 ECE 625 FINAL PROJECT REPORT
}}
void setLCD() { COMWRT4(0x33); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x32); //reset sequence provided by data sheet MSDelay(1); COMWRT4(0x28); //Function set to four bit data length //2 line, 5 x 7 dot format MSDelay(1); COMWRT4(0x06); //entry mode set, increment, no shift MSDelay(1); COMWRT4(0x0E); //Display set, disp on, cursor on, blink off MSDelay(1); COMWRT4(0x01); //Clear display MSDelay(1); COMWRT4(0x80); //set start posistion, home position MSDelay(1);}
void keypadinput(){ do{ //OPEN do1 PORTA = PORTA | 0x0F; //COLUMNS SET HIGH row = PORTA & 0xF0; //READ ROWS }while(row == 0x00); //WAIT UNTIL KEY PRESSED //CLOSE do1
do{ //OPEN do2 do{ //OPEN do3 MSDelay(1); //WAIT row = PORTA & 0xF0; //READ ROWS }while(row == 0x00); //CHECK FOR KEY PRESS //CLOSE do3
California State University, Northridge | 33
December 17, 2011 ECE 625 FINAL PROJECT REPORT
MSDelay(15); //WAIT FOR DEBOUNCE row = PORTA & 0xF0; }while(row == 0x00); //FALSE KEY PRESS //CLOSE do2
while(1) { //OPEN while(1) PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x01; //COLUMN 0 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 0 column = 0; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x02; //COLUMN 1 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 1 column = 1; break; //BREAK OUT OF while(1) }
PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x04; //COLUMN 2 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 2 column = 2; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x08; //COLUMN 3 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00)
California State University, Northridge | 34
December 17, 2011 ECE 625 FINAL PROJECT REPORT
{ //KEY IS IN COLUMN 3 column = 3; break; //BREAK OUT OF while(1) } row = 0; //KEY NOT FOUND break; //step out of while(1) loop to not get stuck }//end while(1) do{ //OPEN do1 PORTA = PORTA | 0x0F; //COLUMNS SET HIGH row = PORTA & 0xF0; //READ ROWS }while(row == 0x00); //WAIT UNTIL KEY PRESSED //CLOSE do1
do{ //OPEN do2 do{ //OPEN do3 MSDelay(1); //WAIT row = PORTA & 0xF0; //READ ROWS }while(row == 0x00); //CHECK FOR KEY PRESS //CLOSE do3 MSDelay(15); //WAIT FOR DEBOUNCE row = PORTA & 0xF0; }while(row == 0x00); //FALSE KEY PRESS //CLOSE do2
}
void funlockedstate() { int count = -1; int equal =1; defaultdisplay(); while(1) { //OPEN WHILE(1) keypadinput();
while(1) {
California State University, Northridge | 35
December 17, 2011 ECE 625 FINAL PROJECT REPORT
//OPEN while(1) PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x01; //COLUMN 0 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 0 column = 0; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x02; //COLUMN 1 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 1 column = 1; break; //BREAK OUT OF while(1) }
PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x04; //COLUMN 2 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 2 column = 2; break; //BREAK OUT OF while(1) } PORTA &= 0xF0; //CLEAR COLUMN PORTA |= 0x08; //COLUMN 3 SET HIGH row = PORTA & 0xF0; //READ ROWS if(row != 0x00) { //KEY IS IN COLUMN 3 column = 3; break; //BREAK OUT OF while(1) } row = 0; //KEY NOT FOUND break; //step out of while(1) loop to not get stuck }//end while(1)
California State University, Northridge | 36
December 17, 2011 ECE 625 FINAL PROJECT REPORT
if(row == 0x10) { PORTB=keypad[0][column]; count++; //OUTPUT TO PORTB LED } else if(row == 0x20){ PORTB=keypad[1][column]; count++; } else if(row == 0x40){ PORTB=keypad[2][column]; count++; } else if(row == 0x80){ PORTB=keypad[3][column]; count++; }
do{ MSDelay(15); PORTA = PORTA | 0x0F; //COLUMNS SET HIGH row = PORTA & 0xF0; //READ ROWS }while(row != 0x00); //MAKE SURE BUTTON IS NOT STILL HELD
value = (PORTB & 0xFF); array[count]= value; setLCD(); for(j=0;j<=count;j++) {
California State University, Northridge | 37
December 17, 2011 ECE 625 FINAL PROJECT REPORT
if(MAX == j) { break; } else { DATWRT5(array[j]); MSDelay(1); } }
if(count==(MAX-1)) { for(i=0;i<4;i++) { if((temp1[i]) != (array[i])) { equal = 0; } } if(equal==1) { printstring1(); MSDelay(1); for(i=0;i<10;i++) { PORTB = 0xAA; MSDelay(100); PORTB = 0x55; MSDelay(100); } break; } else { lockedstate(); MSDelay(1); defaultdisplay(); MSDelay(1);
California State University, Northridge | 38
December 17, 2011 ECE 625 FINAL PROJECT REPORT
count = -1; equal =1; } } }}
ADVANTAGES
The main advantages of this device are as follows:
Highly secure
Flexible & Reprogrammable
Wide operating range & wide operating area
Less power consumption
Remotely controlled
Cost effective & easily available
DISCUSSION
The main part of our project is that we must design a locking system that does not need a physical key to unlock. It can be done using a keypad stuck to some wall. And of course, when the digital key is being put into the system for verification, we need a device that will tell us whether the input key code is correct or not. For this feature, we used the Liquid crystal display (LCD). We chose to order the Dragon 12 plus kit which had all the required features for our
California State University, Northridge | 39
December 17, 2011 ECE 625 FINAL PROJECT REPORT
project. We studied about the keypad module and the LCD display on our kit with the help of the documentation provided to us with the kit and worked a program to configure this design successfully.
CONCLUSION
The working of the keypad module has been studied and interfaced to the microcontroller for application development. We also learnt to interface the LCD display with the microcontroller. We have worked on a program and have implemented a complete working model using a Microcontroller, successfully. The programming and interfacing of microcontroller has been mastered during the implementation.
This Project describes a design of digital door locking system. We successfully demonstrated the working of the project in the below youtube link:http://www.youtube.com/watch?v=YmsBJHufWFo
California State University, Northridge | 40