في هذا المشروع ، ستتعلم كيفية إنشاء نظام إدخال للوحة المفاتيح مكون من 12 مفتاحًا يفتح نفسه فقط عند إدخال رمز المرور الصحيح.
يستخدم المشروع الموضح هنا PCB مخصصًا مصنوعًا على آلة طحن. ومع ذلك ، يمكن إجراء هذا المشروع بنفس السهولة على لوح التجارب أو اللوح الشريطي لأولئك الذين لا يرغبون في استخدام ثنائي الفينيل متعدد الكلور مخصص. إذا كنت تنوي إنشاء هذا المشروع لأغراض الأمان ، فيجب أن تكون لوحة المفاتيح منفصلة عن وحدة التحكم الرئيسية. هذا لمنع الأفراد من اختراق الدائرة عن طريق إجبار الملف اللولبي على الفتح.
كود المشروع
#include <p16f88.inc>
; ===================================================
; Define variables
; ===================================================
dCounter equ 0x70 ; Counter for delays
passLength equ 0x71 ; Password length
tempPort equ 0x72 ; Used to hold numbers
entDone equ 0x73 ; Enter key press flag
fsrTable equ 0x74 ; Counter for indirect register
fsrPass equ 0x75 ;
tempData equ 0x76
numberTable equ 0x20 ; Table for recorded
password equ 0xA0 ; Password location
; ===================================================
org 0x0000
goto setup
; ===================================================
; Setup code
; ===================================================
setup nop
#include "setup.inc"
goto main
; ===================================================
#include "delay.inc"
; ===================================================
; Main program code
; ===================================================
main movlw password
movwf FSR
;****************************************************
; Set password here
;****************************************************
movlw 0x08
movwf INDF
incf FSR
movlw 0x05
movwf INDF
incf FSR
movlw 0x01
movwf INDF
incf FSR
movlw 0x00
movwf INDF
incf FSR
movlw 0x0A ; < End of password value
movwf INDF
incf FSR
movlw 0x04
movwf passLength
movlw numberTable
movwf FSR
;****************************************************
mainloop nop
clrf entDone
keyStart nop
banksel PORTB
movlw 0x01
movwf PORTB
keyScanR1
banksel PORTA
clrf PORTA
movfw PORTA
andlw 0x0F
btfsc STATUS, Z
goto keyScanR2
movwf tempPort
zeroTest btfss tempPort, 0
goto oneTest
movlw 0x00
movwf INDF
incf FSR
goto ksr1end
oneTest btfss tempPort, 1
goto twoTest
movlw 0x01
movwf INDF
incf FSR
goto ksr1end
twoTest btfss tempPort, 2
goto threeTest
movlw 0x02
movwf INDF
incf FSR
goto ksr1end
threeTest btfss tempPort, 3
goto ksr1end
movlw 0x03
movwf INDF
incf FSR
goto ksr1end
ksr1end call beepShrt
ksr1Wait movfw PORTA
andlw 0x0F
btfss STATUS, Z
goto ksr1Wait
keyScanR2
banksel PORTA
movlw 0x02
movwf PORTB
clrf PORTA
movfw PORTA
andlw 0x0F
btfsc STATUS, Z
goto keyScanR3
movwf tempPort
fourTest btfss tempPort, 0
goto fiveTest
movlw 0x04
movwf INDF
incf FSR
goto ksr2end
fiveTest btfss tempPort, 1
goto sixTest
movlw 0x05
movwf INDF
incf FSR
goto ksr2end
sixTest btfss tempPort, 2
goto sevTest
movlw 0x06
movwf INDF
incf FSR
goto ksr2end
sevTest btfss tempPort, 3
goto ksr2end
movlw 0x07
movwf INDF
incf FSR
goto ksr2end
ksr2end call beepShrt
ksr2Wait movfw PORTA
andlw 0x0F
btfss STATUS, Z
goto ksr2Wait
keyScanR3
banksel PORTA
movlw 0x04
movwf PORTB
clrf PORTA
movfw PORTA
andlw 0x0F
btfsc STATUS, Z
goto keyScanEnd
movwf tempPort
eightTest btfss tempPort, 0
goto nineTest
movlw 0x08
movwf INDF
incf FSR
goto ksr3end
nineTest btfss tempPort, 1
goto resTest
movlw 0x09
movwf INDF
incf FSR
goto ksr3end
resTest btfss tempPort, 2
goto entTest
movlw numberTable
movwf FSR
goto ksr3end
entTest btfss tempPort, 3
goto ksr3end
movlw 0x0A
movwf INDF
movlw 0xFF
movwf entDone
goto ksr3end
ksr3end call beepShrt
ksr3Wait movfw PORTA
andlw 0x0F
btfss STATUS, Z
goto ksr3Wait
keyScanEnd btfss entDone, 7
goto mainloop
movlw numberTable
movwf fsrTable
movlw password
movwf fsrPass
passCheck movfw fsrTable
movwf FSR
movfw INDF
movwf tempData
movfw fsrPass
movwf FSR
movfw INDF
subwf tempData, 1
btfss STATUS, Z
goto passwordBad
sublw 0x0A
btfsc STATUS, Z
goto passwordOK
incf fsrTable
incf fsrPass
goto passCheck
passwordOK nop
banksel PORTB
bsf PORTB, 4
call beepShrt
call beepShrt
call beepShrt
call beepShrt
call beepShrt
call beepShrt
call beepShrt
call beepShrt
waitForLock btfss PORTA, 6
goto waitForLock
bcf PORTB, 4
movlw numberTable
movwf FSR
goto mainloop
passwordBad call beepShrt
call beepShrt
movlw numberTable
movwf FSR
goto mainloop
end