'------------------------------------------------------------------------------- ' ! D E M O P R O G R A M ! '------------------------------------------------------------------------------- ' Code is consisted of 4 digits. ' 1 user code is entered in the program. ' File:code11eng.bas '------------------------------------------------------------------------------- ' Code is consisted of 1 to 4 digits. ' 1 user code is entered via keypad. ' File:code11-1.hex '------------------------------------------------------------------------------- ' Code is consisted of 1 to 8 digits. ' 8 user codes are entered via keypad. ' File:code11-2.hex '------------------------------------------------------------------------------- 'Project: CodeLock 8051 'File: code11eng.bas 'Copyright: Kripa PURI 'WWW: www.avr.4mg.com 'Device: Atmel AT89C2051 'Date: 1.2.2005 'Compiler: Bascom 8051 '------------------------------------------------------------------------------- $regfile = "89c2051.dat" $crystal = 4000000 'Type of variables Dim Keyread As Byte Dim Code As Word Dim Usercode As Word Dim Count As Byte Dim Errorcon As Byte Dim K As Byte Dim N As Byte Dim P As Byte 'Initial output states P1 = 255 P3 = 255 P3.3 = 1 P3.4 = 0 'Alias variables Relay Alias P3.4 Beep Alias P3.3 'Keyboard Columns Y1 Alias P1.1 Y2 Alias P1.2 Y3 Alias P1.3 'Keyboard Rows X1 Alias P1.4 X2 Alias P1.5 X3 Alias P1.6 X4 Alias P1.7 '------------------------------------------------------------------------------- 'Key Pad Debounce setup Config Debounce = 40 '------------------------------------------------------------------------------- 'Setting your own user code (Here you set up your own user code) Usercode = 5510 '------------------------------------------------------------------------------- 'Error counter Errorcon = 0 '------------------------------------------------------------------------------- '------------------------------------------------------------------------------- Do Begin: Code = 0 Count = 0 '------------------------------------------------------------------------------- 'Keypad Read Routine Do 'Turns Column 1 On (Low) Y1 = 0 : Y2 = 1 : Y3 = 1 Keyread = 1 Debounce X1 , 0 , Gotkey , Sub Keyread = 4 Debounce X2 , 0 , Gotkey , Sub Keyread = 7 Debounce X3 , 0 , Gotkey , Sub 'Key (*) Keyread = 11 Debounce X4 , 0 , Gotkey , Sub 'Turns Column 2 On (Low) Y1 = 1 : Y2 = 0 : Y3 = 1 Keyread = 2 Debounce X1 , 0 , Gotkey , Sub Keyread = 5 Debounce X2 , 0 , Gotkey , Sub Keyread = 8 Debounce X3 , 0 , Gotkey , Sub Keyread = 0 Debounce X4 , 0 , Gotkey , Sub 'Turns Column 3 On (Low) Y1 = 1 : Y2 = 1 : Y3 = 0 Keyread = 3 Debounce X1 , 0 , Gotkey , Sub Keyread = 6 Debounce X2 , 0 , Gotkey , Sub Keyread = 9 Debounce X3 , 0 , Gotkey , Sub 'Key (#) Keyread = 12 Debounce X4 , 0 , Gotkey , Sub Loop Loop '------------------------------------------------------------------------------- Gotkey: 'One beep for accepted Keyread Reset Beep Waitms 100 Set Beep Waitms 100 '------------------------------------------------------------------------------- 'Select the action, (*)(Keyread 11 = menu) and (#)(Keyread 12 = enter) If Keyread = 11 Then Goto Menu If Keyread = 12 Then Goto Check '------------------------------------------------------------------------------- 'Count Keyread No Incr Count If Count > 4 Then Goto Error 'Assemble Keyread No in Code Code = Code * 10 Code = Code + Keyread 'Back to Keypad Read Routine Return '------------------------------------------------------------------------------- '------------------------------------------------------------------------------- Check: If Code = Usercode Then Goto Opendoor Else Goto Error End If Goto Begin '------------------------------------------------------------------------------- '10 beeps for Error Error: K = 9 : P = 100 : Gosub Beeper Incr Errorcon If Errorcon = 3 Then Wait 60 Errorcon = 0 End If Goto Begin '------------------------------------------------------------------------------- Opendoor: Gosub Ok Set Relay 'Relay is switched on for 2 sec Wait 2 Reset Relay Errorcon = 0 Goto Begin '------------------------------------------------------------------------------- Beeper: Waitms 100 For N = 1 To K Reset Beep Waitms P Set Beep Waitms P Next N Return '------------------------------------------------------------------------------- '2 beeps for OK Ok: Waitms 100 K = 2 P = 200 Gosub Beeper Return '------------------------------------------------------------------------------- 'Menu works only in the files: code11-1.hex and code11-2.hex Menu: Wait 1 Gosub Ok Gosub Ok Gosub Ok Goto Begin '-------------------------------------------------------------------------------