论坛元老
积分 6661
金钱 6661
注册时间 2016-5-29
在线时间 909 小时
1 金钱
chip sn8p2711b
//{{SONIX_CODE_OPTION
.Code_Option LVD LVD_L
.Code_Option Reset_Pin P04
.Code_Option Watch_Dog Disable
.Code_Option High_Clk IHRC_16M
.Code_Option Fcpu Fosc/16
.Code_Option Security Enable
.Code_Option Noise_Filter Enable
//}}SONIX_CODE_OPTION
.DATA
ORG 0H
CHARGEA DS 1 ;----> chargeA setChargeA
SETCHARGEA DS 1
PWM DS 1 ;----> PWM
V1 DS 1 ;----> V1 2
V1@1 DS 1
LAST_V1 DS 1 ;----> last_v1 2
LAST_V1@1 DS 1
DELTA_V DS 1 ;----> delta_v 2
DELTA_V@1 DS 1
ADCV DS 1 ;----> adcv 2;临时ADC电压保存值
ADCV@1 DS 1
ENDV1 DS 1 ;----> endv1 2
ENDV1@1 DS 1
RS0 DS 1 ;----> RS0 RS1
RS1 DS 1
FLAG DS 1 ;----> FLAG flag2 TICKN
FLAG2 DS 1
TICKN DS 1
ADCN DS 1 ;----> ADCN NADC
NADC DS 1
BUFN DS 1 ;----> BUFN ; ADC转换次数 8次再求一次平均值.
STATE DS 1 ;----> state
DELTA_VT DS 1 ;----> delta_vt
MS DS 1 ;----> ms sec v1_0vTime chargeOKtime offlineTime
SEC DS 1
V1_0VTIME DS 1
CHARGEOKTIME DS 1
OFFLINETIME DS 1
T9N DS 1 ;----> t9n t2n t4n
T2N DS 1
T4N DS 1
ONLINETIME DS 1 ;----> ONLINETIME
BATN DS 1 ;----> batn VCA
VCA DS 1
SCAN DS 1 ;----> SCAN VN
VN DS 1
PWMN DS 1 ;----> pwmn
CHAN DS 1 ;----> chAn
MYCHA DS 1 ;----> mycha
LASTCHA DS 1 ;----> lastCha
ON EQU 0 ;//ON 0
OFF EQU 1 ;//OFF 1
CHOKT EQU 20 ;//CHOKT 20
TICK EQU FLAG.0 ;//TICK FLAG.0
TEST_V EQU FLAG.1 ;//TEST_V FLAG.1
CHARGEOK EQU FLAG.2 ;//CHARGEOK FLAG.2
CHARGING EQU FLAG.3 ;//CHARGING FLAG.3
FLASHCHLED EQU FLAG.4 ;//FLASHCHLED FLAG.4
LED1 EQU P0.2 ;//LED1 P0.2
LED2 EQU P4.0 ;//LED2 P4.0
T9NVAL EQU 8 ;//T9NVAL 8
REDLED EQU LED1 ;//REDLED LED1
GREENLED EQU LED2 ;//GREENLED LED2
PWM_PIN EQU P5.3 ;//PWM_PIN P5.3
NADC_VAL EQU 2 ;//NADC_VAL 2
MINCHA EQU 4 ;//MINCHA 4
MAXCHA EQU 100 ;//MAXCHA 100
ENDCHA EQU 20 ;//ENDCHA 20
SCANVAL EQU 4 ;//SCANVAL 4
CHECK6VH EQU 0X5 ;//CHECK6VH 118000*6/488/256
CHECK6VL EQU 0XAA ;//CHECK6VL 118000*6/488%256
CHECK5VH EQU 0X4 ;//CHECK5VH 118000*5/488/256
CHECK5VL EQU 0XB9 ;//CHECK5VL 118000*5/488%256
CHECK4VH EQU 0X3 ;//CHECK4VH 118000*4/488/256
CHECK4VL EQU 0XC7 ;//CHECK4VL 118000*4/488%256
CHECK3VH EQU 0X2 ;//CHECK3VH 118000*3/488/256
CHECK3VL EQU 0XD5 ;//CHECK3VL 118000*3/488%256
CHECK2VH EQU 0X1 ;//CHECK2VH 118000*2/488/256
CHECK2VL EQU 0XE3 ;//CHECK2VL 118000*2/488%256
CHECK1VH EQU 0X0 ;//CHECK1VH 118000*1/488/256
CHECK1VL EQU 0XF1 ;//CHECK1VL 118000*1/488%256
SET6VH EQU 0X7 ;//SET6VH 150000*6 /488/256
SET6VL EQU 0X34 ;//SET6VL 150000*6/488%256
SET5VH EQU 0X6 ;//SET5VH 150000*5/488/256
SET5VL EQU 0X0 ;//SET5VL 150000*5/488%256
SET4VH EQU 0X4 ;//SET4VH 150000*4/488/256
SET4VL EQU 0XCD ;//SET4VL 150000*4/488%256
SET3VH EQU 0X3 ;//SET3VH 150000*3/488/256
SET3VL EQU 0X9A ;//SET3VL 150000*3/488%256
SET2VH EQU 0X2 ;//SET2VH 150000*2/488/256
SET2VL EQU 0X66 ;//SET2VL 150000*2/488%256
SET1VH EQU 0X1 ;//SET1VH 150000*1/488/256
SET1VL EQU 0X33 ;//SET1VL 150000*1/488%256
.CODE
ORG 0H
NOP
NOP
NOP
JMP RESET
ORG 8H
PUSH
BTS1 FTC0IRQ ;----> if ftc0irq else .@f
JMP @F
BCLR FTC0IRQ ;----> ftc0irq..
BSET TICK ;----> tick 1
@@:
EXIT_INT:
POP
RETI
INIT:
CALL GPIO_INIT ;----> gpio_init()
CALL TIMER0_INIT ;----> TIMER0_INIT()
CALL TIMER1_INIT ;----> timer1_init()
CALL ADC_INIT ;----> ADC_INIT()
CALL VAR_INIT ;----> var_init()
MOV A,#0X64 ;----> MS 100
MOV MS,A
MOV A,#0X04 ;----> scan SCANVAL
MOV SCAN,A
RET
TIMER1_INIT:
MOV A,#0X08 ;----> T0M 0X08
MOV T0M,A
CLR TC1C ;----> TC1C 0
MOV A,#0X01 ;----> TC1R 1
MOV TC1R,A
MOV PWM,A ;----> PWM 1
MOV A,#0X91 ;----> TC1M 0X91
MOV TC1M,A
RET
GPIO_INIT:
MOV A,#0X04 ;----> P0M 0X4
MOV P0M,A
CLR P0 ;----> P0 0X0
MOV A,#0X1B ;----> P0UR 0X1B
MOV P0UR,A
MOV A,#0X01 ;----> P4M 0X1
MOV P4M,A
CLR P4 ;----> P4 0X0
MOV A,#0X0C ;----> P4UR 0XC
MOV P4UR,A
MOV A,#0X12 ;----> P4CON 0X12
MOV P4CON,A
MOV A,#0X18 ;----> P5M 0X18
MOV P5M,A
MOV A,#0X08 ;----> P5 0X08
MOV P5,A
CLR P5UR ;----> P5UR 0X0
RET
TIMER0_INIT:
CLR T0M ;----> T0M ..
MOV A,#0X06 ;----> TC0C 6
MOV TC0C,A
MOV TC0R,A ;----> TC0R 6
MOV A,#0XE4 ;----> TC0M 0XE4
MOV TC0M,A
BSET FTC0IEN
RET
ADC_INIT:
MOV A,#0X03 ;----> VREFH 3;参考电压VDD. 5.0V ADC精度4096级
MOV VREFH,A
MOV A,#0X50 ;----> ADR 0X50
MOV ADR,A
MOV A,#0XD4 ;----> ADM 0XD4
MOV ADM,A
MOV A,#0X02 ;----> NADC NADC_VAL
MOV NADC,A
RET
VAR_INIT:
MOV A,#0X14 ;----> v1_0vTime 20
MOV V1_0VTIME,A
MOV A,#0X0A ;----> vn 10
MOV VN,A
MOV A,#0X04 ;----> setChargeA minChA
MOV SETCHARGEA,A
BCLR CHARGEOK ;----> chargeOK..
BSET FPWM1OUT ;----> fpwm1out 1
CLR STATE ;----> state..
CLR ENDV1 ;----> endv1 ..
CLR ENDV1@1 ;----> endv1@1..
MOV A,#0X14 ;----> offlineTime 20
MOV OFFLINETIME,A
BSET REDLED ;----> redled off
BSET GREENLED ;----> greenled off
BCLR FLASHCHLED ;----> flashchLed..
RET
RESET:
MOV A,#0X64 ;----> DELAY_US(100)
CALL DELAY_US
CALL CLR_RAM
CALL INIT
MOV A,#0X64 ;----> DELAY_US(100)
CALL DELAY_US
BSET FGIE
MAIN:
CALL GET_ADC ;----> GET_ADC()
BTS1 TICK ;----> IF TICK ELSE .MAIN
JMP MAIN
BCLR TICK ;----> TICK..
INCMS TICKN ;----> TICKN++
NOP
MOV A,TICKN ;----> IF TICKN<10
SUB A,#0X0A
BTS0 FC
CLR TICKN ;----> TICKN..
MOV A,TICKN ;----> PCL+TICKN
ADD PCL,A
JMP TASK0
JMP TASK1
JMP TASK2
JMP TASK3
JMP TASK4
JMP TASK5
JMP TASK6
JMP TASK7
JMP TASK8
JMP TASK9
JMP MAIN
TASK0:
BTS1 CHARGEOK ;----> if chargeOK else .main;充电OK相关处理
JMP MAIN
BSET REDLED ;----> redled off ;关闭充电灯
BCLR GREENLED ;----> greenled on ; 开充满LED灯
BCLR FPWM1OUT ;----> fpwm1out.. ;关闭PWM
BCLR PWM_PIN ;----> pwm_pin ..
MOV A,V1@1 ;----> IF V1@1 .. ELSE .@F
BTS1 FZ
JMP @F
MOV A,V1 ;----> if v1 < 40 ELSE .@F ;电压接近0V,视为未连接
SUB A,#0X28
BTS0 FC
JMP @F
DECMS V1_0VTIME ;----> if v1_0vTime-- else .main
JMP MAIN
CALL VAR_INIT ;----> var_init();电池拨出后,初始化相关变量为初始化状态
JMP MAIN
@@:
MOV A,#0X0F ;----> v1_0vTime 15
MOV V1_0VTIME,A
JMP MAIN
TASK1:
DECMS MS ;----> IF MS -- ELSE .MAIN ;1秒时间到.
JMP MAIN
MOV A,#0X64 ;----> MS 100
MOV MS,A
BSET TEST_V ;----> test_v 1;启动电压测量
CALL CHECK_V_OK ;----> check_v_ok()
MOV A,ENDV1@1 ;----> if endv1@1 | endv1 != 0 else .main
OR A,ENDV1
BTS0 FZ
JMP MAIN
MOV A,ENDV1@1 ;----> if v1@1 > endv1@1 else .@f
SUB A,V1@1
BTS0 FC
JMP @F
JMP @99
@@:
MOV A,V1@1 ;----> if v1@1 = endv1@1 else .exit1
CMPRS A,ENDV1@1
JMP EXIT1
MOV A,ENDV1 ;----> if v1 > endv1 else .exit1
SUB A,V1
BTS0 FC
JMP EXIT1
@99:
DECMS T9N ;----> IF T9N-- ELSE .main
JMP MAIN
MOV A,STATE ;----> IF STATE = 2 ELSE .@f
CMPRS A,#0X02
JMP @F
MOV A,#0X03 ;----> state 3
MOV STATE,A
MOV A,#0X08 ;----> t9n t9nval
MOV T9N,A
@@:
MOV A,STATE ;----> if state = 3 else .main
CMPRS A,#0X03
JMP MAIN
MOV A,#0X14 ;----> IF SETCHARGEA > ENDCHA ELSE .@F
SUB A,SETCHARGEA
BTS0 FC
JMP @F
DECMS SETCHARGEA ;----> SETCHARGEA --
NOP
JMP MAIN
@@:
MOV A,STATE ;----> IF STATE = 3 ELSE .MAIN
CMPRS A,#0X03
JMP MAIN
BSET CHARGEOK ;----> chargeOK 1
MOV A,#0X04 ;----> STATE 4
MOV STATE,A
JMP MAIN
EXIT1:
MOV A,#0X08 ;----> T9N t9nval
MOV T9N,A
JMP MAIN
TASK2:
BTS0 CHARGEOK ;----> if chargeOk.. else .main
JMP MAIN
MOV A,STATE ;----> if state < 3 else .main
SUB A,#0X03
BTS0 FC
JMP MAIN
BTS1 FLASHCHLED ;----> if flashchled else .main
JMP MAIN
BCLR REDLED ;----> redled on
TASK3:
BTS0 CHARGEOK ;----> if chargeOK = 0 else .main ; 充电进行中,被拔出
JMP MAIN
BTS1 CHARGING ;----> if charging else .@f
JMP @F
MOV A,#0X32 ;----> offlineTime 50
MOV OFFLINETIME,A
BSET FLASHCHLED ;----> flashchLed 1 ;正常充电进行中,闪红灯
JMP MAIN
@@:
MOV A,OFFLINETIME ;----> IF OFFLINETIME ELSE .MAIN
BTS0 FZ
JMP MAIN
MOV A,STATE ;----> IF STATE != 1 ELSE .MAIN
XOR A,#0X01
BTS0 FZ
JMP MAIN
DECMS OFFLINETIME ;----> if offlineTime-- else .main ;否则,被拔出2000毫秒,为拔出,关闭充电灯
JMP MAIN
CALL VAR_INIT ;----> var_init()
JMP MAIN
TASK4:
JMP MAIN
TASK5:
MOV A,PWMN ;----> if pwmn != 0 else .main
BTS0 FZ
JMP MAIN
DECMS PWMN ;----> if pwmn -- else .main
JMP MAIN
MOV A,PWM ;----> if pwm .. else .main
BTS1 FZ
JMP MAIN
MOV A,#0X01 ;----> pwm 1
MOV PWM,A
MOV TC1R,A ;----> TC1R 1
JMP MAIN
TASK6:
JMP MAIN
TASK7:
JMP MAIN
TASK8:
JMP MAIN
TASK9:
JMP MAIN
CLR_RAM:
CLR Y ;----> Y..
MOV A,#0X3F ;----> Z 63
MOV Z,A
NEXT_CLRRAM:
CLR @YZ ;----> YZ..
DECMS Z ;----> IF Z--
JMP NEXT_CLRRAM
CLR @YZ ;----> YZ..
RET
DELAY_US:
BTS0 FZ ;----> IF A ELSE RET
RET
MOV R,A ;----> R A
NEXT_US:
DECMS R ;----> IF R--
JMP NEXT_US
RET
DELAY_MS:
BTS0 FZ ;----> IF A ELSE RET
RET
MOV Y,A ;----> Y A
NEXT_MS:
MOV A,#0XF8 ;----> CALL DELAY_US(248)
CALL DELAY_US
MOV A,#0XF8 ;----> CALL DELAY_US(248)
CALL DELAY_US
MOV A,#0XF8 ;----> CALL DELAY_US(248)
CALL DELAY_US
MOV A,#0XF8 ;----> CALL DELAY_US(248)
CALL DELAY_US
DECMS Y ;----> IF Y--
JMP NEXT_MS
RET
SETVN:
MOV A,#0X0A ;----> vn 10
MOV VN,A
RET
CHECK_V_OK:
BTS0 CHARGEOK ;----> if chargeOK.. else ret
RET
MOV A,STATE ;----> if state = 3 else ret
CMPRS A,#0X03
RET
MOV A,ENDV1@1 ;----> if endv1@1 | endv1 != 0 else .setvn
OR A,ENDV1
BTS0 FZ
JMP SETVN
MOV A,ENDV1@1 ;----> if v1@1 > endv1@1 else .@f
SUB A,V1@1
BTS0 FC
JMP @F
JMP VOK
@@:
MOV A,V1@1 ;----> if v1@1 = endv1@1 else .setvn
CMPRS A,ENDV1@1
JMP SETVN
MOV A,ENDV1 ;----> if v1 > endv1 else .setvn
SUB A,V1
BTS0 FC
JMP SETVN
VOK:
DECMS VN ;----> if vn-- else ret
RET
BSET CHARGEOK ;----> chargeOK 1
MOV A,#0X04 ;----> STATE 4
MOV STATE,A
RET
GET_ADC:
BTS1 FEOC ;----> IF FEOC ELSE RET
RET
BCLR FEOC ;----> FEOC ..
MOV A,NADC ;----> IF NADC ELSE .@F
BTS0 FZ
JMP @F
DECMS NADC ;----> NADC --
NOP
JMP RESTART_ADC
@@:
MOV A,ADR ;----> y= ADR&0X0F
AND A,#0X0F
MOV Y,A
MOV A,ADB ;----> r adb
MOV R,A
SWAPM R ;----> r<>
MOV A,R ;----> z= r & 0xf0
AND A,#0XF0
MOV Z,A
MOV A,Z ;----> y | z
OR Y,A
MOV A,#0X0F ;----> r & 0x0f
AND R,A
MOV A,Y ;----> RS0 + y
ADD RS0,A
MOV A,R ;----> A R
ADC RS1,A
INCMS BUFN ;----> BUFN++
NOP
MOV A,BUFN ;----> IF BUFN >= 16 ELSE .restart_adc
SUB A,#0X10
BTS1 FC
JMP RESTART_ADC
BCLR FC ;----> FC..
RRCM RS1 ;----> RS1>>>
RRCM RS0 ;----> RS0>>>
BCLR FC
RRCM RS1 ;----> RS1>>>
RRCM RS0 ;----> RS0>>>
BCLR FC ;----> FC..
RRCM RS1 ;----> RS1>>>
RRCM RS0 ;----> RS0>>>
BCLR FC ;----> FC..
RRCM RS1 ;----> RS1>>>
RRCM RS0 ;----> RS0>>>
MOV A,RS0 ;----> ADCV RS0
MOV ADCV,A
MOV A,RS1 ;----> ADCV@1 RS1
MOV ADCV@1,A
CLR BUFN ;----> BUFN RS1 RS0 0
CLR RS1
CLR RS0
MOV A,ADCN ;----> PCL+ADCN
ADD PCL,A
JMP TD4
JMP TD1
TD4:
BCLR FC ;----> FC..
RRCM ADCV@1 ;----> ADCV@1>>>
RRCM ADCV ;----> ADCV>>>
MOV A,ADCV ;----> chargeA ADCV
MOV CHARGEA,A
BTS1 TEST_V ;----> IF TEST_V ELSE .RESTART_ADC
JMP RESTART_ADC
BCLR TEST_V ;----> TEST_V..
MOV A,#0X02 ;----> NADC NADC_VAL
MOV NADC,A
MOV A,#0X01 ;----> ADCN 1
MOV ADCN,A
MOV A,#0XD1 ;----> ADM 0XD1
MOV ADM,A
CALL SET_PWM_FROM_CHARGEA ;----> SET_PWM_from_chargeA()
RET
TD1:
MOV A,ADCV ;----> V1 ADCV
MOV V1,A
MOV A,ADCV@1 ;----> V1@1 ADCV@1
MOV V1@1,A
CLR ADCN ;----> ADCN ..
MOV A,#0XD4 ;----> ADM 0XD4
MOV ADM,A
MOV A,#0X02 ;----> NADC NADC_VAL
MOV NADC,A
CALL CHANGESETCHA ;----> changeSetChA()
RET
RESTART_ADC:
BSET FADS ;----> FADS 1
CALL SET_PWM_FROM_CHARGEA ;----> SET_PWM_from_chargeA()
RET
SET_PWM_FROM_CHARGEA:
MOV A,CHARGEA ;----> if chargeA != 0 else .@f
BTS0 FZ
JMP @F
MOV A,#0X01 ;----> mycha 1
MOV MYCHA,A
JMP N90
@@:
CLR MYCHA ;----> mycha ..
N90:
MOV A,MYCHA ;----> if mycha = lastcha else .@f
CMPRS A,LASTCHA
JMP @F
MOV A,CHAN ;----> if chan < 200 else .N99
SUB A,#0XC8
BTS0 FC
JMP N99
INCMS CHAN ;----> chan++
NOP
MOV A,CHAN ;----> IF CHAN = 5 ELSE .N99
CMPRS A,#0X05
JMP N99
MOV A,MYCHA ;----> a mycha
BTS0 FZ ;----> if a else charging..
BCLR CHARGING
BTS1 FZ ;----> if a .. else charging 1
BSET CHARGING
JMP N99
@@:
CLR CHAN ;----> chan..
MOV A,MYCHA ;----> lastcha mycha
MOV LASTCHA,A
N99:
MOV A,CHARGEA ;----> IF chargeA < setChargeA ELSE .@F
SUB A,SETCHARGEA
BTS0 FC
JMP @F
MOV A,PWM ;----> IF PWM<255 ELSE RET
SUB A,#0XFF
BTS0 FC
RET
INCMS PWM ;----> PWM++
NOP
JMP WRITE_TC1R
@@:
MOV A,SETCHARGEA ;----> IF chargeA > setChargeA+1 ELSE RET
ADD A,#0X01
SUB A,CHARGEA
BTS0 FC
RET
MOV A,PWM ;----> IF PWM ELSE RET
BTS0 FZ
RET
DECMS PWM ;----> PWM--
NOP
MOV A,PWMN ;----> if pwmn = 0 else .WRITE_TC1R
BTS1 FZ
JMP WRITE_TC1R
MOV A,#0X03 ;----> pwmn 3
MOV PWMN,A
WRITE_TC1R:
MOV A,PWM ;----> TC1R PWM
MOV TC1R,A
RET
CLR_DELTA_V:
CLR DELTA_V@1 ;----> DELTA_V@1..
CLR DELTA_V ;----> DELTA_V..
MOV A,V1 ;----> LAST_V1 V1
MOV LAST_V1,A
MOV A,V1@1 ;----> LAST_V1@1 V1@1
MOV LAST_V1@1,A
RET
CHANGESETCHA:
BTS1 FLASHCHLED ;----> IF flashChLed != 0 ELSE .CLR_DELTA_V
JMP CLR_DELTA_V
MOV A,STATE ;----> IF STATE < 2 ELSE .@F
SUB A,#0X02
BTS0 FC
JMP @F
MOV A,#0X03 ;----> VCA 3
MOV VCA,A
MOV A,#0X06 ;----> batn 6
MOV BATN,A
JMP NFF
@@:
MOV A,BATN ;----> VCA BATN
MOV VCA,A
NFF:
MOV A,V1 ;----> delta_v = v1-last_v1
SUB A,LAST_V1
MOV DELTA_V,A
MOV A,V1@1 ;----> a v1@1
SBC A,LAST_V1@1
MOV DELTA_V@1,A ;----> delta_v@1 a
MOV A,V1 ;----> last_v1 v1
MOV LAST_V1,A
MOV A,V1@1 ;----> LAST_V1@1 V1@1
MOV LAST_V1@1,A
BTS0 DELTA_V@1.7 ;----> IF DELTA_V@1.7 =0 else .@F
JMP @F
MOV A,DELTA_V@1 ;----> IF DELTA_V@1=0 ELSE .MFF
BTS1 FZ
JMP MFF
MOV A,VCA ;----> IF DELTA_V > vca ELSE .@F
SUB A,DELTA_V
BTS0 FC
JMP @F
MFF:
MOV A,#0X04 ;----> SCAN SCANVAL
MOV SCAN,A
RET
@@:
DECMS SCAN ;----> IF SCAN-- ELSE RET
RET
MOV A,#0X04 ;----> SCAN SCANVAL
MOV SCAN,A
MOV A,STATE ;----> if state = 0 else .@f
BTS1 FZ
JMP @F
MOV A,SETCHARGEA ;----> if setchargeA >= 40 else .@f
SUB A,#0X28
BTS1 FC
JMP @F
MOV A,#0X01 ;----> state = 1
MOV STATE,A
MOV A,#0X08 ;----> t9n t9nval
MOV T9N,A
CALL SET_ENDV ;----> set_endv()
@@:
MOV A,#0X02 ;----> if state <= 2 else RET
SUB A,STATE
BTS1 FC
RET
MOV A,SETCHARGEA ;----> if setchargeA < maxCha else ret
SUB A,#0X64
BTS0 FC
RET
MOV A,BATN ;----> setchargeA+batn
ADD SETCHARGEA,A
MOV A,#0X64 ;----> IF SETCHARGEA > MAXCHA ELSE RET
SUB A,SETCHARGEA
BTS0 FC
RET
MOV A,#0X64 ;----> SETCHARGEA MAXCHA
MOV SETCHARGEA,A
RET
SET_ENDV:
MOV A,STATE ;----> if state = 1 else ret
CMPRS A,#0X01
RET
MOV A,#0X02 ;----> state = 2
MOV STATE,A
JMP TEST_S5
MOV A,#0X05 ;----> if v1@1 > check6vh else .@F
SUB A,V1@1
BTS0 FC
JMP @F
JMP S6
@@:
MOV A,V1@1 ;----> if v1@1 = check6vh else .test_s5
CMPRS A,#0X05
JMP TEST_S5
MOV A,V1 ;----> if v1 >= check6vl else .test_s5
SUB A,#0XAA
BTS1 FC
JMP TEST_S5
S6:
MOV A,#0X0C ;----> batn 12
MOV BATN,A
MOV A,#0X34 ;----> endv1 set6vl
MOV ENDV1,A
MOV A,#0X07 ;----> endv1@1 set6vh
MOV ENDV1@1,A
RET
TEST_S5:
MOV A,#0X04 ;----> if v1@1 > check5vh else .@F
SUB A,V1@1
BTS0 FC
JMP @F
JMP S5
@@:
MOV A,V1@1 ;----> if v1@1 = check5vh else .test_s4
CMPRS A,#0X04
JMP TEST_S4
MOV A,V1 ;----> if v1 >= check5vl else .test_s4
SUB A,#0XB9
BTS1 FC
JMP TEST_S4
S5:
MOV A,#0X0A ;----> batn 10
MOV BATN,A
CLR ENDV1 ;----> endv1 set5vl
MOV A,#0X06 ;----> endv1@1 set5vh
MOV ENDV1@1,A
RET
TEST_S4:
MOV A,#0X03 ;----> if v1@1 > check4vh else .@F
SUB A,V1@1
BTS0 FC
JMP @F
JMP S4
@@:
MOV A,V1@1 ;----> if v1@1 = check4vh else .test_s3
CMPRS A,#0X03
JMP TEST_S3
MOV A,V1 ;----> if v1 >= check4vl else .test_s3
SUB A,#0XC7
BTS1 FC
JMP TEST_S3
S4:
MOV A,#0X08 ;----> batn 8
MOV BATN,A
MOV A,#0XCD ;----> endv1 set4vl
MOV ENDV1,A
MOV A,#0X04 ;----> endv1@1 set4vh
MOV ENDV1@1,A
RET
TEST_S3:
MOV A,#0X02 ;----> if v1@1 > check3vh else .@F
SUB A,V1@1
BTS0 FC
JMP @F
JMP S3
@@:
MOV A,V1@1 ;----> if v1@1 = check3vh else .test_s2
CMPRS A,#0X02
JMP TEST_S2
MOV A,V1 ;----> if v1 >= check3vl else .test_s2
SUB A,#0XD5
BTS1 FC
JMP TEST_S2
S3:
MOV A,#0X06 ;----> batn 6
MOV BATN,A
MOV A,#0X9A ;----> endv1 set3vl
MOV ENDV1,A
MOV A,#0X03 ;----> endv1@1 set3vh
MOV ENDV1@1,A
RET
TEST_S2:
MOV A,#0X01 ;----> if v1@1 > check2vh else .@F
SUB A,V1@1
BTS0 FC
JMP @F
JMP S2
@@:
MOV A,V1@1 ;----> if v1@1 = check2vh else .test_s1
CMPRS A,#0X01
JMP TEST_S1
MOV A,V1 ;----> if v1 >= check2vl else .test_s1
SUB A,#0XE3
BTS1 FC
JMP TEST_S1
S2:
MOV A,#0X04 ;----> batn 4
MOV BATN,A
MOV A,#0X66 ;----> endv1 set2vl
MOV ENDV1,A
MOV A,#0X02 ;----> endv1@1 set2vh
MOV ENDV1@1,A
RET
TEST_S1:
MOV A,V1@1 ;----> if v1@1 > check1vh else .@f
BTS0 FZ
JMP @F
JMP S1
@@:
MOV A,V1 ;----> if v1 >= check1vl else .@f
SUB A,#0XF1
BTS1 FC
JMP @F
S1:
MOV A,#0X02 ;----> batn 2
MOV BATN,A
MOV A,#0X33 ;----> endv1 =set1vL
MOV ENDV1,A
MOV A,#0X01 ;----> endv1@1 =set1vh
MOV ENDV1@1,A
RET
@@:
CLR STATE ;----> state ..
MOV A,#0X04 ;----> setchargeA mincha
MOV SETCHARGEA,A
RET
ENDP
我来回答