///////////////////////////////////////////////////////////////////////////////
//
// IAR C/C++ Compiler V2.10.4.157 for STM8                10/Aug/2020  13:50:19
// Copyright 2010-2015 IAR Systems AB.
//
//    Source file  =  F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\QMC5883L.c
//    Command line =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\QMC5883L.c -e -Ol --no_cse
//        --no_unroll --no_inline --no_code_motion --no_tbaa --no_cross_call
//        --debug --code_model small --data_model medium -o
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\Obj\ --dlib_config
//        E:\IAR\stm8\LIB\dlstm8smf.h -lB
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\inc\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\radio\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\SX1278\ --vregs 16
//    List file    =  F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\QMC5883L.s
//
///////////////////////////////////////////////////////////////////////////////

        EXTERN ?add32_l0_l0_0x
        EXTERN ?b0
        EXTERN ?b1
        EXTERN ?b2
        EXTERN ?b3
        EXTERN ?epilogue_l2_l3
        EXTERN ?epilogue_l2_w6
        EXTERN ?inc32_l1_l1
        EXTERN ?inc32_l2_l2
        EXTERN ?load32_0x_l1
        EXTERN ?load32_0x_l3
        EXTERN ?load32_l0_0x
        EXTERN ?mov_l0_l3
        EXTERN ?mov_l1_l0
        EXTERN ?mov_l3_l0
        EXTERN ?move1616_v_x_y_a
        EXTERN ?mul16_x_x_w0
        EXTERN ?push_l2
        EXTERN ?push_l3
        EXTERN ?push_w6
        EXTERN ?sdiv16_x_x_y
        EXTERN ?srl32_l0_l0_db
        EXTERN ?w0
        EXTERN ?w1
        EXTERN ?w2
        EXTERN ?w3
        EXTERN ?w4
        EXTERN ?w5
        EXTERN ?w6
        EXTERN ?w7
        EXTERN BeepStart
        EXTERN CarAction
        EXTERN CarRecDataStr
        EXTERN Init_HMC5883
        EXTERN Multiple_Read_HMC5883
        EXTERN SendData
        EXTERN Single_Read_HMC5883
        EXTERN Single_Write_HMC5883
        EXTERN SystemPara
        EXTERN VAL_PHOTO
        EXTERN abs
        EXTERN ge_state
        EXTERN geo_wave_flag
        EXTERN get_photoresistor_ad
        EXTERN judge_day_night
        EXTERN mag_time_count
        EXTERN memcpy
        EXTERN no_car_count
        EXTERN ph_car_out
        EXTERN ph_stable_value

        PUBLIC NO_car_deal
        PUBLIC QMC5883LStr
        PUBLIC QmcDeal
        PUBLIC geomag_car_in
        PUBLIC geomag_car_out
        PUBLIC geomag_self_adaption
        PUBLIC have_car_send

// F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\QMC5883L.c
//    1 #include "QMC5883L.h"

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    2 struct QMCSTR QMC5883LStr;
QMC5883LStr:
        DS8 32
//    3 static void QmcTest(void)
//    4 {

        SECTION `.near.data`:DATA:REORDER:NOROOT(0)
//    5         static enum QMC_STATE QmcState = IDLE;
??QmcState:
        DC8 4

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    6         static uint8_t buff[MagDataNum][6] = {0},qmc_dec_count = 0;
??buff:
        DS8 36

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??qmc_dec_count:
        DS8 1

        SECTION `.near_func.text`:CODE:NOROOT(0)
        CODE
QmcDeal:
        REQUIRE QmcTest
        ;               // Fall through to label QmcTest

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
QmcTest:
        CALL      L:?push_l2
        CALL      L:?push_l3
        SUB       SP, #0x18
//    7         uint32_t temp[6] = {0},i=0,j=0;
        LDW       Y, #?_0
        LDW       X, SP
        ADDW      X, #0x1
        PUSHW     X
        LD        A, #0x18
        CALL      L:?move1616_v_x_y_a
        POPW      X
        CLRW      X
        LDW       S:?w3, X
        LDW       S:?w2, X
        CLRW      X
        LDW       S:?w5, X
        LDW       S:?w4, X
//    8 	switch(QmcState)
        LD        A, L:??QmcState
        TNZ       A
        JREQ      L:??QmcTest_0
        DEC       A
        JREQ      L:??QmcTest_1
        DEC       A
        JRNE      ??lb_0
        JP        L:??QmcTest_2
??lb_0:
        SUB       A, #0x2
        JRNE      ??lb_1
        JP        L:??QmcTest_3
??lb_1:
        JP        L:??QmcTest_4
//    9 	{
//   10 		case qmc_init:
//   11 		{
//   12                     if(Init_HMC5883())
??QmcTest_0:
        CALL      L:Init_HMC5883
        CP        A, #0x0
        JREQ      L:??QmcTest_5
//   13                     {
//   14                         QmcState = qmc_dec;
        MOV       L:??QmcState, #0x1
//   15                         qmc_dec_count = 0;
        MOV       L:??qmc_dec_count, #0x0
//   16                         ge_state = YES;
        MOV       L:ge_state, #0x1
        JP        L:??QmcTest_4
//   17                     }
//   18                     else
//   19                     {
//   20                         ge_state = NO;
??QmcTest_5:
        MOV       L:ge_state, #0x0
//   21                     }
//   22                     break;
        JP        L:??QmcTest_4
//   23 		}
//   24 		case qmc_dec:
//   25 		{
//   26                       if((Single_Read_HMC5883(SLAVE_ADD,0x06))&0x01){;}
??QmcTest_1:
        MOV       S:?b0, #0x6
        LD        A, #0x1a
        CALL      L:Single_Read_HMC5883
        AND       A, #0x1
        CP        A, #0x0
        JRNE      ??lb_2
        JP        L:??QmcTest_4
//   27                       else
//   28                         return;
//   29                       Multiple_Read_HMC5883(SLAVE_ADD,buff[qmc_dec_count++]);
??lb_2:
        LD        A, L:??qmc_dec_count
        LD        S:?b0, A
        LD        A, S:?b0
        ADD       A, #0x1
        LD        L:??qmc_dec_count, A
        CLRW      Y
        EXG       A, YL
        LD        A, S:?b0
        EXG       A, YL
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       X, Y
        CALL      L:?mul16_x_x_w0
        ADDW      X, #??buff
        LD        A, #0x1a
        CALL      L:Multiple_Read_HMC5883
//   30 		      if(qmc_dec_count>=MagDataNum)
        LD        A, L:??qmc_dec_count
        CP        A, #0x6
        JRNC      ??lb_3
        JP        L:??QmcTest_4
//   31                       {
//   32                           QMC5883LStr.DataOkFlag = TRUE;
??lb_3:
        MOV       L:QMC5883LStr, #0x1
//   33                           for(j=0;j<6;j++)
        CLRW      X
        LDW       S:?w5, X
        LDW       S:?w4, X
        JP        L:??QmcTest_6
//   34                           {
//   35                               for(i=1;i<MagDataNum-1;i++)temp[j] += buff[i][j];
??QmcTest_7:
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       X, S:?w3
        CALL      L:?mul16_x_x_w0
        ADDW      X, #??buff
        ADDW      X, S:?w5
        LD        A, (X)
        CLRW      X
        LD        XL, A
        LDW       S:?w7, X
        CLRW      X
        LDW       S:?w6, X
        LDW       X, #0x4
        LDW       S:?w0, X
        LDW       X, S:?w5
        CALL      L:?mul16_x_x_w0
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       S:?w0, X
        LDW       X, Y
        ADDW      X, S:?w0
        CALL      L:?mov_l0_l3
        CALL      L:?add32_l0_l0_0x
        CALL      L:?mov_l3_l0
        LDW       X, #0x4
        LDW       S:?w0, X
        LDW       X, S:?w5
        CALL      L:?mul16_x_x_w0
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       S:?w0, X
        ADDW      Y, S:?w0
        LDW       X, Y
        CALL      L:?load32_0x_l3
        CALL      L:?inc32_l1_l1
??QmcTest_8:
        LDW       X, S:?w2
        CPW       X, #0x0
        JRNE      L:??QmcTest_9
        LDW       X, S:?w3
        CPW       X, #0x5
??QmcTest_9:
        JRC       L:??QmcTest_7
//   36                               temp[j] = temp[j]/(MagDataNum-2);
        LDW       X, #0x4
        LDW       S:?w0, X
        LDW       X, S:?w5
        CALL      L:?mul16_x_x_w0
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       S:?w0, X
        ADDW      Y, S:?w0
        LDW       X, Y
        CALL      L:?load32_l0_0x
        CALL      L:?srl32_l0_l0_db
        DATA
        DC8       0x2
        CODE
        CALL      L:?mov_l1_l0
        LDW       X, #0x4
        LDW       S:?w0, X
        LDW       X, S:?w5
        CALL      L:?mul16_x_x_w0
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       S:?w0, X
        ADDW      Y, S:?w0
        LDW       X, Y
        CALL      L:?load32_0x_l1
        CALL      L:?inc32_l2_l2
??QmcTest_6:
        LDW       X, S:?w4
        CPW       X, #0x0
        JRNE      L:??QmcTest_10
        LDW       X, S:?w5
        CPW       X, #0x6
??QmcTest_10:
        JRNC      L:??QmcTest_11
        CLRW      X
        LDW       S:?w2, X
        INCW      X
        LDW       S:?w3, X
        JRA       L:??QmcTest_8
//   37                           }
//   38                           for(i=0;i<6;i++)QMC5883LStr.QMC_CUR_ROPORT[i] = temp[i];
??QmcTest_11:
        CLRW      X
        LDW       S:?w3, X
        LDW       S:?w2, X
        JRA       L:??QmcTest_12
??QmcTest_13:
        LDW       X, #0x4
        LDW       S:?w0, X
        LDW       X, S:?w3
        CALL      L:?mul16_x_x_w0
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       S:?w0, X
        ADDW      Y, S:?w0
        LDW       X, Y
        CALL      L:?load32_l0_0x
        LD        A, S:?b3
        LDW       X, S:?w3
        ADDW      X, #QMC5883LStr + 2
        LD        (X), A
        CALL      L:?inc32_l1_l1
??QmcTest_12:
        LDW       X, S:?w2
        CPW       X, #0x0
        JRNE      L:??QmcTest_14
        LDW       X, S:?w3
        CPW       X, #0x6
??QmcTest_14:
        JRC       L:??QmcTest_13
//   39                           for(i=0;i<3;i++)
        CLRW      X
        LDW       S:?w3, X
        LDW       S:?w2, X
        JRA       L:??QmcTest_15
//   40                           {
//   41                                 QMC5883LStr.QMC_CUR[i] = QMC5883LStr.QMC_CUR_ROPORT[i*2+1];
??QmcTest_16:
        LDW       X, S:?w3
        SLLW      X
        ADDW      X, #QMC5883LStr + 3
        LD        A, (X)
        CLRW      Y
        LD        YL, A
        LDW       X, S:?w3
        SLLW      X
        ADDW      X, #QMC5883LStr + 26
        LDW       (X), Y
//   42                                 QMC5883LStr.QMC_CUR[i]<<=8;
        LDW       X, S:?w3
        SLLW      X
        ADDW      X, #QMC5883LStr + 26
        LDW       X, (X)
        CLR       A
        RLWA      X, A
        LDW       Y, S:?w3
        SLLW      Y
        ADDW      Y, #QMC5883LStr + 26
        LDW       (Y), X
//   43                                 QMC5883LStr.QMC_CUR[i] += QMC5883LStr.QMC_CUR_ROPORT[i*2];
        LDW       X, S:?w3
        SLLW      X
        ADDW      X, #QMC5883LStr + 2
        LD        A, (X)
        CLRW      Y
        LD        YL, A
        LDW       X, S:?w3
        SLLW      X
        ADDW      X, #QMC5883LStr + 26
        LDW       X, (X)
        LDW       S:?w0, Y
        ADDW      X, S:?w0
        LDW       Y, S:?w3
        SLLW      Y
        ADDW      Y, #QMC5883LStr + 26
        LDW       (Y), X
//   44                           }
        CALL      L:?inc32_l1_l1
??QmcTest_15:
        LDW       X, S:?w2
        CPW       X, #0x0
        JRNE      L:??QmcTest_17
        LDW       X, S:?w3
        CPW       X, #0x3
??QmcTest_17:
        JRC       L:??QmcTest_16
//   45                           if(HC_DEBUG)UsartPrint(QMC5883LStr.QMC_CUR_ROPORT,6);
//   46                           QmcState = qmc_lowpower;
        MOV       L:??QmcState, #0x2
//   47                       }
//   48                       break;
        JRA       L:??QmcTest_4
//   49 		}
//   50 		case qmc_lowpower:
//   51 		{
//   52                       Single_Write_HMC5883(SLAVE_ADD,0x0a,0x80);
??QmcTest_2:
        MOV       S:?b1, #0x80
        MOV       S:?b0, #0xa
        LD        A, #0x1a
        CALL      L:Single_Write_HMC5883
//   53                       SCL_H;
        BSET      L:0x5005, #0x3
//   54                       SDA_H;
        BSET      L:0x5005, #0x2
//   55                       QmcState = IDLE;
        MOV       L:??QmcState, #0x4
//   56                       break;
        JRA       L:??QmcTest_4
//   57 		}
//   58                 case IDLE:
//   59                 {
//   60                     if(QMC5883LStr.DataOkFlag==0)QmcState = qmc_init;
??QmcTest_3:
        LD        A, L:QMC5883LStr
        CP        A, #0x0
        JRNE      L:??QmcTest_4
        MOV       L:??QmcState, #0x0
//   61                     break;
//   62                 }
//   63 		default :break;
//   64 	}
//   65 
//   66 }
??QmcTest_4:
        ADD       SP, #0x18
        JP        L:?epilogue_l2_l3
//   67 
//   68 void QmcDeal(void)
//   69 {
//   70 	QmcTest();
//   71 }
//   72 
//   73 ////////////////////地磁检测车进入//////////////////////////////////////////
//   74 /***
//   75 输入：无
//   76 功能：地磁检测车进入
//   77 输出：无
//   78 ***/

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   79 int geomag_car_in(void)
//   80 {
//   81         static uint8_t stable_count = 0;
//   82         static int tempX,tempY,tempZ,tempStableX,tempStableY,tempStableZ;
//   83         tempX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BASE[0]);
geomag_car_in:
        LDW       X, L:QMC5883LStr + 26
        SUBW      X, L:QMC5883LStr + 8
        CALL      L:abs
        LDW       L:??tempX, X
//   84         tempY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BASE[1]);
        LDW       X, L:QMC5883LStr + 28
        SUBW      X, L:QMC5883LStr + 10
        CALL      L:abs
        LDW       L:??tempY, X
//   85         tempZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BASE[2]);
        LDW       X, L:QMC5883LStr + 30
        SUBW      X, L:QMC5883LStr + 12
        CALL      L:abs
        LDW       L:??tempZ, X
//   86         tempStableX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BEFORE[0]);
        LDW       X, L:QMC5883LStr + 26
        SUBW      X, L:QMC5883LStr + 14
        CALL      L:abs
        LDW       L:??tempStableX, X
//   87         tempStableY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BEFORE[1]);
        LDW       X, L:QMC5883LStr + 28
        SUBW      X, L:QMC5883LStr + 16
        CALL      L:abs
        LDW       L:??tempStableY, X
//   88         tempStableZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BEFORE[2]);
        LDW       X, L:QMC5883LStr + 30
        SUBW      X, L:QMC5883LStr + 18
        CALL      L:abs
        LDW       L:??tempStableZ, X
//   89 	if(( tempX > 2*SystemPara.QmcFixPara[2])||(tempZ > 2*SystemPara.QmcFixPara[2]))//已检测到车
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        SLLW      X
        CPW       X, L:??tempX
        JRSLT     L:??geomag_car_in_0
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        SLLW      X
        CPW       X, L:??tempZ
        JRSGE     L:??geomag_car_in_1
//   90 	{
//   91 		//前后二次电磁值相比较，若大于阀值，则说明变化明显，有效
//   92 		if(tempStableX > 0x50||tempStableZ > 0x50)//车未停稳
??geomag_car_in_0:
        LDW       X, L:??tempStableX
        CPW       X, #0x51
        JRSGE     L:??geomag_car_in_2
        LDW       X, L:??tempStableZ
        CPW       X, #0x51
        JRSLT     L:??geomag_car_in_3
//   93 		{
//   94                         memcpy(QMC5883LStr.QMC_BEFORE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
??geomag_car_in_2:
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       Y, #QMC5883LStr + 26
        LDW       X, #QMC5883LStr + 14
        CALL      L:memcpy
//   95 			stable_count = 0;
        MOV       L:??stable_count, #0x0
//   96 		}
//   97 		else //车稳了
//   98 		{
//   99 			stable_count++;
//  100 			if(stable_count >= 6)
//  101 			{
//  102 				stable_count = 6;
//  103 				memcpy(QMC5883LStr.QMC_STABLE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
//  104 				return 1;
//  105 			}
//  106 		}
//  107 	}
//  108         return 0;
??geomag_car_in_1:
        CLRW      X
        RET
??geomag_car_in_3:
        LD        A, L:??stable_count
        ADD       A, #0x1
        LD        L:??stable_count, A
        LD        A, L:??stable_count
        CP        A, #0x6
        JRC       L:??geomag_car_in_1
        MOV       L:??stable_count, #0x6
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       Y, #QMC5883LStr + 26
        LDW       X, #QMC5883LStr + 20
        CALL      L:memcpy
        CLRW      X
        INCW      X
        RET
//  109 }

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??stable_count:
        DS8 1

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempX:
        DS8 2

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempY:
        DS8 2

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempZ:
        DS8 2

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempStableX:
        DS8 2

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempStableY:
        DS8 2

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??tempStableZ:
        DS8 2
//  110 /////////////////////////////地磁检测车离开/////////////////////////////
//  111 /***
//  112 输入：first_dec：对参数进行清零；next_dec：正常检测
//  113 功能：地磁检测车离开
//  114 输出：1：车离开；0：车未离开
//  115 ***/

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  116 int geomag_car_out(int flag)
//  117 {
geomag_car_out:
        CALL      L:?push_l2
        CALL      L:?push_l3
        SUB       SP, #0x2
//  118         int tempX,tempY,tempZ,tempStableX,tempStableY,tempStableZ;
//  119         static uint8_t again_change_count = 0,again_change_count1 = 0;
//  120         tempX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_STABLE[0]);
        LDW       X, L:QMC5883LStr + 26
        SUBW      X, L:QMC5883LStr + 20
        CALL      L:abs
        LDW       S:?w7, X
//  121         tempY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_STABLE[1]);
        LDW       X, L:QMC5883LStr + 28
        SUBW      X, L:QMC5883LStr + 22
        CALL      L:abs
        LDW       S:?w6, X
//  122         tempZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_STABLE[2]);
        LDW       X, L:QMC5883LStr + 30
        SUBW      X, L:QMC5883LStr + 24
        CALL      L:abs
        LDW       (0x1,SP), X
//  123         tempStableX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BEFORE[0]);
        LDW       X, L:QMC5883LStr + 26
        SUBW      X, L:QMC5883LStr + 14
        CALL      L:abs
        LDW       S:?w4, X
//  124         tempStableY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BEFORE[1]);
        LDW       X, L:QMC5883LStr + 28
        SUBW      X, L:QMC5883LStr + 16
        CALL      L:abs
        LDW       S:?w5, X
//  125         tempStableZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BEFORE[2]);
        LDW       X, L:QMC5883LStr + 30
        SUBW      X, L:QMC5883LStr + 18
        CALL      L:abs
        LDW       Y, X
//  126 
//  127 
//  128          /***有波动***/
//  129         if((tempX > SystemPara.QmcFixPara[2])||(tempZ > SystemPara.QmcFixPara[2]))
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        CPW       X, S:?w7
        JRSLT     L:??geomag_car_out_0
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        CPW       X, (0x1,SP)
        JRSGE     L:??geomag_car_out_1
//  130 	{
//  131                 if((tempStableX > 0x50)||(tempStableZ > 0x50))
??geomag_car_out_0:
        LDW       X, S:?w4
        CPW       X, #0x51
        JRSGE     L:??geomag_car_out_2
        CPW       Y, #0x51
        JRSLT     L:??geomag_car_out_3
//  132                 {
//  133 			again_change_count1 = 0;
??geomag_car_out_2:
        MOV       L:??again_change_count1, #0x0
        JRA       L:??geomag_car_out_1
//  134 		}
//  135 		else
//  136 		{
//  137 			again_change_count1++;
??geomag_car_out_3:
        LD        A, L:??again_change_count1
        ADD       A, #0x1
        LD        L:??again_change_count1, A
//  138 			if(again_change_count>=SystemPara.QmcFixPara[1] )
        LD        A, L:??again_change_count
        CP        A, L:SystemPara + 19
        JRC       L:??geomag_car_out_1
//  139 			{
//  140                                  geo_wave_flag = 1;//有波动
        CLRW      X
        INCW      X
        LDW       L:geo_wave_flag, X
//  141 			}
//  142 
//  143 		}
//  144 
//  145 	}
//  146 
//  147 	if((tempX > 2*SystemPara.QmcFixPara[2])||(tempZ > 2*SystemPara.QmcFixPara[2]))
??geomag_car_out_1:
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        SLLW      X
        CPW       X, S:?w7
        JRSLT     L:??geomag_car_out_4
        LD        A, L:SystemPara + 20
        CLRW      X
        LD        XL, A
        SLLW      X
        CPW       X, (0x1,SP)
        JRSGE     L:??geomag_car_out_5
//  148 	{
//  149 		if((tempStableX > 0x50)||(tempStableZ > 0x50))
??geomag_car_out_4:
        LDW       X, S:?w4
        CPW       X, #0x51
        JRSGE     L:??geomag_car_out_6
        CPW       Y, #0x51
        JRSLT     L:??geomag_car_out_7
//  150 		{
//  151 			memcpy(QMC5883LStr.QMC_BEFORE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
??geomag_car_out_6:
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       Y, #QMC5883LStr + 26
        LDW       X, #QMC5883LStr + 14
        CALL      L:memcpy
//  152 			again_change_count = 0;
        MOV       L:??again_change_count, #0x0
//  153 		}
//  154 		else
//  155 		{
//  156 			again_change_count++;
//  157 			if(again_change_count>=SystemPara.QmcFixPara[1] )
//  158 			{
//  159                                return 1;
//  160 			}
//  161 
//  162 		}
//  163 	}
//  164 	return 0;
??geomag_car_out_5:
        CLRW      X
??geomag_car_out_8:
        ADD       SP, #0x2
        JP        L:?epilogue_l2_l3
??geomag_car_out_7:
        LD        A, L:??again_change_count
        ADD       A, #0x1
        LD        L:??again_change_count, A
        LD        A, L:??again_change_count
        CP        A, L:SystemPara + 19
        JRC       L:??geomag_car_out_5
        CLRW      X
        INCW      X
        JRA       L:??geomag_car_out_8
//  165 
//  166 }

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??again_change_count:
        DS8 1

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??again_change_count1:
        DS8 1
//  167 /////////////////////////////地磁自适应////////////////////////////////
//  168 /***
//  169 功能：地磁自适应
//  170 ***/

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  171 void geomag_self_adaption(void)
//  172 {
geomag_self_adaption:
        CALL      L:?push_l2
        CALL      L:?push_w6
//  173 	//set_parking_space_status=0;
//  174 	//mag_time_count=0;
//  175         int mag_x_OPT,mag_y_OPT;
//  176         int mag_x_filter = QMC5883LStr.QMC_CUR[0],mag_y_filter = QMC5883LStr.QMC_CUR[2];
        LDW       X, L:QMC5883LStr + 26
        LDW       Y, X
        LDW       X, L:QMC5883LStr + 30
        LDW       S:?w5, X
//  177         int CARON_magX = QMC5883LStr.QMC_BASE[0],CARON_magY = QMC5883LStr.QMC_BASE[2];
        LDW       X, L:QMC5883LStr + 8
        LDW       S:?w0, X
        LDW       X, L:QMC5883LStr + 12
        LDW       S:?w6, X
//  178 
//  179 	mag_x_OPT=abs(mag_x_filter-CARON_magX);
        LDW       X, Y
        SUBW      X, S:?w0
        CALL      L:abs
        LDW       S:?w4, X
//  180 	mag_y_OPT=abs(mag_y_filter-CARON_magY);
        LDW       X, S:?w5
        SUBW      X, S:?w6
        CALL      L:abs
//  181 	if(mag_x_OPT>0x90||mag_y_OPT>0x90)
        LDW       Y, S:?w4
        CPW       Y, #0x91
        JRSGE     L:??geomag_self_adaption_0
        CPW       X, #0x91
        JRSLT     L:??geomag_self_adaption_1
//  182 	{
//  183 		if(mag_x_OPT>mag_y_OPT)
??geomag_self_adaption_0:
        CPW       X, S:?w4
        JRSGE     L:??geomag_self_adaption_2
//  184 		{
//  185 			SystemPara.QmcFixPara[2]= mag_x_OPT/3;
        LDW       X, #0x3
        LDW       Y, X
        LDW       X, S:?w4
        CALL      L:?sdiv16_x_x_y
        LD        A, XL
        LD        L:SystemPara + 20, A
        JP        L:?epilogue_l2_w6
//  186 		}
//  187 		else
//  188 			SystemPara.QmcFixPara[2]= mag_y_OPT/3;
??geomag_self_adaption_2:
        LDW       Y, #0x3
        CALL      L:?sdiv16_x_x_y
        LD        A, XL
        LD        L:SystemPara + 20, A
        JP        L:?epilogue_l2_w6
//  189 	}
//  190 	else if(SystemPara.QmcFixPara[2]>=45)
??geomag_self_adaption_1:
        LD        A, L:SystemPara + 20
        CP        A, #0x2d
        JRC       L:??geomag_self_adaption_3
//  191 	{
//  192 		SystemPara.QmcFixPara[2]=SystemPara.QmcFixPara[2]-0x10;
        LD        A, L:SystemPara + 20
        ADD       A, #0xf0
        LD        L:SystemPara + 20, A
//  193 	}
//  194 }
??geomag_self_adaption_3:
        JP        L:?epilogue_l2_w6
//  195 //////////////////////////////
//  196 /***
//  197 功能：有车处理函数
//  198 ***/

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  199 void have_car_send()
//  200 {
//  201                 memcpy(QMC5883LStr.QMC_STABLE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
have_car_send:
        LDW       X, #0x6
        LDW       S:?w0, X
        LDW       Y, #QMC5883LStr + 26
        LDW       X, #QMC5883LStr + 20
        CALL      L:memcpy
//  202                 get_photoresistor_ad();
        CALL      L:get_photoresistor_ad
//  203                 ph_stable_value = VAL_PHOTO;
        LDW       X, L:VAL_PHOTO
        LDW       L:ph_stable_value, X
//  204                 judge_day_night(first_dec);
        CLRW      X
        INCW      X
        CALL      L:judge_day_night
//  205                 ph_car_out(first_dec);
        CLRW      X
        INCW      X
        CALL      L:ph_car_out
//  206                 geomag_car_out(first_dec);                          
        CLRW      X
        INCW      X
        CALL      L:geomag_car_out
//  207                 BeepStart(4,0);
        CLR       A
        LDW       X, #0x4
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        CALL      L:BeepStart
//  208                 CarRecDataStr.CarState = 1;
        MOV       L:CarRecDataStr + 11, #0x1
//  209                 CarRecDataStr.CmdSource = 3;
        MOV       L:CarRecDataStr + 9, #0x3
//  210                 SendData(HAVE_CAR);
        LD        A, #0x23
        JP        L:SendData
//  211 }
//  212 
//  213 /***
//  214 功能：无车处理函数
//  215 ***/

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  216 void NO_car_deal(void)//无车处理
//  217 {
//  218         mag_time_count = 0;
NO_car_deal:
        MOV       L:mag_time_count, #0x0
//  219         BeepStart(1,1);
        LD        A, #0x1
        CLRW      X
        LDW       S:?w0, X
        INCW      X
        LDW       S:?w1, X
        CALL      L:BeepStart
//  220         CarRecDataStr.CarState = 0;
        MOV       L:CarRecDataStr + 11, #0x0
//  221         CarRecDataStr.CmdSource = 2;
        MOV       L:CarRecDataStr + 9, #0x2
//  222         no_car_count ++;
        LDW       X, L:no_car_count
        INCW      X
        LDW       L:no_car_count, X
//  223         if(no_car_count>=6)//无车自动升起只允许尝试5次
        LDW       X, L:no_car_count
        CPW       X, #0x6
        JRSLT     L:??NO_car_deal_0
//  224         {
//  225               no_car_count = 6;
        LDW       X, #0x6
        LDW       L:no_car_count, X
//  226               return;
        RET
//  227         }
//  228 	geomag_car_out(first_dec);//复位内部变量
??NO_car_deal_0:
        CLRW      X
        INCW      X
        CALL      L:geomag_car_out
//  229 	ph_car_out(first_dec);//复位内部变量
        CLRW      X
        INCW      X
        CALL      L:ph_car_out
//  230         CarAction(0,0,1,1);
        MOV       S:?b2, #0x1
        MOV       S:?b1, #0x1
        CLR       S:?b0
        CLR       A
        CALL      L:CarAction
//  231         CarRecDataStr.CarState = 0;
        MOV       L:CarRecDataStr + 11, #0x0
//  232         CarRecDataStr.CmdSource = 2;
        MOV       L:CarRecDataStr + 9, #0x2
//  233         judge_day_night(first_dec);
        CLRW      X
        INCW      X
        CALL      L:judge_day_night
//  234         SendData(HAVE_CAR);
        LD        A, #0x23
        JP        L:SendData
//  235         
//  236 }

        SECTION VREGS:DATA:REORDER:NOROOT(0)

        SECTION `.near.rodata`:CONST:REORDER:NOROOT(0)
?_0:
        DC32 0, 0, 0, 0, 0, 0

        END
// 
//    84 bytes in section .near.bss
//     1 byte  in section .near.data
//    24 bytes in section .near.rodata
// 1 204 bytes in section .near_func.text
// 
// 1 204 bytes of CODE  memory
//    24 bytes of CONST memory
//    85 bytes of DATA  memory
//
//Errors: none
//Warnings: 9
