📄 main.src
字号:
CLR FLAG_NTC
CLR FLAG_I_BIG
OR P2,#30H ;Turn off R_LED
AND P2,#0DFH ;Turn on G_LED
LD CHARGE_I,CHARGE_I1 ;Charge Battery use float current(75mA)
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CP FLAG_I_BIG,#01H
JP EQ,I_BIG_FAIL
LD VOLTAGE_NTC,V_NTC80_75mA
CALL NTC_CHECK ;Check whether the Battery temperature higher than 80C
CP FLAG_NTC,#01H ;
JP EQ,PROTECT_NTC ;If T_bat>80C,Jamp to PROTECT_NTC
CP FLAG_BAT_CON,#01H ;Check whether the Battery is connected
JP EQ,MAIN ;If the Battery is disconnected, Go to INIT_SYS
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_H_BATTERY ;Check whether the battery voltage is higher than 10V
JP UGT,BAT_FALL_10V ;If Vo>10V, Jamp to BAT_NTC_FALL
CP R2,VO_L_BATTERY ;Check whether the battery voltage is lower than 2V
JP ULT,BAT_FALL ;If Vo<2V,Jamp to BAT_NTC_FALL
JP FLOAT_CHARGE1 ;Go on control the charge current is 75mA
PROTECT_NTC: ;
STOP_TIMER0 ;TIMER0 stop
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_L_BATTERY_B ;Check whether the battery voltage is lower than 2V
JP UGE,NTC_FAIL ;If Vo<2V,Jamp to BAT_NTC_FALL
CALL DELAY20mS
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_L_BATTERY_B ;Check whether the battery voltage is lower than 2V
JP UGE,NTC_FAIL ;If Vo<2V,Jamp to BAT_NTC_FALL
CALL DELAY200mS
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_L_BATTERY_B ;Check whether the battery voltage is lower than 2V
JP ULT,BAT_NTC_FALL ;If Vo<2V,Jamp to BAT_NTC_FALL
NTC_FAIL: ;The battery temperature is higher than 80C
OR P2,#08H ;If the tempariture of NTC > 80,turn off MOSFET
AND P2,#0CFH ;Turn LED_R & LED_G off
LD KIND_TIMER0,#01H ;Setup LED_R & LED_G blink
LD DATA_PWM,#00H ;Stop charging
LD DATA_PWMEX,#00H
CONTROL_PWM ;CONTROL PWM output
BLINK1_RG:
LD COUNTER0,#0AH ;setup COUNTER=0.5S
LD COUNTER1,#01H
LD COUNTER2,#01H
CLR FLAG_TIMER0 ;Clear FLAG_TIMER0
STATR_TIMER0 ;Run TIMER0
BAT_CHECK1:
LD BTCON,#02H ;Clear Basic timer counter
CP FLAG_TIMER0,#00H ;Check whether the timer0 is overflow
JP EQ,BAT_CHECK1_1
LD COUNTER0,#0AH ;setup COUNTER=0.5S
LD COUNTER1,#01H
LD COUNTER2,#01H
CLR FLAG_TIMER0 ;Clear FLAG_TIMER0
STATR_TIMER0 ;Run TIMER0
BAT_CHECK1_1:
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP ULE,BAT_CHECK1 ;If higher than 0C, battery disconnected
CALL DELAY20mS ;Delay 200mS & Check again
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP ULE,BAT_CHECK1 ;If higher than 0C, battery disconnected
CALL DELAY200mS ;Delay 200mS & Check again
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP ULT,BAT_CHECK1 ;If higher than 0C, battery disconnected
BAT_DISCONNECT:
JP MAIN ;If Battery is disconnected,Jamp to INIT_SYS
BAT_NTC_FALL: ;T_bat>80C & V_bat>10V or V_bat<2V
OR P2,#08H ;If the tempariture of NTC > 80,turn off MOSFET
OR P2,#30H ;Turn LED_G off
AND P2,#0EFH ;Turn LED_R on
LD KIND_TIMER0,#02H ;LED_G blink
LD DATA_PWM,#00H ;Stop charging
LD DATA_PWMEX,#00H
CONTROL_PWM ;CONTROL PWM output
JP BLINK1_RG ;LED_G blink
BAT_FALL: ;V_bat<2V
STOP_TIMER0 ;TIMER0 stop
OR P2,#30H
AND P2,#0CFH ;Turn LED_G & LED_R on
OR P2,#08H ;If Battery is Open or Short,turn off MOSFET
CLR FLAG_TIMER0
LD DATA_PWM,#00H ;Stop charging
LD DATA_PWMEX,#00H
CONTROL_PWM ;CONTROL PWM output
JP BAT_CHECK1 ;Goto check whecher Battery connect
BAT_FALL_10V: ;V_bat>10V
CALL DELAY20mS
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP UGT,MAIN ;If higher than 0C, battery disconnected
CALL DELAY200mS
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP UGT,MAIN ;If higher than 0C, battery disconnected
STOP_TIMER0 ;TIMER0 stop
OR P2,#30H
AND P2,#0CFH ;Turn LED_G & LED_R on
OR P2,#08H ;If Battery is Open or Short,turn off MOSFET
CLR FLAG_TIMER0
LD DATA_PWM,#00H ;Stop charging
LD DATA_PWMEX,#00H
CONTROL_PWM ;CONTROL PWM output
LD R8,#0C8H
BAT_DOWN:
LD BTCON,#02H ;Clear Basic timer counter
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP UGT,MAIN ;If higher than 0C, battery disconnected
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_4V_BATTERY ;Check whether the battery voltage is lower than 2V
JP ULT,BAT_CHECK_10V ;If Vo<2V,Jamp to BAT_NTC_FALL
CALL DELAY500mS
DEC R8
JP NZ,BAT_DOWN
BAT_CHECK_10V:
LD BTCON,#02H ;Clear Basic timer counter
ADC7_CHOICE ;Select ADC7 to Check whether battery is disconnected
CALL AD_CONV ;read the Voltage of the NTC
CP R2,VOLTAGE_NTC0 ;Check whether battery is disconnected
JP UGT,MAIN ;If higher than 0C, battery disconnected
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_5V_BATTERY ;Check whether the battery voltage is lower than 2V
JP ULT,BAT_CHECK_10V ;If Vo<2V,Jamp to BAT_NTC_FALL
CP R2,VO_8V_BATTERY ;Check whether the battery voltage is higher than 10V
JP UGT,BAT_CHECK_10V ;If Vo>10V, Jamp to BAT_NTC_FALL
JP MAIN
I_BIG_FAIL:
STOP_TIMER0 ;TIMER0 stop
OR P2,#30H ;Turn off LED_G & LED_R
AND P2,#0DFH ;Turn on G_LED
OR P2,#08H ;If Battery is Open or Short,turn off MOSFET
CLR FLAG_TIMER0
CLR FLAG_I_BIG
LD DATA_PWM,#00H ;Stop charging
LD DATA_PWMEX,#00H
CONTROL_PWM ;CONTROL PWM output
JP BAT_CHECK1 ;Goto check whecher Battery connect
HERE: LD BTCON,#02H ;Clear Basic timer counter
JP HERE
;/*----------------------------Control the output current-----------------------------------------*/
PWM_CON_0: ;Control the output current
LD BTCON,#02H ;Clear Basic timer counter
ADC8_CHOICE ;select ADC8 to detect the charge current
CALL AD_CONV ;read the value of charge current
CP R2,CHARGE_I_2 ;Check whether the charge current is bigger than 770mA
JP UGT,PWM_DEC_0 ;If Io>770mA, reduce the charge current
CP R2,CHARGE_I_1 ;Check whether the charge current is lower than 730mA
JP ULT,PWM_INC_0 ;If Io<730mA, increase the charge current
RET
PWM_DEC_0:
CP DATA_PWM,#00H ;Check whether DATA_PWM=0
JP NE,PWM_DEC_0_1 ;If DATA_PWM=0, Check whether the charge current is bigger than 800mA
RET ;If not, go on control PWM
PWM_DEC_0_1:
SUB DATA_PWM,#01H ;If DATA_PWM!=0, reduce the charge current
CONTROL_PWM ;CONTROL PWM output
JP PWM_CON_0 ;Go on control PWM
PWM_INC_0:
CP DATA_PWM,#3FH ;Check whether DATA_PWM=0FFH
JP NE,PWM_INC_0_1 ;If DATA_PWM=0ffH, keep on the output current
RET
PWM_INC_0_1:
ADD DATA_PWM,#01H ;If DATA_PWM!=0ffH, increase the charge current
CONTROL_PWM ;CONTROL PWM output
JP PWM_CON_0
;/*----------------------------Control the output current-----------------------------------------*/
PWM_CON: ;Control the output current
ADC8_CHOICE ;select ADC8 to detect the charge current
CALL AD_CONV ;read the value of charge current
CP R2,CHARGE_I ;Check whether the charge current is the bulk current
JP UGT,PWM_DEC ;If Io>Ibulk, reduce the charge current
JP ULT,PWM_INC ;If Io<Ibulk, increase the charge current
RET
PWM_DEC:CP DATA_PWM,#00H ;Check whether DATA_PWM=0
JP NE,PWM_DEC1 ;If DATA_PWM=0, keep on the output current
CP DATA_PWMEX,#00H
JP NE,PWM_DEC1
ADC8_CHOICE ;select ADC8 to detect the charge current
CALL AD_CONV ;read the value of charge current
CP R2,CHARGE_I_800mA ;Check whether the charge current is the bulk current
JP UGE,SET_FLAG_I
RET
SET_FLAG_I:
LD FLAG_I_BIG,#01H
RET
PWM_DEC1:
CP DATA_PWMEX,#00H
JP EQ,PWM_DEC1_1
SUB DATA_PWMEX,#04H
CONTROL_PWM
RET
PWM_DEC1_1:
SUB DATA_PWM,#01H ;If DATA_PWM!=0, reduce the charge current
LD DATA_PWMEX,#0FCH
CONTROL_PWM ;CONTROL PWM output
RET
PWM_INC:
CP DATA_PWM,#3FH ;Check whether DATA_PWM=0FFH
JP NE,PWM_INC1 ;If DATA_PWM=0ffH, keep on the output current
CP DATA_PWMEX,#0FCH
JP NE,PWM_INC1
LD FLAG_I_BIG,#01H
RET
PWM_INC1:
CP DATA_PWMEX,#0FCH
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -