; ; PIC12C509 ; Keyless Controller Ver 0.3 ; Programmed by DD ; Greatly Supported by S.IWANO ; ; Data Format ; +---------------+ ; | | |O|O|I|O|I|I| GPIO I:Input O:Output X:Don't Use ; +---------------+ ; Input Data ; GPO => Lock Signal Input ; GP1 => Unlock Signal Input ; GP3 => Press Button ; ; Output Data ; GP2 => Turn Light Signal Output ; GP4 => Lock Signal Output ; GP5 => Unlock Signal Output ; ; Function ; (1)Press Lock Button to double lock the doors. ; 3-3-7 Blinks ; (2)Press Unlock Button to unlock the doors. ; 2 Blinks ; (3)Press Lock Button again while turn lights are blinking ; to automatically close the windows. 15 Blinks ; (4)When automatically closing the windows, press unlock button ; to stop closing the windows and unlock the doors (Emergency Mode) ; (5)When automatically closing the windows, press lock button again ; to just stop closing the windows (Stop Closing the doors) ; ; Flow Chart ; (START): ; GP4=0, GP5=0, GP2=0 ; Go to SLEEP ; (SLEEP): ; If GP3=1 then ; if GP0=1 go to DBLLOCK. ; if GP1=1 go to UNLOCK. ; GP4=0, GP5=0, GP2=0 ; Sleep z.z.z.... ; Go to START ; (DBLLOCK): ; GP4=1, GP5=1 ; Wait for 500ms ; GP4=0, GP5=0 ; Wait for 500ms ; Start 3-3-7 Blinks of Turn Light Signal ; While blinking, if GP3=1 then if GP0=1, go to WDWCLS ; if GP1=1, go to UNLOCK ; Go to SLEEP ; (UNLOCK): ; GP5=1 ; Wait for 500ms ; GP5=0 ; Wait for 500ms ; Start 2 blinks of turn light signal ; While blinking, if GP3=1 then if GP0=1, go to DBLLOCK ; if GP1=1, go to UNLOCK ; Go to SLEEP. ; (WDWCLS): ; GP4=1, GP5=1 ; Wait for 30 seconds. ; While waiting, if GP3=1 then if GP0=1 go to WDWSTP ; if GP1=1 go to WDWSTP ; Go to SLEEP ; (WDWSTP): ; GP4=0, GP5=0 ; Wait for 500ms. ; GP5=1 ; Wait for 500ms. ; 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) blkcnt ;Blink Counter waitcnt ;Wait Counter endc org 0x00 ;Start of Code Space ;========================================= ; Start Program (& Wake up from Sleep) ;========================================= START movlw b'00001011' ;GP5,4,2:Output GP3,1,0:Input tris 6 ;Set GPIO Input/Output movlw b'00000000' ;Wakeup Enable option movlw b'00000000' ;GP5,4,2=0 movwf GPIO SLP btfss GPIO,3 ;If GP3=0 goto slpskp ; go to slpskp 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 slpskp movlw b'00000000' ;GP5,4,2=0 movwf GPIO sleep ;Go to Sleep Mode goto START ;=========================== ; Double Lock Operation ;=========================== DBLLOCK movlw b'00110000' ;GP5,4=1 movwf GPIO movlw d'5' movwf waitcnt ;Set counter 5 dbllp1 call wait100ms decfsz waitcnt,F goto dbllp1 ;Wait for 500ms movlw b'00000000' ;GP5,4=0 movwf GPIO movlw d'5' movwf waitcnt ;Set counter 5 dbllp11 call wait100ms decfsz waitcnt,F goto dbllp11 ;Wait for 500ms movlw d'3' movwf blkcnt dbllp2 movlw d'3' ;Wait for 300ms bsf GPIO,2 ;Turn Light Signal ON call dblsub bcf GPIO,2 ;Turn Light Signal OFF movlw d'3' ;Wait for 300ms call dblsub decfsz blkcnt,F goto dbllp2 ;Repeat until blkcnt=0 movlw d'6' ;Wait for 600ms call dblsub movlw d'3' movwf blkcnt dbllp3 movlw d'3' ;Wait for 300ms bsf GPIO,2 ;Turn Light Signal ON call dblsub bcf GPIO,2 ;Turn Light Signal OFF movlw d'3' ;Wait for 300ms call dblsub decfsz blkcnt,F goto dbllp3 ;Repeat until blkcnt=0 movlw d'6' ;Wait for 600ms call dblsub movlw d'7' movwf blkcnt dbllp4 movlw d'3' ;Wait for 300ms bsf GPIO,2 ;Turn Light Signal ON call dblsub bcf GPIO,2 ;Turn Light Signal OFF movlw d'3' ;Wait for 300ms call dblsub decfsz blkcnt,F goto dbllp4 ;Repeat until blkcnt=0 goto SLP ;Go to SLP dblsub movwf waitcnt dblsb1 call wait100ms btfss GPIO,3 ;If GP3=0 goto dblskp ; go to dblskp btfsc GPIO,0 ;If Input Lock Signal=1, goto WDWCLS ; go to WDWCLS btfsc GPIO,1 ;If Input Unlock Signal=1, goto UNLOCK ; go to UNLOCK dblskp decfsz waitcnt,F goto dblsb1 ;Repeat until waitcnt=0 retlw 0 ;=========================== ; Unlock Operation ;=========================== UNLOCK movlw b'00100000' ;GP5=1 movwf GPIO movlw d'5' movwf waitcnt ;Set counter 5 unllp1 call wait100ms decfsz waitcnt,F goto unllp1 ;Wait for 500ms movlw b'00000000' ;GP5=0 movwf GPIO movlw d'5' movwf waitcnt ;Set counter 5 unllp11 call wait100ms decfsz waitcnt,F goto unllp11 ;Wait for 500ms movlw d'2' movwf blkcnt unllp2 movlw d'10' ;Wait for 1000ms bsf GPIO,2 ;Turn Light Signal ON call unlsub bcf GPIO,2 ;Turn Light Signal OFF movlw d'10' ;Wait for 1000ms call unlsub decfsz blkcnt,F goto unllp2 ;Repeat until blkcnt=0 goto SLP ;Go to SLP unlsub movwf waitcnt unlsb1 call wait100ms btfss GPIO,3 ;If GP3=0 goto unlskp ; go to unlskp btfsc GPIO,0 ;If Input Lock Signal=1, goto DBLLOCK ; go to DBLLOCK btfsc GPIO,1 ;If Input Unlock Signal=1, goto UNLOCK ; go to UNLOCK unlskp decfsz waitcnt,F goto unlsb1 ;Repeat until waitcnt=0 retlw 0 ;=========================== ; Window Auto Close ;=========================== WDWCLS movlw b'00110000' ;GP5,4=1 movwf GPIO movlw d'10' movwf waitcnt ;Set counter 10 wdclp0 call wait100ms decfsz waitcnt,F goto wdclp0 ;Wait for 1000ms movlw d'14' ;28 sec movwf blkcnt wdclp1 movlw d'3' ;Wait for 300ms bsf GPIO,2 ;Turn Light Signal ON call wdcsub bcf GPIO,2 ;Turn Light Signal OFF movlw d'17' ;Wait for 1700ms call wdcsub decfsz blkcnt,F goto wdclp1 ;Repeat until blkcnt=0 goto SLP ;Go to SLP wdcsub movwf waitcnt wdcsb1 call wait100ms btfss GPIO,3 ;If GP3=1 goto wdcskp ; go to wdcskp btfsc GPIO,0 ;If Input Lock Signal=1, goto WDWSTP ; go to WDWSTP btfsc GPIO,1 ;If Input Unlock Signal=1, goto WDWSTP ; go to WDWSTP wdcskp decfsz waitcnt,F goto wdcsb1 ;Repeat until waitcnt=0 retlw 0 ;================================= ; Emergency Stop Closing Window ;================================= WDWSTP movlw b'00000000' ;GP5,4=0 movwf GPIO call wait100ms ;wait for 500ms call wait100ms call wait100ms call wait100ms call wait100ms movlw b'00100000' ;GP5=1, GP2,1=0 movwf GPIO call wait100ms ;wait for 500ms call wait100ms call wait100ms call wait100ms call wait100ms goto SLP ;Subroutine ;================================ ; Wait for 100ms ;================================ wait100ms movlw d'128' ;*128 movwf wcnt2 waitlp2 clrf wcnt1 waitlp1 decfsz wcnt1,F goto waitlp1 decfsz wcnt2,F goto waitlp2 retlw 0 end