Advertisement  

Monday, 26 June 2017
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #144 - CodeLock AVR Print
CodeLockAVR - electronic combination lock with AT90S2313
by Rudi Šlejkovec, rudi.slejkovec@siol.net

CodeLock electronic combination lock is realised with Atmel AVR microcontroller AT90S2313. Program in hex code is 2 kB long. User code is consisted of 1 to 4 digits.
If the code is entered in the correct sequence, then after 1 second the relay and the electric striker (in the door) switch on for 1 second and then switch off again.
User code can be changed via 3x4 matrix keypad. Keypad can be bought at local electronic shop.
Initial user code (1234) is set up with a jumper. The jumper must be inserted before the voltage (12V) connection. The jumper must be removed after 2 beeps.



LCD display is an option!

Signaling
Each pressed key is immediately confirmed with one short beep. Two short beeps follow after entering the right user code. One long beep appears when entering the wrong user code. The keypad is blocked for 20 seconds for each incorrect action. User code is retained even in the event of a power failure.
You can use a LED diode instead of a Beeper. Look at the code lock electric circuit diagram.
The third row of the keypad (numbers 7, 8 and 9) can be unpluged. In that way you get 3x3 matrix keypad. If the additional row (the second one) of the keypad is also unpluged you get 3x2 matrix keypad. In that way you can use only: 1, 2, 3, *, 0 and # keys.

In short:

1. OPENING (For the first time): 1 2 3 4 #
The relay is being activated for 1 second.

2. WRITING YOUR CODE (For the first time): * 1 2 3 4 # 5 5 1 0 #
For opening the door press: 5 5 1 0 # (5 5 1 0 is your code)
The relay is being activated for 1 second.

3. CHANGING THE CODE: * OldCode # NewCode #
Example: * 5 5 1 0 # 6 6 1 0 #
Two short beeps indicate that new user code is written.
For opening the door press: 6 6 1 0 #
The relay is being activated for 1 second.

Circuit diagram





Sample program :

'-------------------------------------
' ! D E M O P R O G R A M !
'-------------------------------------
' Code is consisted of 4 digits.
' 1 user code is entered in program.
' File:codelcd-D.bas you can download on:
' http://www.avr.4mg.com/custom3.html
'
' Code is consisted of 1 to 4 digits.
' 1 user code is entered via keypad.
' File:codelcd.hex you can download on:
' http://www.avr.4mg.com/custom3.html
'-------------------------------------
' Professional version:
' Code is consisted of 4 to 12 digits.
' File:codelcd6.hex,codelcd40.hex
' 6 or 40 user codes.
' Current in stand-by is 4 mA.
'-------------------------------------
'-------------------------------------
'Project: CodeLockAVR - LCD
' File:codelcd-D.bas
'Copyright: Rudi Slejkovec
'WWW: www.avr.4mg.com
'Device: Atmel AVR uC
'Date: 5.2.2005
'-------------------------------------

$regfile = "2313def.dat"
$crystal = 4000000

Dim Keyread As Byte
Dim Key As Byte
Dim Code As Word
Dim Mycode As Word
Dim Digits As Byte
Dim Point As Byte

Ddrd = 255
Portd = 0

Relay
Alias Portd.4
Beep
Alias Portd.3

Config Kbd = Portb , Debounce = 40

Config Lcd = 16 * 2
'Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3
'Enable = Portd.6 , Rs = Portd.5
'-------------------------------------
'Standard LCD 2x16; type:CMC216x01 or sim.; www.cct.com.my
'pin1: Ground(-)
'pin2: Supply(+)
'pin3: Supply(0V-5V DC) for LCD Contrast Level
'pin4: RS Signal
'pin5: R/W Selection
'pin6: Enable Signal
'pin7: Db0 (Data Bus Line)
'pin8: Db1 (Data Bus Line)
'pin9: Db2 (Data Bus Line)
'pin10: Db3 (Data Bus Line)
'pin11: Db4 (Data Bus Line)
'pin12: Db5 (Data Bus Line)
'pin13: Db6 (Data Bus Line)
'pin14: Db7 (Data Bus Line)
'pin15: Backlight Ground(-)
'pin16: Backlight Supply(+)
'-------------------------------------


'-------------------------------------
Mycode
= 5060
'-------------------------------------



Do
    Cls
    Cursor Off Noblink
    Lcd "WWW.AVR.4MG.COM"
    Wait 2
    Lowerline
    Lcd "CodeLockAVRdemo"
    Wait 4
    Cls

    Set Beep
    Waitms 100
    Reset Beep
    Waitms 100

Begin
:
    Code
= 0
    Digits
= 0
    Point
= 0

Scan
:
    Cls
    Lcd " Enter code"
Do
    Keyread
= Getkbd()
        If Keyread <> 16 Then Gosub Gotkey
        Waitms 100
            If Digits = 4 Then
 
If Code = Mycode Then
 
Goto Opendoor
 
Else
 
Goto Error
 
End If
            End If
Loop

Loop



Gotkey
:
    Ddrb = 255
    Set Beep
    Waitms 100
    Reset Beep
    Waitms 100

    Key
= Lookup(keyread , Dta)

    Incr Digits
    Point
= Digits + 6
    Locate 2 , Point
    Lcd "*"
    Code
= Code * 10
    Code
= Code + Key
Return

Dta
:
    Data 12 , 9 , 6 , 3 , 0 , 8 , 5 , 2 , 11 , 7 , 4 , 1

Error
:
    Cls
    Lcd " Code wrong"
    Waitms 100
    Set Beep
    Wait 3
    Reset Beep
    Wait 20
    Goto Begin

Ok
:
    Waitms 100
    Set Beep
    Waitms 200
    Reset Beep
    Waitms 200
    Set Beep
    Waitms 200
    Reset Beep
    Return

Opendoor
:
    Cls
    Lcd " Code accepted"
    Gosub Ok
    Lowerline
    Lcd " Unlocked"
    Waitms 300
    Set Relay
    Wait 1
    Reset Relay
    Wait 1
    Goto Begin