;==========================================================
;Copy 16bit results to Temp regs
;40-45h = Time values
;d1,d2,d3,d4,d5,d6 = Temp Regs
;Median = d3,d4
;==========================================================
Cal_Median movf 40h,W
movwf d1
movf 41h,W
movwf d2
movf 42h,W
movwf d3
movf 43h,W
movwf d4
movf 44h,W
movwf d5
movf 45h,W
movwf d6
;
movlw .2
movwf Pass_Count
Next_1 call Comp_1_2
btfss STATUS,C
goto Next_2
Swap_1_2 movf d1,W
movwf Temp
movf d3,W
movwf d1
movf Temp,W
movwf d3
;
movf d2,W
movwf Temp
movf d4,W
movwf d2
movf Temp,W
movwf d4
Next_2 call Comp_2_3
btfss STATUS,C
goto Cal_Pass
Swap_2_3 movf d3,W
movwf Temp
movf d5,W
movwf d3
movf Temp,W
movwf d5
;
movf d4,W
movwf Temp
movf d6,W
movwf d4
movf Temp,W
movwf d6
Cal_Pass decfsz Pass_Count,F
goto Next_1
return ;d3,d4 = Median
;------------------------------------------
Comp_1_2 movf d3,W
subwf d1,W
btfss STATUS,Z
return
movf d4,W
subwf d2,W
return
Comp_2_3 movf d5,W
subwf d3,W
btfss STATUS,Z
return
movf d6,W
subwf d4,W
return