;**************************************************************************************************
; function: N-次方差计算
;**************************************************************************************************
; INPUT:
; ZH:ZL:= #R_SSP_ADC_CoorBuf_E0E2
; VarL:= NUMBER
; VarL,VarH,VAR2,VAR3
;**************************************************************************************************
Sub_calculation_Coording_3DEA:
CALL Sub_OpenStk_withXDate__11F2
;
WDR
CLR XH
CLR XL
MOVW dw4A, XL
WDR
LDD ZH, Y+$04
LDD ZL, Y+$05 ;D
MOVW dw4E, ZL
; [ 信号曲线参数保存 ]
MOVW ZL, dw4E
PUSH ZL
PUSH ZH
LDI XH, HIGH(R_SSP_ADC_buffer_C307)
LDI XL, LOW(R_SSP_ADC_buffer_C307)
CALL Sub_MOV_SMPADC_To_Coor_42E5
POP ZH
POP ZL
;
LDI XL, $01
LDD XH, Y+$07
TST XH
BREQ _L_next_3E0F
BRLT _L_next_3E0F
_L_loop_3E0B: LSL XL
DEC XH
TST XH
BRNE _L_loop_3E0B ; bgt _L_loop_3E0B
_L_next_3E0F: MOV dw48, XL
LDI ZH, HIGH(R_SSP_ADC_buffer_C307)
LDI ZL, LOW(R_SSP_ADC_buffer_C307)
MOVW dw4d:dw4C, ZH:ZL
MOV dw49, dw48
; RAM_dw4A <== Fun_SUM{ @R_SSP_ADC_buffer_C307+.. for 2^^Stk }
_L_loop_3E1A: TST dw49
BREQ _L_next_3E30
MOVW ZL, dw4D:dw4C
CLR XH
LD XL, Z+
MOVW dw4D:dw4C, ZH:ZL
MOVW ZH:ZL, dw4B:dw4A
ADD ZL, XL
ADC ZH, XH
MOVW dw4B:dw4A, ZH:ZL
DEC dw49
JMP _L_loop_3E1A
;
; RAM_dw4E <== RAM_dw4E + RAM_dw48+1/2
_L_next_3E30: MOV XL, dw48
LSR XL
CLR XH
MOVW ZH:ZL, dw4F:dw4E
ADD ZL, XL
ADC ZH, XH
MOVW dw4F:dw4E, ZH:ZL
;
CLR ZH
MOV ZL, dw48
LDI XL, LOW(D_LONGE_ADC/10) ;
LDI XH, HIGH(D_LONGE_ADC/10) ;
SUB XL, ZL
SBC XH, ZH
MOVW dw47:dw46, XH:XL
WDR
_L_loop_3E44: ; number
TST dw46
BRNE _L_0701_0514
TST dw47
BRNE _L_0701_0514
JMP _L_exit_3E91
_L_0701_0514: WDR
CLR ZH
MOV ZL, dw48
MOVW XL, dw4A
CALL SUB_HC_IDIV ; X/Z == {Fun_SUM{@R_SSP_ADC_buffer_C307+.. for 2^^Stk}} / 2^^Stk
MOVW XH:XL, ZL ; X/Z =>Z, r=>X
MOVW ZH:ZL, dw4E
ST Z+, XL
MOVW dw4E, ZL
;
MOVW ZH:ZL, dw4D:dw4C
CLR XH
MOV XL, dw48
SUB ZL, XL
SBC ZH, XH
LD XL, Z
CLR XH
MOVW ZH:ZL, dw4A
SUB ZL, XL
SBC ZH, XH
MOVW dw4A, ZL
MOVW ZH:ZL, dw4D:dw4C
CLR XH
LD XL, Z+
ADD dw4A, XL
ADC dw4B, XH
MOVW dw4D:dw4C, ZH:ZL
;
MOVW XH:XL, dw47:dw46
SBIW XH:XL, 1
MOVW dw47:dw46, XH:XL
JMP _L_loop_3E44
_L_exit_3E91: MOVW ZH:ZL, dw4E
SBIW ZH:ZL, 1
LDD XL, Z+$00
STS R_C306, XL
;
MOVW XL, dw48
LSR XL
MOV dw49, XL
_L_loop_3E9E: TST dw49
BREQ _L_end_3EB2
MOVW ZL, dw4E
ADIW ZH:ZL, 1
MOVW dw4E, ZL
SBIW ZH:ZL, 1
LDS XL, R_C306
STD Z+$00, XL
DEC dw49
JMP _L_loop_3E9E
_L_end_3EB2: CALL Sub_CloseStk_withXDate__1232 |