Friday, November 8, 2013

Software and Conclusion

CCS Software

We use CCS software to program for microcontroller PIC. The program is the integration of three separate compliers for three different PIC families:
  • PCB for PIC 12-bit opcodes
  • PCM for PIC 14-bit opcodes
  • PCH for PIC 16 and 18-bit

PIC 16F877a is a PIC 14, so we can use the CCS software to program for it with C language.
The basic structure of the program when using C language:
#include, #device, #use, #fuse….// pre-processor directives.
#define, int8 ..........// data definitions, declare constant, variable…
Void Function () {} // function definition
Void main () {// main program.}

Algorithm Block Diagram


Significant Code

void Scan_keyboard()
{  
PORTB=0xfe;    // 1111 1110 Checking row 1 pressed.
           if(RB4==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB5==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB6==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB7==0) {  program;while(RB4==0)   {do nothing}  }
PORTB=0xfd;  // 1111 1101 Checking row 2 pressed.
    if(RB4==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB5==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB6==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB7==0) {  program;while(RB4==0)   {do nothing}  }
      PORTB=0xfb;  // 1111 1011 Checking row 3 pressed.
    if(RB4==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB5==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB6==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB7==0) {  program;while(RB4==0)   {do nothing}  }     
     PORTB=0xf7;  // 1111 0111 Checking row 4 pressed.
    if(RB4==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB5==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB6==0) {  program;while(RB4==0)   {do nothing}  }
    if(RB7==0) {  program;while(RB4==0)   {do nothing}  }
  }
------------------------------------------------------------------------------------------------
Void check()
{
     lcd_putcmd(line_1);
     printf(LCD_PutChar,"CHECKING........");
     delay_ms(600);
     for(j=0;j<=8;j++)
     if(read_eeprom(0x00+j)-b[j]!=0)
     {
         write_eeprom(0x09,read_eeprom(0x09)+1);
         wrong();
     }
     else count=count+1;
     if (count==9)
     {  LCD_PutCmd(Clear_Scr);
        lcd_putcmd(line_1);
        RC6=1;RC7=0;;i=0;
        write_eeprom(0x09,0);
        printf(LCD_PutChar,"OPENING.....");      
     }                        
}

The code and simulation file of the project can be downloaded with the following link:


Conclusion

With the system operating in our project, from simulation in Proteus software program, we can produce the real system.

Because of working in prototype, if we use the high-power motor to pull the door opening or closing, we will calculate so much. To apply for reality, our system needs to adjust to increase the stability and connect with the mechanical part.

Nowadays, the other digital lock systems have used many modern modes: card, finger print… However, the price is not cheap. Thus, our system still has certainly applications, so we will afford to finish completely our project to suitable with the reality demand.

Saturday, October 5, 2013

Hardware

Control Block

We use micro-controller PIC 16F877a with:
  • 40 pins. 5 I/O ports RA, RB, RC, RD, RE.
  • Up to 256 x 8 bytes of EEPROM Data Memory
Figure 1: PIC16F877

 Choosing the ports connect with peripheral device:

+ Because of in CCS software support file LCD.C default using in PORTD, so we use port RD to connect with the LCD. Set up: SET_TRIS_D(0x00).
  • Pins RD4 => RD7 of PIC connect with data pins D4 => D7 of LCD.
  • Pin RD0 of PIC connects with enable pin (E) of LCD.
  • Pin RD1 of PIC connects with pin RS – Register Selected of LCD
  • Pin RD2 of PIC connects with pin RW – Read/Write selecting mode of LCD.

+ Choosing port RB connecting with the 4x4 keyboard.
+ Choosing port RC to control the motor, switches and alert (using led).
  • Pins RC0, RC1 connect to switches to control the motor stopping.
  • Pins RC6, RC7 control motor through H bridge circuit.
  • Pins RB5 send the signal to warning system.

Display Block

The display block is the LCD 16x2.
Figure 2: LCD's pins

When making the LCD, manufacture integrated control chip (HD44780) inside and only bring out necessary pins. The HD44780 has two importance 8 bit register: IR (Instructor Register), DR (Data Register).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. By controlling two pins RS and R/W, we can shift between two register when communicate with MPU. The table below is the set up with two pins RS and R/W:

RS
R/W

0
0
Write to RS register to order the register
0
1
Read the busy flag at DB7 and the value of address counter at DB0-DB6
1
0
Write to the DR register
1
1
Read data from DR

In the program using LCD at mode 4 bit. The instruction using:
  • lcd_send_byte( BYTE address, BYTE n ) to control LCD. For example the instruction: lcd_send_byte(0,0x01) using to clear screen, lcd_send_byte(0,0x08) display off without clearing.
  • lcd_gotoxy(a,b): set write position x,y on LCD .
  • printf(lcd_putc,”…”): display a string < 16 characters on the LCD.
  •  lcd_putc(‘…’) : display a character on the next position on the LCD .

Keyboard Block

Figure 3: Keyboard block
  • Communicating with PIC 16F877a, to display, enter password, change password, open and close the door…
  • Using 4x4 keyboards with the key number from 0 => 9 and functional key: open door, close door, change pass.
  • To connect with microcontroller, we need to connect 8 inputs of keyboards with pull up resistor to the power terminal. 

Amplifier Signal Block (Motor)

Figure 4: Motor block

  • Forward controlling mode:


In this mode, 4 signals controlling connected in 4 transistors and the condition of forward current flow through load (motor):
+ Signal 1 = 1 (opened transistor Q1).
+ Signal 2 = 0 (closed transistor Q2)
+ Signal 3 = 0 (closed transistor Q3)
+ Signal 4 = 1 (opened transistor Q4)
The current flows as in the figure 5.
Figure 5: Forward controlling mode

  • Reverse controlling mode:


This mode, we also connect 4 signals controlling in 4 transistors. And 4 signals controlling should satisfy with the condition:
+ Signal 1 = 0 (Closed transistor Q1).
+ Signal 2 = 1 (Opened transistor Q2)
+ Signal 3 = 1 (Opened transistor Q3)
+ Signal 4 = 0 (Closed transistor Q4)
And the current flows as in the figure 6.
Figure 6: Reverse controlling mode

Power Supply Block


We create the 5V source to supply to micro-controller. Using AC source connects to diode bridge circuit to make the DC voltage, through the capacitor to reduce noise. Using IC7805 stabilizes the output voltage.

Schematic Diagram




Sunday, September 15, 2013

System Analysis

Block Diagram of General System

Figure 1: Operation Block Diagram
  • User-interface and Information Display: use to transfer the signal, information to the controller.
  • The controller: receives the information and process that data. Sent signal out to control the operating devices.
  • Devices: motor, relay...to control the door or the lock.

Call Graph Diagram


Figure 2: Call graph diagram between hardware and software

System Specific Diagram

System Module



Friday, August 23, 2013

Basic Idea

Problems

With each family, offices, companies, business, schools and everywhere, we're completely need to secure our properties. Every door we should equip with a lock. Current markets are having many lock types and usually are mechanical lock; this mechanical lock had a big problem were low security, because it's easy to break by multipurpose kit.

Digital Locks generally are the security lock to prevent the devices, the property… from stealing. And when we want to unlock, we need to use the installed code. There are 2 general types in current market are Electric Digital Locks and Mechanic Digital Locks.
  •  Mechanic Digital Lock: when unlock or lock we need to rotate the numerical circle in the lock to make a sequence couple with the installed sequence and the lock be unlocked.
  • Electric Digital Lock: when unlock the lock, we need to enter the password is a sequence of numerical. If it's correct, the lock will be opened.
Generally, the Electric Digital Locks have more character and number to be installed, and longer of character sequence than Mechanic Digital Lock, so that Electric Digital Lock has the higher security. On the other hand, the actions in the Electric Digital Lock are easier with keyboard replace with rotate circle in the Mechanic Digital Lock. Moreover, when we want to change the password, it’s seemed to be easier because of keyboard action.

Electrical Digital Lock has high security, easy to use and have the alert action if we enter incorrect password more than condition times. The user interface, display the information about enter password, alert, changing the password make user more easily to use.

Figure 1: The digital lock with LCD display user interface

Coming up with the problems, we try to design and simulate the Digital Lock system, so that we can understand more about this system and figure out some solutions to improve it.


System Requirements

After consider many types of digital lock in current market, we have some requirements of a normal digital lock

  • User interface easy to use.
  • The password's length has high security.
  • Password can change.
  • Alert function when enter incorrect password 3 times.
  • Rotate motor to control the door have precisely open and close.
  •  The system work even when the electrics are shut down.
  •  Portable digital lock system.
  • The low voltage power used in lock system, do not make user into danger.


Component Selection

With the above requirement about the functions, we have chosen the main components:

  • Micro Controller 16f877 with the EEPROM memory can storage the data even the electrics are gone out.
  • LCD 16x2 display to show the information, to communicate with user.
  • 16-key keyboard have numerical key and the function key to enter password and the open-close order to micro controller.
  • Motor to control door open and close.
  • Power supply prevent of power failure is accumulator.


Approaching Method

The most important of the digital lock is the keyboard scanning algorithm, and then is the saving and changing the password on the EEPROM. Also, we need some other parts are display the information into LCD display; it's also have some library installed so it's not complicate. Finally, it's the signal out to control the lock door. Therefore, the main algorithms we need to consider are:
  • Key scanning algorithms.
  • Password storage in EEPROM and changing password in EEPROM
  • Display the information into LCD display.


CO