LIST P=12C508A,R=HEX
;
; MIXER FOR DLETA WIND & V-TAIL
; SUN, PU-NENG
;
;
;
;
; VERSION 1.0 (MAY/09/2004) 12C508A
;
; Mixing Y with X, a proportion of ChY is bi-directionally mixed with ChX
;d ChA = (Q(d ChX) + R(d ChY))
;d ChB = (Q(d ChX) - R(d ChY))
;
;where Q, R are the mixing ratio, 1 OR 0.5
;
; JUMP1 JUMP2 Q Rr
; Off Off 1 1 (DEFAULT)
; Off On 1 0.5
; On Off 0.5 1
; On On 0.5 0.5
;
;ChA GPIO4 ,OUTPUT
;ChB GPIO5 ,OUTPUT
;ChX GPIO2 ,INPUT
;ChY GPIO3 ,INPUT
; JUMP1 GPIO0--GND, ON=GND
; JUMP2 GPIO1--GND, ON=GND
;
;
; PROGRAMMER SETUP AS: OSC= IntRC, WDT= SET, CP= BLANK, MCLR= BLANK
;
;
; DEFINE RAM
;----- SYSTEM ---------
TMR0EQU 1;TIMER 0
PCL EQU 2 ;PROGRAM COUNTER
STATUS EQU 3
FSR EQU 4 ;BUFFER OF INDIRECT ADDR
OSCCAL EQU 5
GPIOEQU 6
;
RP0EQU 5
;---------------------------
;
;---- USER registers DEFINE ------
;
TMR1 EQU H'11' ;
TMR2 EQU H'12' ;
ChXEQU H'13' ;
ChYEQU H'14'
ChAEQU H'15'
ChBEQU H'16'
FLAGR EQU H'17' ;FLAG REGISTER
X1EQU H'1A' ;
Y1EQU H'1B'
XEQU H'1C' ;
YEQU H'1D'
;
;
;---- VARIABLES DEFINE ----
;
W EQU 0 ;d VALUE FOR INCF......
F EQU 1 ;d VALUE
NOISE EQU H'50' ;PULSE LESS THEN THIS DEFINE AS NOISE
T1EQU H'3C';60 * 100uS LOOP
;-------FLAG
QQ EQU 0 ;
RR EQU 1
FIREQU 2
;
;---- HARDWARE PINS DEFINE ----
;
ChA1EQU 4
ChB1EQU 5
ChXIEQU 2
ChYIEQU 3
SW1EQU 0
SW2EQU 1
;
;========== MAIN PROGRAM =========
;
ORG 0
MOVWF OSCCAL
;
;-------SETUP (LL2=1,POINT=150)
START MOVLW B'00001111' ;PA<5:2>=INPUT, OTHERS =OUTPUT
TRIS GPIO
MOVLW H'80';T0CS=0,ENABLE GP2, ENABLE GPPU0,1,3
OPTION ;
CLRF GPIO;SET ALL OUTPUT LOW
;---------------------------------
CLRFGPIO
CLRF FLAGR
BTFSS GPIO,SW1;SW OPEN=HIGH,QQ=0
BSF FLAGR,QQ
BTFSS GPIO,SW2
BSF FLAGR,RR
;---------------------------------------------
;-----------Who first
;-------WHEN VALID PULSE GO THROUGH, IS THERE > 6 mS BETWEEN?
;-------IF NOT, EXCHANGE THE SEQUENCE
;
W1CLRWDT
BTFSS GPIO,2
GOTO W1
CLRF TMR1;READ INPIN PULSE WEITH
W2 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,2 ;UNTIL INPIN GO LOW
GOTO W2 ;END LOOP
W3 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO W1 ;ELSE IT'S NOISE,
CLRF TMR2;READ INPIN PULSE WEITH
W4 INCF TMR2,F ;START LOOP
CLRWDT
MOVLW 0x21
MOVWF TMR1
W5 DECFSZ TMR1,F ;(3uS * 33)+7=106 uS LOOP
GOTO W5
BTFSS GPIO,3;UNTIL INPIN GO HIGH
GOTO W4 ;
W6 CLRF TMR1;READ INPIN PULSE WEITH
W7 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,3;UNTIL INPIN GO LOW
GOTO W7 ;END LOOP
W8 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO W1 ;ELSE IT'S NOISE, back to w1
W9MOVLW T1
SUBWF TMR2,W
SKPC ;IF f > w, C= 1,JUMP
GOTO W101 ;
BCF FLAGR,FIR; PIN3 GO FIRST
GOTO R101
;--------------------------------
W101CLRWDT
BTFSS GPIO,3
GOTO W101
CLRF TMR1;READ INPIN PULSE WEITH
W102 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,3 ;UNTIL INPIN GO LOW
GOTO W102 ;END LOOP
W103 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO W101 ;ELSE IT'S NOISE,
CLRF TMR2;READ INPIN PULSE WEITH
W104 INCF TMR2,F ;START LOOP
CLRWDT
MOVLW 0x21
MOVWF TMR1
W105 DECFSZ TMR1,F ;(3uS * 33)+7=106 uS LOOP
GOTO W105
BTFSS GPIO,2;UNTIL INPIN GO HIGH
GOTO W104 ;
W106CLRF TMR1;READ INPIN PULSE WEITH
W107 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,2;UNTIL INPIN GO LOW
GOTO W107 ;END LOOP
W108 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO W101 ;ELSE IT'S NOISE, back to w1
W109MOVLW T1
SUBWF TMR2,W
SKPC ;IF f > w, C= 1,JUMP
GOTO W1 ;
BSF FLAGR,FIR; PIN2 GO FIRST
GOTO R1
;---------------------------------------------------
;-------READ VALID PULSES, LIMIT THE NUMBER 100<200
;-------PUT NUMBERS IN X, Y REGISTERS
R1CLRWDT
BTFSS GPIO,2
GOTO R1
CLRF TMR1;READ INPIN PULSE WEITH
R2 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,2 ;UNTIL INPIN GO LOW
GOTO R2 ;END LOOP
R3MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO R1 ;ELSE IT'S NOISE,
MOVLW .99
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R31 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R4 ;ELSE TMR1 >200,
MOVLW .200
MOVWF TMR1
GOTO R4
R31MOVLW .100
MOVWF TMR1
R4 MOVF TMR1,W ;ChXI IS FIRST
MOVWF X
R5CLRWDT
BTFSS GPIO,3
GOTO R5
CLRF TMR1;READ INPIN PULSE WEITH
R6 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,3 ;UNTIL INPIN GO LOW
GOTO R6 ;END LOOP
R7 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO R5 ;ELSE IT'S NOISE, READ FIRST AGAIN
MOVLW .99
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R71 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R8 ;ELSE TMR1 >200,
MOVLW .200
MOVWF TMR1
GOTO R8
R71MOVLW .100
MOVWF TMR1
R8 MOVF TMR1,W ;ChXI NOT FIRST
MOVWF Y
GOTO C10
;------------------
R101CLRWDT
BTFSS GPIO,3
GOTO R101
CLRF TMR1;READ INPIN PULSE WIDTH
R102 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,3 ;UNTIL INPIN GO LOW
GOTO R102 ;END LOOP
R103MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO R101 ;ELSE IT'S NOISE,
MOVLW .99
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R131 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R104 ;ELSE TMR1 >200,
MOVLW .200
MOVWF TMR1
GOTO R104
R131MOVLW .100
MOVWF TMR1
R104 MOVF TMR1,W ;ChXI IS FIRST
MOVWF Y
R105CLRWDT
BTFSS GPIO,2
GOTO R105
CLRF TMR1;READ INPIN PULSE WIDTH
R106 INCF TMR1,F ;START LOOP
CLRWDT
NOP ;10 uS LOOP
NOP
NOP
NOP
NOP
BTFSC GPIO,2 ;UNTIL INPIN GO LOW
GOTO R106 ;END LOOP
R107 MOVLW NOISE
SUBWF TMR1,W
SKPC ;IF f > w, C= 1,SKIP
GOTO R105 ;ELSE IT'S NOISE, READ FIRST AGAIN
MOVLW .99
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R171 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF TMR1,W
SKPC ;IF f > w, C= 1, SKIP
GOTO R108 ;ELSE TMR1 >200,
MOVLW .200
MOVWF TMR1
GOTO R108
R171MOVLW .100
MOVWF TMR1
R108 MOVF TMR1,W ;ChXI NOT FIRST
MOVWF X
GOTO C10
;------------------
;---------------------------------------------------
;-------GET ChA, ChB FROM X,Y,q,r
C10CLRWDT
BTFSC FLAGR,QQ;q=0, NORAL
GOTO C30
BTFSC FLAGR,RR
GOTO C20
;--------------------------
MOVLW .50;QQ=0, RR=0
SUBWF X,W
MOVWF X1; XX=X-50
MOVLW .100
SUBWF Y,W
MOVWF Y1; YY=Y-100
ADDWF X1,W;
MOVWF ChA; A=(X-50)+(Y-100)
MOVLW .50;
ADDWF X,W
MOVWF X1; XX=X+50
MOVF Y1,W
SUBWF X1,W
MOVWF ChB; B=(X+50)-(Y-100)
GOTO P1
;-----------------------------
C20MOVLW .25;QQ=0, RR=1
SUBWF X,W
MOVWF X1; XX=X-25
MOVLW .100
SUBWF Y,W
MOVWF Y1; YY=Y-100
BCF STATUS,0
RRF Y1,F ;YY=(Y-100)/2
MOVF Y1,W
ADDWF X1,W;
MOVWF ChA; A=(X-25)+((Y-100)/2)
MOVLW .25;
ADDWF X,W
MOVWF X1; XX=X+25
MOVF Y1,W
SUBWF X1,W
MOVWF ChB; B=(X+25)-((Y-100)/2)
GOTO P1
;---------------------------------
C30BTFSC FLAGR,RR;
GOTO C40
;--------------------------
MOVLW .100;QQ=1,RR=0
SUBWF X,W
MOVWF X1
BCF STATUS,0
RRF X1,F ; XX=(X-100)/2
MOVLW .100
SUBWF Y,W
MOVWF Y1; YY=Y-100
MOVLW .75
ADDWF X1,W
ADDWF Y1,W
MOVWF ChA; A=75+((X-100)/2)+(Y-100)
MOVLW .175;
ADDWF X1,F
MOVF Y1,W
SUBWF X1,W
MOVWF ChB; B=175+((X-100)/2)-(Y-100)
GOTO P1
;---------------------------------
C40 MOVF X,W ;QQ=1, RR=1
MOVWF X1
BCF STATUS,0
RRF X1,F ; XX=X/2
MOVF Y,W
MOVWF Y1
BCF STATUS,0
RRF Y1,F;YY=Y/2
MOVF Y1,W;RRF DO NOT INVOLVE W
ADDWF X1,W;
MOVWF ChA; A=(X/2)+(Y/2)
MOVLW .150;
ADDWF X1,F
MOVF Y1,W
SUBWF X1,W
MOVWF ChB; B=(150+(X/2))-(Y/2)
GOTO P1
;
;-------------------------------
;-------RESTRICT ChA, ChB BETWEEN 100~200
;-------AND OUTPUT ChA, ChB (*10uS) TO PIN 0,1
P1CLRWDT
MOVLW .99
SUBWF ChA,W
SKPC ;IF f > w, C= 1, SKIP
GOTO P11 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF ChA,W
SKPC ;IF f > w, C= 1, SKIP
GOTO P12 ;ELSE TMR1 >200,
MOVLW .200
MOVWF ChA
GOTO P12
P11MOVLW .100
MOVWF ChA
;------------------
P12MOVLW .99
SUBWF ChB,W
SKPC ;IF f > w, C= 1, SKIP
GOTO P13 ;ELSE TMR1 < 100,
MOVLW .200
SUBWF ChB,W
SKPC ;IF f > w, C= 1, SKIP
GOTO P15 ;ELSE TMR1 >200,
MOVLW .200
MOVWF ChB
GOTO P15
P13MOVLW .100
MOVWF ChB
;--------------------
P15BSF GPIO,ChA1
P2 CLRWDT;10uS LOOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ ChA,F
GOTO P2; END OF LOOP
BCF GPIO,ChA1
BSF GPIO,ChB1
P3 CLRWDT; 10uS LOOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ ChB,F
GOTO P3; END OF LOOP
BCF GPIO,ChB1
BTFSC FLAGR,FIR
GOTO R1;MAIN PROGRAM LOOP
GOTO R101
;==========================================================
END
|