LIST P=PIC12C508A, R=HEX ; ; MUTLI-FUNCTION CONTROLOR FOR R/C MODEL ; SUN, PU-NENG ; JULY/17/2003 ; ; VERSION 1.02 (AUGEST/20/2003) ; fix one bug, to make sure when alarm off, the freq is low ; ; VERSION 1.01 (JULY/23/2003) ; FIX BUG,LIGHT & FLASH DO NOT WORK WITH 12C508A ; ADD OPTION TO TURN T0CS=0, TO ENABLE GP2 ; ; VERSION 1.0 ; USE A SPARE CHANNEL ON R/C RECEIVER, ; TO CONTROL ANYTHING YOU WANT,MISSLE,CAMERA, ; HEAD LIGHT,LANDING FLASH,AND BUZZER FOR LOCATE THE PLANE ; ; CONFIG IntRC, OTHERS DON'T CHECK __CONFIG H'0FEA' ; ; DEFINE RAM ;----- SYSTEM --------- STATUS EQU 3 GPIO EQU 6 ; PA EQU 6 ; ;---- USER DEFINE ------ ; CNTA EQU H'7' ;PLUSE WIDTH COUNTER CNTB EQU H'8' ;DOUBLE CLICK TIMER CNTC EQU H'9' ;ROUND RUNNING CNTD EQU H'A' ;ROUND RUNNING *256 FLAGR EQU H'B' ;FLAG REGISTER STA EQU 0 ;STATUS ,FLAG REGISTER BIT 0 HFLAG EQU 1 LFLAG EQU 2 ; ; ; DEFINE BIT ; W EQU 0 ;d VALUE FOR INCF...... F EQU 1 ;d VALUE OFF EQU 0 ;FLAG BIT 0 ON EQU 1 ;FLAG BIT 1 INPUT EQU 3 ;GPIO 3 IS INPUT ONLY PIN SHOOT EQU 1 ;FOR MISSLE OR CAMERA PUSH ON , RELEASE OFF LIGHT EQU 2 ;ONE PUSH ON, ANOTHER PUSH OFF FLASH EQU 0 ;WHEN LIGHT ON, ON/OFF EVERY 0.5 SEC BUZZER EQU 4 ;DOUBLE CLICK ON, ONE PUSH OFF FREQ EQU 5 ;WHEN BUZZER ON, OUT TWO TONES ALARM ; ; DEFINE VARIABLES ; NOISE EQU H'20' ;*20uS= 0.7 mS, PULSE < 0.6 DEFINE AS NOISE ACTION EQU H'50' ;80 *20uS= 1.6 mS, PULSE > 1.6 DEFINE AS VALID DOUBLE EQU H'15' ;*2.0mS= .3 SEC, DOUBLE CLICK INTERVAL ; ;========== MAIN PROGRAM ========= ; ; ORG 0 GOTO START ; ;========================================== ORG 3 SUB1 INCFSZ CNTC,F GOTO SUB2 INCF CNTD,F SUB2 BTFSC CNTD,6 ;CNTD BIT 2 = 0.5 SEC ON, 0.5 SEC OFF GOTO ON1 OFF1 NOP NOP BCF PA,FLASH OFF2 BTFSS PA,BUZZER GOTO OFF4 BTFSC CNTC,4 ;0.5 SEC 800 Hz FREQ FOR ALARM GOTO OFF3 BCF PA,FREQ NOP RETLW 0 ;----------------------- OFF3 BSF PA,FREQ RETLW 0 ;----------------------- OFF4 NOP NOP NOP RETLW 0 ;----------------------- ON1 BTFSC PA,LIGHT BSF PA,FLASH ON2 BTFSS PA,BUZZER GOTO ON4 BTFSC CNTC,5 ;0.5 SEC 400 Hz FREQ FOR ALARM GOTO ON3 BCF PA,FREQ NOP RETLW 0 ;----------------------- ON3 BSF PA,FREQ RETLW 0 ;----------------------- ON4 NOP NOP NOP RETLW 0 ;================================================ ;------------------------------------------ START MOVLW 8 ;PA3=INPUT, OTHERS =OUTPUT TRIS GPIO ; MOVLW H'C0' ;T0CS=0, TO ENABLE GP2 OPTION CLRW MOVWF GPIO MOVWF CNTB MOVWF FLAGR ;SET STATUS= 0 HFALG & LFALG =0 MAIN CLRF CNTA MAIN1 NOP BTFSC PA,INPUT GOTO MAIN2 CALL SUB1 GOTO MAIN1 MAIN2 INCF CNTA,F BTFSS PA,INPUT GOTO MAIN3 CALL SUB1 GOTO MAIN2 MAIN3 MOVLW NOISE SUBWF CNTA,W SKPC ;IF f > w, C= 1,SKIP GOTO MAIN ;ELSE IT'S NOISE MAIN4 MOVLW ACTION SUBWF CNTA,W SKPC ;IF f > w, C=1, SKIP TO HIGH GOTO LOW1 ;ELSE IT'S LOW HIGH1 BTFSC FLAGR,STA ;IS STATUS HIGH OR LOW ? GOTO MAIN ;IF HIGH THE BUTTON NO RELEASE YET HIGH2 BTFSC FLAGR,HFLAG ; GOTO HIGH3 BSF FLAGR,HFLAG GOTO MAIN HIGH3 BCF FLAGR,LFLAG ;RESET LOW PASS COUNTER BCF FLAGR,HFLAG BSF FLAGR,STA ;SET STATUS FLAG AS HIGH MOVF CNTB,F SKPZ GOTO BUZZER1 ;CNTB NO ZERO MOVLW DOUBLE MOVWF CNTB ;SET CNTB = DOUBLE INTERVAL TIME BSF PA,SHOOT BCF PA,BUZZER BCF PA,FREQ ;TURN BUZZER OFF BTFSC PA,LIGHT GOTO HIGH4 ;LIGHT IS ON , TURN IT OFF BSF PA,LIGHT GOTO MAIN ;--------------------------------------------------------- HIGH4 BCF PA,LIGHT BCF PA,FLASH GOTO MAIN ;--------------------------------------------------------- BUZZER1 BSF PA,BUZZER CLRF CNTB GOTO MAIN ;--------------------------------------------------------- LOW1 MOVF CNTB,F SKPZ DECF CNTB,F BTFSS FLAGR,STA GOTO MAIN LOW2 BTFSC FLAGR,LFLAG ; GOTO LOW3 BSF FLAGR,LFLAG GOTO MAIN LOW3 BCF FLAGR,HFLAG BCF FLAGR,LFLAG BCF FLAGR,STA ;SET STATUS FLAG AS LOW BCF PA,SHOOT ;SHOOT OFF GOTO MAIN ;--------------------------------------------------------- END