'---------------------------------------------------------- 'Comblck2.bs2 electronic combination lock 'Original program for BS1 by Jim Steinman 'Modifed to work on BS2 by Gerry Crenshaw WD4BIS '--------Jims Original Notes-------------------------------- 'This program implements a combination lock that I used for a garage 'door opener. The stamp reads keypresses from a surplus telephone 'keypad and checks that the correct key is pressed and not too much 'time expires between subsequent keypresses. If a wrong number is 'entered, the user is penalized with a 10 second lockout, during which 'the keyboard is ignored. When the lockout time is up, you simply 'start over from the beginning. Wrong keys are counted and if more 'than three occur, then someone is clearly trying to "break in" and a '10 minute lockout is initiated. The wrong key counter can only be 'cleared by entering the correct combination or resetting the stamp 'Key debounce is taken care of inherently because the program waits 'for each key to be released before scanning for another. '---------Gerrys Notes on converting program to BS2----------- 'All () changed to [] 'Removed all variables after Next statements 'changed SKIP labels to SKIPIT. SKIP is a reserved word in the BS2. 'Changed PINS to INS 'Changed LED outputs to p14 and p15 'keyboard wiring stamp pin3 connects to row1----1 2 3 ' " pin4 " " row2----4 5 6 ' " pin5 " " row3----7 8 9 ' " pin0 " " column1----| | | ' " pin1 " " column2------| | ' " pin2 " " column3--------| '*****important: columns 1,2,& 3 are also pulled to ground with '10 k resistors. ie-connect 3 resistors from pin0 to ground, 'pin1 to ground and pin2 to ground. 'star, zero, and pound keys are ignored due to i/o shortage 'register usage pin usage 'w0 b0-keyboard read pin0-keyboard column input ' b1-1st number pin1-keyboard column input 'w1 b2-2nd number pin2-keyboard column input ' b3-3rd number pin3-keyboard row output 'w2 b4-4th number pin4-keyboard row output ' b5-lookup result pin5-keyboard row output 'w3 b6-main loop pin14-output-led1-red-indicator ' b7-wrong key counter pin15-output-led2-green-actuator 'w4 b8-expiry and lockout counter ' b9- " " -once everything is working, led1 can be 'w5 b10-scan loop be used for something else (it is only ' b11-spare there to indicate keypresses) and led2 can 'w6 b12-stack be replaced with a relay or something ' b13- " suitable to activate your equipment 'this is the password-enter your own here b1=1 'number for 1st keypress b2=6 'number for 2nd keypress b3=1 'number for 3rd keypress b4=8 'number for 4th keypress init: dirs=%11111000 'set up pins b7=0 'zero wrong key counter '----------main loop---------------------------------------------- start: for b6=0 to 3 'get each of the 4 key presses in turn w4=0 'zero expire counter looplo: gosub scan 'read keys if b0<>0 then looplo 'loop till no key is pressed-you must 'release a key before pressing another loophi: 'loop till a key is pressed or till 'time is expired-unless in first pass if b6=0 then fetchkey 'in first pass so go ahead w4=w4 + 1 'increment counter if w4>500 then start 'time is expired-exit and start over '500 counts is about 3 secs fetchkey: gosub scan 'read keys if b0=0 then loophi 'loop till key is pressed lookup b6,[b1,b2,b3,b4],b5 'check what key is pressed if b0<>b5 then lockout 'wrong key pressed so lockout pulsout 14,3000 'correct key pressed-flash led1-30 mS pulse next ' b6:get remaining key presses 'okay this is it-we've got the password b7=0 'clear the wrong key counter High 15 'turn on led2 pause 1000 '----activate your equipment here--- low 15 'turn off led2 goto start '--------end of main loop----------------------------------------- 'returns with 0 in b0 if no key is scan: for b10=3 to 5 'pressed or the value of the key high b10 'put each row high in turn b0=ins & %00000111 'read columns and mask unused bits low b10 if b0>0 then gotkey 'a key has been pressed so jump ahead next return 'no key was pressed so exit gotkey:if b0<>4 then skipit 'b0 will contain 1,2 or 4 b0=3 'change this to 1,2 or 3 skipit:b10=b10-3*3 'convert to numeric value of key b0=b0+b10 return 'return with value in b0 '10 second lockout lockout:b7=b7+1 'increment wrong key counter if b7>3 then longlock 'only 3 wrong keys are allowed for w4=1 to 100 toggle 14 'blink led1 pause 100 next goto start longlock:for w4=1 to 6000 '10 minute lockout-too many wrong keys toggle 14 'blink led1 pause 100 next goto start