; ; PIC12C509A ; Keyless Controller Ver 0.1 ; Programmed by DD ; Greatly Supported by S.IWANO ; ; Data Format ; +---------------+ ; | | |O|O|X|X|I|I| GPIO I:Input O:Output X:Don't Use ; +---------------+ ; Input Data ; GPO => Lock Signal Input ; GP1 => Unlock Signal Input ; ; Output Data ; GP4 => Lock Signal Output ; GP5 => Unlock Signal Output ; ; Function ; (1)Press Lock Button to double lock the doors. ; (2)Press Unlock Button to unlock the doors. ; (3)Press Lock Button within 3 seconds after unlock the door ; to double lock the doors and automatically close the windows. ; (4)When automatically closing the windows, press unlock button ; to stop closing the windows and unlock the doors (Emergency Mode) ; ; Flow Chart ; (START): ; GP4=0, GP5=0 ; If GP0=1 then go to MODE (DBLLOCK). ; If GP1=1 then go to MODE (UNLOCK). ; Go to SLEEP ; (SLEEP): ; GP4=0, GP5=0 ; Sleep z.z.z.... ; Go to START ; (DBLLOCK): ; GP4=1, GP5=1 ; Wait for GP0 turns 0. ; Go to SLEEP ; (UNLOCK): ; GP5=1. ; Wait for GP1 turns 0. ; GP5=0. ; Wait for 3 seconds. ; While waiting, if GP0 turns 1 go to (WDWCLS) ; Go to SLEEP. ; (WDWCLS): ; GP4=1, GP5=1 ; Wait for 30 seconds. ; While waiting, if GP1 turns 1 go to (WDWSTP) ; Go to SLEEP ; (WDWSTP): ; GP4=0, GP5=0 ; Wait for 1 second. ; GP5=1 ; Wait for 0.5 second. ; Go to SLEEP list p=pic12C509A include "p12c509a.inc" ; __FUSES _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC ; Configuration Code = 0xFFEA ; When burning PIC, the following configuration is necessary ; MCLR is OFF ; Code Protection(CP) is OFF ; Watch Dog Timer(WDT) is OFF ; Clock is Internal RC Oscillator cblock 0x08 ;Store variables above control registers wcnt1 ;Wait Counter1 (For 100ms Wait) wcnt2 ;Wait Counter2 (For 100ms Wait) wt3cnt ;Conuter for waiting 3 second wt30ct1 ;Counter(1) for waiting 30 second wt30ct2 ;Counter(2) for waiting 30 second wt1cnt ;Counter for waiting 1 second endc org 0x00 ;Start of Code Space ;========================================= ; Start Program (& Wake up from Sleep) ;========================================= START movlw b'00000011' ;GP5-2:Output GP1,0:Input tris 6 ;Set GPIO Input/Output movlw b'00000000' ;Wakeup Enable option bcf GPIO,4 ;Reset Output Lock Signal bcf GPIO,5 ;Reset Output Unlock Signal btfsc GPIO,0 ;If Input Lock Signal = 1, goto DBLLOCK ; go to BDLLOCK btfsc GPIO,1 ;If Input Unlock Signal = 1, goto UNLOCK ; go to UNLOCK SLP bcf GPIO,4 ;Reset Output Lock Signal bcf GPIO,5 ;Reset Output Unlock Signal sleep ;Go to Sleep Mode goto START ;=========================== ; Double Lock Operation ;=========================== DBLLOCK movlw b'00110000' movwf 6 ; bsf GPIO,4 ;Set Output Lock Signal ; bsf GPIO,5 ;Set Output Unlock Signal (for double lock) dbllp btfsc GPIO,0 ;Wait for Input Lock Signal turns 0 goto dbllp goto SLP ;Go to SLP ;=========================== ; Double Lock Operation ;=========================== UNLOCK bsf GPIO,5 ;Set Output Unlock Signal unllp btfsc GPIO,1 ;Wait for Input Unlock Signal turns 0 goto unllp movlw d'30' ;Set Wait Counter 30 movwf wt3cnt unwtlp call wait100ms ;Wait for 100ms btfsc GPIO,0 ;If Input Lock Signal turns 1, goto WDWCLS ; go to WDWCLS (Window Close) decfsz wt3cnt,F ;Wait for 3 seconds goto unwtlp goto SLP ;Go to SLP ;=========================== ; Window Auto Close ;=========================== WDWCLS bsf GPIO,4 ;Set Output Lock Signal bsf GPIO,5 ;Set Output Unlock Signal (for double lock) movlw d'30' ;Set Wait Counter(2) 30 (second) movwf wt30ct2 wdcllp1 movlw d'10' ;Set Wait Counter(1) 10 (1 second) movwf wt30ct1 wdcllp2 call wait100ms ;Wait for 100ms btfsc GPIO,1 ;If Input Unlock Signal turns 1, goto WDWSTP ; go to WDWSTP (Stop closing window) decfsz wt30ct1,F ;Wait for 1 second goto wdcllp2 decfsz wt30ct2,F ;Wait for 30 seconds goto wdcllp1 goto SLP ;Go to SLP ;================================= ; Emergency Stop Closing Window ;================================= WDWSTP bcf GPIO,4 ;Reset Output Lock Signal bcf GPIO,5 ;Reset Output Unlock Signal (Stop closing window) movlw d'10' ;Set Wait Counter 10 movwf wt1cnt wdstlp1 call wait100ms ;Wait for 100ms decfsz wt1cnt,F ;Wait for 1 second goto wdstlp1 bsf GPIO,5 ;Set Output Unlock Signal (Unlock Doors) movlw d'5' ;Set Wait Counter 5 movwf wt1cnt wdstlp2 call wait100ms ;Wait for 100ms decfsz wt1cnt,F ;Wait for 1 second goto wdstlp2 goto SLP ;Go to SLP ;Subroutine ;================================ ; Wait for 100ms ;================================ wait100ms movlw d'128' ; movwf wcnt2 waitlp2 clrf wcnt1 waitlp1 decfsz wcnt1,F goto waitlp1 decfsz wcnt2,F goto waitlp2 retlw 0 end