首页 >> 项目方案 >> 正文
密码控制门项目
字体放大 字体缩小 字体恢复 杏仁黄 秋叶褐 胭脂红 芥末绿 天蓝 雪青 灰 银河白(默认色)

密码控制门项目

 
Abstract
This manual is intended to give instructions on installation of the system, use of the system, and troubleshooting of the system. A layperson who is familiar with basic electrical wiring, carpentry and electronics will find this manual sufficient to install the automatic door opener system. The instructions for use of the system are intended for any adult user to understand. The troubleshooting manual is written so that someone familiar with electronics should be able to debug the system. The basic function of the system is as follows. The Automatic Door Opener, will be operated by a remote control. With just a touch of a button on the remote control, the user can open or close the door by herself, without the help of anyone, giving her more independence in her life. This device can also be operated using a pushbutton or a keypad, and can also be accessed using the conventional key bypass. Since the original manual operation is remained in this design, the Automatic Door Opener can be operated manually during power failure.

;;歌林电子制作工作室www.nbglin.com
;;更多内容请选购本工作室光盘
System Components
The Door Opener contains many commercially available components and a prototype PCB circuit which links them all together. The commercially available components are:
Stanley Magic Access Door Opener
Weiser Lock Electronic Deadbolt (Powerbolt 3000)
HES Electronic Strike (series 5724)
Push Plate (model AC-TS2)
Volgen 30W Power Supply
Linx keyfob transmitter
The User Manuals that were included with each of these components are contained in the appendix. A technical description and trouble shooting guide for the system is also given in the appendix.

Installation instructions
Proper installation of the devices is very important to the reliability of the system. The instructions included in the manuals (see appendix) for the individual components should be followed carefully.

Power: A dedicated 120VAC circuit (own circuit breaker) should be installed to power the system. The 120VAC circuit should be run using 12AWG or 14AWG Romex cable with a 20 Amp circuit breaker at the panel. The circuit should be wired directly into the Stanley Door Opener Header or to an outlet next to the header which the device can be plugged into. The 120VAC connections inside the Stanley Door Opener Header are shown below.

Figure 1: 120VAC connections to Door Opener and Power Supply

Stanley Door Opener: The Stanley Manual includes installation instructions for many applications. This application is a “Door Attachment – In” with “No Breakout”. The instructions for this type of installation are on pages 3 and 4 of the Stanley manual. Most of the mounting holes in the header are not predrilled and must be done so by the installer. The door opener terminals OP and CM on the Stanley PCB are connected to the door opener terminals on the prototype PCB.

Power Supply: The 12VDC power supply is mounted inside the Stanley Door Opener header. The 120VAC input is connected to the power supply as shown in figure 1 above. The 12VDC output is also shown in the figure and should be made from a twisted pair.

Electronic Strike: The electronic strike should be installed so as to replace the existing strike to work with the door handle. The strike is connected to the PCB via terminal connectors. Note that the strike has a 12V wire and a ground wire.

Electronic Deadbolt: The electronic deadbolt can be placed at any available and convenient location on the door.

Prototype Circuit Box: The circuit should be placed in proximity to the deadbolt because it contains a transmitter which communicates with the deadbolt. The greatest concern when installing the circuit box is that it not be shielded by grounded metal. If the circuit becomes shielded, the remote receiver will not operate. The box is not weatherproof so it must be placed in a dry location. The box should be accessible to the home owner because there is some general maintenance required.

Keypad: The keypad must be placed outside the door in a preferable location. In order to weatherproof the keypad, latex caulk should be used in the screw holes and around the edges.

Push Plate: The push plate should be placed in a preferable location inside the door. The push plate pins 1 and 3 are connected to the push plate terminals on the prototype PCB.

Turning the System On
The system is ‘on’ when 120VAC power is supplied to it and the Stanley door opener switch is in the ‘on’ position. An important note is that on power-up, the deadbolt will automatically change states, and should by returned to its starting position by using the lock/unlock buttons on the deadbolt assembly.

Using the Automatic Door System
The system has two basic functions, the open sequence and the lock sequence. The open sequence first unlocks the deadbolt and releases the strike, then opens the door, holds it, and finally closes the door. The lock sequence simply locks the door.
A picture of a prototype unit constructed for demonstration purposes is shown below. Note that on this unit the keypad is mounted inside instead of outside.

Figure 2: Prototype Unit

Interface Components: The interface components include the system remote control, keypad, push plate, and deadbolt. Each of these components can be located on figure 2 above.

Opening the Door: The door can be opened from the inside by three methods. When the push plate is depressed or the open key on the remote control is pressed, the open sequence will be triggered. The door can also be operated manually from the inside by unlocking the deadbolt, and then opening the door like a normal door. The door can also be opened from the outside using three methods. When the proper code is entered into the keypad or the door open key is pressed on the remote control, the open sequence will be triggered. Alternatively, the deadbolt can be unlocked using a key, and the door can be opened like a normal door. Note that when the door is opened manually, one must push against the force of the spring mechanism and motor. This will not hurt the unit.

Locking the Door: The door can be locked from the inside by pressing the lock key on the remote control or by pressing the lock key on the deadbolt assembly. The door can be locked from the outside by pressing the lock key on the remote control, by pressing the # key on the keypad, or by using the deadbolt key.

Keypad Operation: The keypad is used to open and lock the door from the outside. The door is opened by punching in the four digit code. The door is locked by pressing the # key. The keypad is programmed so that a new code can be saved. The procedure for changing the keypad code is below.

Procedure to change keypad code:
1. OPEN the door using the pushbutton, keypad, or the remote.
2. Press “*” button.
3. Enter the new 4-digit code.
4. LOCK the door using the keypad (“#”) or remote to confirm the new code. The new code will be activated next time the door is used.

Special Buttons on the Keypad:
*: to change the keycode
#: to LOCK the door AFTER the door is closed.

Device Maintenance
The system has three components which run on battery power. The deadbolt contains four AA Alkaline batteries which should be changed yearly or tested and changed accordingly. The system remote control contains a 3.3V pancake cell which should be replaced every two years. The deadbolt remote, contained within the prototype circuit box, also has a 3.3V pancake cell which should be replaced every other year. The cell is replaced by opening the circuit box, loosening the bracket that secures the transmitter, removing the remote cover, and swapping out the battery. The deadbolt remote is shown in the figure below.

Figure 3: Deadbolt remote, left- inside PCB box, right- top removed to replace battery.


APPENDIX I
Trouble Shooting Guide
A quick check of the system can be done by checking the node voltages given on the diagram in Appendix II. The voltages are given when the system is in a normal running state and no inputs are activated. Logical inferences can be made from these tests to help diagnose the problem. However, it may be necessary to run a complete diagnostic on the system. In this case, the following steps are given in a specific order so that the problem can be narrowed down to a single external component or circuit component. The steps must be followed in the order given.
Step 1: Power Sources
The first things to check when troubleshooting are the power sources. Check the batteries contained in the system remote, deadbolt remote, and deadbolt assembly. Checking the deadbolt assembly batteries is done by attempting to operate the deadbolt using the keys on the unit itself. The transmitter batteries must be checked using a meter. Also check the circuit breaker for the system.

Step 2: PCB
If the batteries are all good, then it is most likely necessary to troubleshoot the PCB circuit and external components. A list of all the components connected to the PCB and the solid state devices on the PCB is given below.


Component List:
External Devices
Volgen 12V 30W Power Supply (Digikey 62-1006-ND)
Stanley Magic Access Automatic Door Opener
Electronic Deadbolt
HES Electronic Strike (series 5724)
Linx Keyfob Transmitter (CMD-KEY2-418)
Push Plate (NO SPST)
12-key Keypad (standard)
Solid State PCB Devices
Linx Decoder Module (FCTN-DEC1-418)
Micro-controller (PIC16F877-20/P)
Solenoid Driver (Burr Brown DRV101T)
Buffer (74C902)
Reed Relay (EAC D1A05A)
Diode (1N4001)
Voltage Regulator (7805)

INPUTS: The first tests done on the PCB are to check the external inputs. The Figure below shows the PCB.


Figure 4: PCB (Inputs/Outputs are labeled, semiconductors are numbered 1 through 10)

The external inputs are tested by using a multimeter on the blue input/output terminals.
Power supply test- the voltage across the 12V input and ground should be 12V. If it is not, the power supply is bad.
Push Plate- When the push plate is depressed, there will be 5VDC between the push plate terminals. Otherwise there should be no potential.
Keypad test- The keypad is tested by depressing buttons on the keypad and simultaneously measuring the resistance on terminals D through K. The chart below shows which terminals should short together when each key is pressed. Note that the keypad used is the matrix style. The shorted terminals are noted by a bullet.

Figure 5: Keypad codes
INTERNAL COMPONENTS: The internal components of the PCB are tested next.
Voltage Regulator- The voltage regulator, component number 9 on the PCB, is tested by reading the voltage on pin 3 (right most pin). The voltage should read 5.09VDC.
Linx RF Module- This module is tested by using the Linx remote. When the open button on the remote is depressed, pin 8 of PCB component 2 should rise to 5VDC. When the lock button is depressed, pin 10 should rise to 5VDC. If the linx unit does not respond, it is difficult to know if the receiver is bad, or if the remote is bad. It is recommended that a new remote be ordered first and tested. Note that the new remote must be opened and address line A9 (pin 22 of HT-640) must be scratched off so that it matches the receiver address.
Input Buffer- The input buffer (PCB component 3) should be grounded on pin 7 and have 5VDC at pin 14. The output pins 1, 3, and 5 should normally be LOW. Pin 1 will be HI (4.16V) when the remote close button is pressed, pin 3 will be HI when the remote open button is pressed, and pin 5 will be HI when the push plate is depressed.
PIC Microcontroller- The PIC is tested by removing it from the circuit and testing the output buffer. The inputs have already been tested, so if the output buffer works, the pic is most likely the culprit.
Output Buffer- At this point, the PIC should be removed from the circuit. The output buffer (PCB component 4) is tested by jumping the 5V input for the PIC (pin 32) to the PIC output pins 19, 20, 21, and 27. When pin 19 of the PIC is made HI, the output buffer pin 6 should go HI. When pin 20 of the PIC is made HI, the output buffer pin 4 should go HI. When pin 21 of the PIC is made HI, the output buffer pin 13 should go HI. When pin 27 of the PIC is made HI, the output buffer pin 2 should go HI. At all other times, pin 14 should be 5V and all others should be LOW.
Output Reed Relays- The reed relays are tested by jumping 5V to the PIC output pins 19, 21, and 27. When PIC pin 19 is made HI, there should be a short circuit between the Deadbolt Open terminals. When PIC pin 21 is made HI, there should be a short circuit across the Door Opener terminals. When PIC pin 27 is made HI, there should be an open circuit across the Deadbolt Lock terminals. All three of the preceeding output terminals should normally be open circuit.
Solenoid Driver- The solenoid driver, PCB component 8, is tested by jumping 5V to PIC pin 20. The strike leads in the terminals should be removed from the strike terminals. When pin 20 is made HI, there should be 12VDC across the Strike terminals. If there is no voltage, then the diode, PCB component 10 should be tested. If the diode is good, then the solenoid driver is bad. If the diode is bad, it should be replaced with the solenoid driver.
PIC Microcontroller Continued- The PIC should be replaced back into the circuit. The output terminals should be individually tested for each input command. The sequence of events for the Open command is as follows:
1s 2s 3s 4s 5s 6s 7s
Deadbolt Terminals Shorted
Strike Terminals 12VDC
Door Open Terminals Shorted

Figure 6: Open Sequence
The deadbolt lock terminals should be tested for each input lock command. When a lock command is given, the deadbolt lock terminals should be shorted for 1 second. If all the commands are working, then the problem is with and external component.
Step 3: External Output Components
The system should be completely reconnected at this point. An input Open command should be given. The deadbolt, strike and door opener should respond according to figure 6 above. If one of the components does not respond, it must be replaced. Next an input close command should be given, if the deadbolt does not close, it must be replaced.


Microcontroller Code
;;;;;;; Automatic Door Opener ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Spring 2002
; 歌林电子制作工作室www.nbglin.com
;
;;;;;;; Program hierarchy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

list P=PIC16F877, F=INHX8M, C=160, N=77, ST=OFF, MM=OFF, R=DEC, X=OFF
#include P16F877.inc
__config(_CP_OFF & _PWRTE_ON & _XT_OSC & _WDT_OFF & _BODEN_OFF)


;;;;;;; Equates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Bank0RAM equ H'20' ;Start of Bank 0 RAM area

MaxCount equ 50 ;Number of loops in half a second
Deadstrike equ B'00000011' ;Deadbolt and strike at bits 0 and 1 repectively
Motor equ B'00000100' ;Motor at Bit 2 of Port D
ADDRH equ 1


;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

cblock Bank0RAM
W_TEMP ;Temporary storage for W during interrupts
STATUS_TEMP ;Temporary storage for STATUS during interrupts
TEMP_1 ;used by initLCD and DisplayV
TEMP2 ;used by initLCD and DisplayV another temp variable for adres

KEYCODE ;Index for ScanKeys Table
TEMP1
KEYSTATE
KeyToggle1
FSR_TEMP

code1
code2
code3
code4
store1
store2
store3
store4
doorlock
INPUT_TEMP
endc

;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MOVLF macro literal,dest
movlw literal
movwf dest
endm

MOVFF macro source,dest
movf source,W
movwf dest
endm

BANK0 macro
bcf STATUS,5 ;select page 0
bcf STATUS, RP1
endm

BANK1 macro
bsf STATUS,5 ;select page 1
bcf STATUS, RP1
endm

BANK2 macro
bsf STATUS, RP1 ;Bank 2
bcf STATUS, RP0
endm
BANK3 macro
bsf STATUS, RP0
bsf STATUS, RP1
endm


;;;;;;;;#define;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#define Col1 PORTC,2 ;strobe col 1 of keypad
#define Col2 PORTA,5 ;strobe col 2 of keypad
#define Col3 PORTA,2 ;strobe col 3 of keypad
#define Locked doorlock,0 ;status of the door

;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org H'000' ;Reset vector
nop ;for in circuit debugger
goto Mainline ;Branch past tables
org H'004' ;Interrupt vector
goto IntService ;Branch to interrupt service routine

;;;;;;;;;;;;;;;;ScanKeys_Table subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine returns the byte pointed to by KeyCode
;It needs to be in first 256 words of program space as a table.
;Upper 4 bits sets row low[B4,3,2,1]; lower 3 lines read the
;3 choices in the selected row, and check for match.
; Note only 12 keys are scanned here.
; The AnyKey subroutine is modified from that on page 146
;to drive bits c2,a5, and a2 successively low and then to
;test bits 4,3,2 and 1 of PORTB to see if all of them are high
;(corresponding to no keys pressed).
;For example, the table entry for the "2" key is
; 0111101x see below for array:
;B4 1 2 3
;B3 4 5 6
;B2 7 8 9
;B1 . 0 chs
; c2 a5 a2

ScanKeys_Table
movf KEYCODE,W
addwf PCL,F ;chg pc with pclath=H'00',and offset in w
retlw B'11101010' ;test 0 key
retlw B'01110110' ;test 1 key
retlw B'01111010' ;2
retlw B'01111100' ;3
retlw B'10110110' ;4
retlw B'10111010' ;5
retlw B'10111100' ;6
retlw B'11010110' ;7
retlw B'11011010' ;8
retlw B'11011100' ;9
retlw B'11100110' ;.
retlw B'11101100' ;chs

;;;;;;; End of Tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;******** Mainline program ****************************************************
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Mainline
call Initial ;Initialize everything
call LockDoor
call FlashRead

MainLoop
call ReadCode
call CheckInput
call Check
call CheckLock
call ChangeCode

;incf code1,F
;call FlashWrite
;call FlashRead
nop
;call LoopTime
goto MainLoop

;;;;;;; LoopTime subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine waits for Timer2 to complete its ten millisecond count
; sequence.

LoopTime
btfss PIR1,TMR2IF ;Check whether ten milliseconds are up
goto LoopTime
bcf PIR1,TMR2IF ;Clear flag
return

;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This subroutine performs all initializations of variables and registers.


Initial
BANK1
MOVLF B'00000100',ADCON1 ;Select PORTA pins for ADC or digital I/O
; bit 7 is ADFM, 0->left justify
MOVLF B'00000000',TRISA ;Set I/O for PORTA
MOVLF B'11100001',TRISB ;Set I/O for PORTB init as inputs
MOVLF B'11010111',TRISC ;Set I/O for PORTC
MOVLF B'01101000',TRISD ;Set I/O for PORTD
MOVLF B'00000100',TRISE ;Set I/O for PORTE
MOVLF 249,PR2 ;Set up Timer2 for a looptime of 10 ms
MOVLF B'01000100',OPTION_REG ;sets prescaler to 32
bsf PIE1,CCP1IE ;enable temperature interrupt using CCP2
;bsf PIE2,CCP1IE ;enable temperature interrupt using CCP2
bcf TRISC,2
bsf TRISB,1 ; make PB input
bsf TRISB,2
bsf TRISB,3
bsf TRISB,4

BANK0
clrf TMR0
clrf code1
clrf code2
clrf code3
clrf code4
bcf Locked
MOVLF 2,store1
MOVLF 4,store2
MOVLF 6,store3
MOVLF 8,store4

MOVLF B'01000000',INTCON ;Enable RB0/INT interrupts (see page 98)
;bsf INTCON,GIE ;global interrupt enable
MOVLF B'01001101',T2CON ;Finish set up of Timer2 (see page 62)

clrf PORTD
clrf PORTB
clrf PORTE

MOVLF B'00000001',T1CON ;Timer0 'on' for CCP1
MOVLF B'00000101',CCP1CON ;control for temp capture on rising edge
clrf KEYCODE
clrf TEMP1

clrf KEYSTATE

clrf INPUT_TEMP

clrf KeyToggle1
clrf FSR_TEMP

return


;;;;;;; IntService interrupt service routine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This interrupt service routine fields all interrupts. It first sets aside W
; and STATUS. It assumes that direct addressing will not be used in the
; mainline code to access Bank 1 addresses (once the Initial subroutine has
; been executed and interrupts enabled). It polls each possible interrupt
; source to determine whether it needs service.

IntService
; Set aside W and STATUS
;bsf PORTA,2 ;cpu time in interrupts
movwf W_TEMP ;Copy W to RAM
swapf STATUS,W ;Move STATUS to W without affecting Z bit
movwf STATUS_TEMP ;Copy to RAM (with nibbles swapped)
;MOVFF FSR,FSR_TEMP ;copy indf pointer

; Execute polling routine
Poll
btfsc PIR1,CCP1IF
;btfsc INTCON,T0IF
bcf INTCON,T0IF
;btfsc INTCON,INTF
;goto RPG
bcf INTCON,RBIF
; Restore STATUS and W and return from interrupt
;MOVFF FSR_TEMP,FSR ;restore indf register
swapf STATUS_TEMP,W ;Restore STATUS bits (unswapping nibbles)
movwf STATUS ; without affecting Z bit
swapf W_TEMP,F ;Swap W_TEMP
swapf W_TEMP,W ; and swap again into W without affecting Z bit
;bcf PORTA,2 ;cpu time in interrupts
retfie ;Return from mainline code; reenable interrupts

;;;;;;; T40 subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Pause for 40 microseconds (assumes 4 MHz crystal).

T40
movlw 12
movwf TEMP_1
T40_1
decfsz TEMP_1,F
goto T40_1
return

;;;;;; Wait100ms ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; call looptime 10 times
Wait100ms
; call LoopTime
; call LoopTime
; call LoopTime
; call LoopTime
; call LoopTime
; call LoopTime
; call LoopTime
; call LoopTime
return

;;;;;;;;;;;;;;AnyKey subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; The AnyKey subroutine
; is modified from Peatman page 146 to
; drive bits c2, a5,a2 [Col1,Col2,Col3]
; successively low and
; test bits B4,3,2,1 to see if they are low
; corresp. to a key pressed.
; returns with Z=1 if none pressed
; Z=0 if some key pressed
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AnyKey
;;drive Col1,2,3 low, make PB temp input
;bcf INTCON,GIE ;Disable interrupts
clrf PORTB

bcf Col1 ;c2
bcf Col2 ;a5
bcf Col3 ;a2
;; load w with expected value if none pressed
movlw B'00011110'
;;xor[10] =1 ->pressed;xor[11]->0 not pressed
xorwf PORTB,W ;Get b'xxx0000x' if none pressed
andlw B'00011110' ;force bits 0,5,6,7 of W to zero

return ;return with Z=1 if none pressed
;Z=0 if some key pressed

;;;;;;;;ScanKeys subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ScanKeys
;bcf INTCON,7 ; turn off all interrupts
clrf KEYCODE

;MOVLF B'00000110', ADCON1
ScanKeys_1
call ScanKeys_Table ;get next table entry
movwf TEMP1
;bcf PORTD,7 ;PD-7bit 0 of entry table
;btfsc TEMP1,0
;bsf PORTD,7
bsf Col1
nop
nop
bsf Col3
nop
nop
bsf Col2
nop
nop
;call Wait100ms
btfss TEMP1,1 ;drive columns low
bcf Col3
nop
nop
btfss TEMP1,2
bcf Col2
nop
nop
btfss TEMP1,3
bcf Col1
nop
nop

swapf TEMP1,F
rlf TEMP1,W
;movwf PORTB ;PB3,2,1 from table entry
xorwf PORTB,W ;compare upper 4 bits of PORTB with table entry
andlw B'00011110' ;Z=1 if a match
btfsc STATUS,Z
goto ScanKeys_done
incf KEYCODE,F ;try next entry
btfss KEYCODE,4 ;stop with Z=0 when KEYCODE =B'xxx1xxxx'
goto ScanKeys_1
ScanKeys_done

;MOVFF TRISA_TEMP,TRISA

;MOVLF B'00000100',ADCON1 ;Select PORTA pins for ADC or digital I/O
; bit 7 is ADFM, 0->left justify

nop
nop
;bsf INTCON,7 ;enable interrupts again
return


;;;;; WaitForEnterRaise ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;Envoked when Enter is pressed, simply loop until enter is raised

WaitForEnterRaise

WaitForEnterLoop
btfsc PORTD,3 ;skip out of loop when Enter is raised
goto WaitForEnterLoop

WaitForEnterLoop2
btfsc PORTD,5 ;skip out of loop when Enter is raised
goto WaitForEnterLoop2

return


;;;;;;; WaitAWhile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; A timing function to control stuff

WaitAWhile

MOVLF 100,TEMP_1 ; timing parameter
WaitAWhile_1
call LoopTime
decf TEMP_1,F
btfss STATUS,Z
goto WaitAWhile_1
return

;;;;;;; Wait1s ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; A timing function to control stuff

Wait1s

MOVLF 130,TEMP_1 ; timing parameter
Wait1s_1
call LoopTime
decf TEMP_1,F
btfss STATUS,Z
goto Wait1s_1
return

;;;;;;; WaitKey ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; A timing function to control stuff

WaitKey
MOVLF 10,TEMP_1 ; timing parameter
WaitKey_1
call LoopTime
decf TEMP_1,F
btfss STATUS,Z
goto WaitKey_1
return

;;;;;;; ReadCode subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
ReadCode

call AnyKey
btfsc STATUS,Z
return
call ScanKeys
call WaitForKeyRaise
MOVFF code2,code1
MOVFF code3,code2
MOVFF code4,code3
MOVFF KEYCODE,code4

return

;;;;;;; WaitForKeyRaise subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
WaitForKeyRaise
KeyRaiseLoop
call WaitKey
call AnyKey
btfss STATUS,Z
goto KeyRaiseLoop
return

;;;;;;; CheckInput subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
CheckInput
clrf INPUT_TEMP
btfsc PORTD,3 ;OPEN Input from remote
bsf INPUT_TEMP,0
btfsc PORTD,6 ;OPEN Input from pushbutton
bsf INPUT_TEMP,0
btfss INPUT_TEMP,0
goto CheckInputEnd
call WaitAWhile
call WaitForEnterRaise
call OpenDoor

CheckInputEnd
return

;;;;;;; CheckLock subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
CheckLock
btfss PORTD,5 ;Input from remote
goto CheckLockEnd
call WaitAWhile
call WaitForEnterRaise
call LockDoor

CheckLockEnd
return

;;;;;;; Check subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Check
movf code4,W
sublw 11
btfsc STATUS,Z
call LockDoor

movf code1,W
subwf store1,W
btfss STATUS,Z
return

movf code2,W
subwf store2,W
btfss STATUS,Z
return

movf code3,W
subwf store3,W
btfss STATUS,Z
return

movf code4,W
subwf store4,W
btfss STATUS,Z
return

call OpenDoor

clrf code1
clrf code2
clrf code3
clrf code4

return

;;;;;;;;;;LockDoor;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; To lock the door
LockDoor
btfsc Locked
return
movlw B'00010000' ;Bit 4 of PORTD is set high
movwf PORTD
call Wait1s
clrf PORTD
bsf Locked

return

;;;;;;;;;;OpenDoor;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; To open the door

OpenDoor
btfss Locked
return

; To set the deadbolt (1 second) and the door strike (5 seconds) high
movlw B'00000011' ;Bits 0 and 1 of Port D are high
movwf PORTD
call Wait1s
movlw B'00000010'
movwf PORTD

; A delay of 3 seconds
call Wait1s
call Wait1s
call Wait1s

; Set the motor on for 1 second
movlw B'00000110' ;Bits 1 and 2 of Port D are set High
movwf PORTD

; A delay of 1 second and then set motor off
call Wait1s
movlw B'00000010'
movwf PORTD

; A delay of 2 seconds and then set strike off
call Wait1s
call Wait1s
clrf PORTD

bcf Locked

clrf code1
clrf code2
clrf code3
clrf code4
return

;;;;;;;;;;Read ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Flash Program Read

FlashRead
BANK2

;;;;; code1
movlw ADDRH
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, RD ; EEPROM Read

nop ; Any instructions here are ignored as program
nop ; memory i sread in third cycle after BSF EECON1, RD

BANK2 ; Bank 2

movf EEDATH, W ; W = LSByte of program EEDATA

BANK0 ;Bank 0

movwf store1



;;;;; code2

BANK2
movlw ADDRH+1
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, RD ; EEPROM Read

nop ; Any instructions here are ignored as program
nop ; memory i sread in third cycle after BSF EECON1, RD

BANK2 ; Bank 2

MOVF EEDATH, W ; W = LSByte of program EEDATA

BANK0 ;Bank 0

movwf store2


;;;;; code3
BANK2
movlw ADDRH+2
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, RD ; EEPROM Read

nop ; Any instructions here are ignored as program
nop ; memory i sread in third cycle after BSF EECON1, RD

BANK2 ; Bank 2

MOVF EEDATH, W ; W = LSByte of program EEDATA

BANK0 ;Bank 0

movwf store3

;;;;; code4
BANK2
movlw ADDRH+3
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, RD ; EEPROM Read

nop ; Any instructions here are ignored as program
nop ; memory i sread in third cycle after BSF EECON1, RD

BANK2 ; Bank 2

MOVF EEDATH, W ; W = LSByte of program EEDATA

BANK0 ;Bank 0

movwf store4


return

;;;;;;;;;;Write ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FLASH PROGRMA WRITE

FlashWrite
BANK2 ; Bank 2
movlw ADDRH
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read

BANK0
movf code1,W
BANK2
movwf EEDATH ; MS Program memory value to write
;movlw DATAL
;movwf EEDATA ; LS program memory value to write
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, WREN ; Enable writes

bcf INTCON, GIE ; Disable Interrupts
movlw H'55' ;
movwf EECON2 ; Write 55h
movlw H'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write

nop ; Instructions here are ignored by the microcontroller
nop
; Microcontroller will halt operation and wait for
; a write complete. after the write


BANK2 ; Bank 2
movlw ADDRH+1
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read

BANK0
movf code2,W
BANK2
movwf EEDATH ; MS Program memory value to write
;movlw DATAL
;movwf EEDATA ; LS program memory value to write
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, WREN ; Enable writes

bcf INTCON, GIE ; Disable Interrupts
movlw H'55' ;
movwf EECON2 ; Write 55h
movlw H'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write

nop ; Instructions here are ignored by the microcontroller
nop
; Microcontroller will halt operation and wait for
; a write complete. after the write
BANK2 ; Bank 2
movlw ADDRH+2
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read

BANK0
movf code3,W
BANK2
movwf EEDATH ; MS Program memory value to write
;movlw DATAL
;movwf EEDATA ; LS program memory value to write
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, WREN ; Enable writes

bcf INTCON, GIE ; Disable Interrupts
movlw H'55' ;
movwf EECON2 ; Write 55h
movlw H'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write

nop ; Instructions here are ignored by the microcontroller
nop
; Microcontroller will halt operation and wait for
; a write complete. after the write
BANK2 ; Bank 2
movlw ADDRH+3
movwf EEADRH ; MSByte of Program Address to read
;movlw ADDRL
;movwf EEADR ; LSByte of program address to read

BANK0
movf code4,W
BANK2
movwf EEDATH ; MS Program memory value to write
;movlw DATAL
;movwf EEDATA ; LS program memory value to write
BANK3 ; Bank 3
bsf EECON1, EEPGD ; Point to PROGRAM memory
bsf EECON1, WREN ; Enable writes

bcf INTCON, GIE ; Disable Interrupts
movlw H'55' ;
movwf EECON2 ; Write 55h
movlw H'AA'
movwf EECON2 ; Write AAh
bsf EECON1, WR ; Set WR bit to begin write

nop ; Instructions here are ignored by the microcontroller
nop
; Microcontroller will halt operation and wait for
; a write complete. after the write
; the microcontroller continues with 3rd instruction
bcf INTCON, GIE ; Enable interrupts
bcf EECON1, WREN ; disable writes

BANK0
nop
return

;;;;;;;;;;ChangeCode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; To change the code

ChangeCode
movf code4,W
sublw 10
btfss STATUS,Z
return

btfsc Locked
return


AnyKeyLoop1
call AnyKey
btfsc STATUS,Z
goto AnyKeyLoop1

call ScanKeys
call WaitForKeyRaise
MOVFF code2,code1
MOVFF code3,code2
MOVFF code4,code3
MOVFF KEYCODE,code4

AnyKeyLoop2
call AnyKey
btfsc STATUS,Z
goto AnyKeyLoop2

call ScanKeys
call WaitForKeyRaise
MOVFF code2,code1
MOVFF code3,code2
MOVFF code4,code3
MOVFF KEYCODE,code4

AnyKeyLoop3
call AnyKey
btfsc STATUS,Z
goto AnyKeyLoop3

call ScanKeys
call WaitForKeyRaise
MOVFF code2,code1
MOVFF code3,code2
MOVFF code4,code3
MOVFF KEYCODE,code4

AnyKeyLoop4
call AnyKey
btfsc STATUS,Z
goto AnyKeyLoop4

call ScanKeys
call WaitForKeyRaise
MOVFF code2,code1
MOVFF code3,code2
MOVFF code4,code3
MOVFF KEYCODE,code4

MOVFF code1,store1
MOVFF code2,store2
MOVFF code3,store3
MOVFF code4,store4

call FlashWrite
;call FlashRead

return

end

  
日期:2005年03月25日   来源: 
相关文章:
·用超低功耗MSP430单片机设计数据采集系统 2005-06-27
·火灾探测器受干扰的原因及改进方法 2005-07-02
·特殊构件的焊接技术 2005-10-18
·触摸屏的工作原理及典型应用 2005-11-25
·高质量C++/C编程指南---类的构造函数,析构函数,赋值 2005-12-13
·电子产品高温老化的原理以及一间智能温控老化室的应用 2006-01-05
·新近成功开发无霍尔传感器无刷电机控制器 2006-01-20
·归纳一下最近比较流行的电动自行车技术 2006-01-23
·电子工作台 --- workbench 电子仿真软件 2006-05-23
·液晶字模工具 ------ HZDotReader V3 2006-05-23
·51系列单片机仿真软件----伟福e6000w  2006-05-23
·无传感器无刷电机驱动控制器系统的优点 2006-06-10
·PIC单片机C语言编译器 --PICC 8.05 完整破解版 2006-07-09
·adobe reader 7.0 2006-07-09
·ARM内核的MP3解码 2006-07-09