📄 main.src
字号:
JP EQ,PWM_INC1_1
ADD DATA_PWMEX,#04H
CONTROL_PWM
RET
PWM_INC1_1:
ADD DATA_PWM,#01H ;If DATA_PWM!=0ffH, increase the charge current
CLR DATA_PWMEX
CONTROL_PWM ;CONTROL PWM output
RET
;/*----------------------------Check whether -V=50mV/240Sec---------------------------------------*/
VO_CHECK:
CALL VOLTAGE_CHECK ;Detect the charge voltage
CP VO_DATAH,VO_DATAH1 ;Gain the bigger charge voltage
JP UGT,VO_BIG ;If the charge voltage bigger than before,go to VO_BIG
JP ULT,VO_LIT ;If the charge voltage smaller than before,go to VO_LIT
CP VO_DATAL,VO_DATAL1 ;Gain the bigger charge voltage
JP UGT,VO_BIG ;If the charge voltage bigger than biggest,go to VO_BIG
JP ULT,VO_LIT ;If the charge voltage smaller than biggest,go to VO_LIT
CLR COUNT_S ;If the charge voltage equal to the biggest, Clear COUNT_S
RET
VO_BIG: CALL DELAY20mS
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL PWM_CON
CALL VOLTAGE_CHECK ;Detect the charge voltage
CP VO_DATAH,VO_DATAH1 ;Gain the bigger charge voltage
JP UGT,VO_BIG1 ;If the charge voltage bigger than before,go to VO_BIG
CP VO_DATAL,VO_DATAL1 ;Gain the bigger charge voltage
JP UGT,VO_BIG1 ;If the charge voltage smaller than biggest,go to VO_LIT
RET
VO_BIG1:
LD VO_DATAH1,VO_DATAH ;Load the biggest charge voltage
LD VO_DATAL1,VO_DATAL ;Load the biggest charge voltage
CLR COUNT_S ;Clear COUNT_S
RET
VO_LIT:
CP VO_DATAL1,VO_DATAL
JP UGE,VO_LIT_L1
LD VO_DATA,VO_DATAL
COM VO_DATA
ADD VO_DATA,VO_DATAL1
INC VO_DATA
JP VO_LIT_L
VO_LIT_L1:
LD VO_DATA,VO_DATAL1
SUB VO_DATA,VO_DATAL
VO_LIT_L:
CP VO_DATA,#04H
JP ULE,RET_VO_CHECK
LD FLAG_FULL,#01H
RET_VO_CHECK:
RET
OVER_240S:
CLR COUNT_S
CLR VO_DATAH1
CLR VO_DATAL1
CLR FLAG_COUNT1 ;Clear 1S timer flag
RET
;/*----------------------------Read the charge voltage--------------------------------------------*/
VOLTAGE_CHECK: ;Read the charge voltage
CLR VO_DATAH ;Initialize VO_DATAH
CLR VO_DATAL ;Initialize VO_DATAL
CLR R9 ;Initialize R9
VOLTAGE_CHECK1: ;Begin to Read the charge voltage
ADC5_CHOICE ;Select ADC5 to detect charge voltage
CALL AD_CONV ;Begin conversion
ADD VO_DATAL,AD_DATAL
ADC VO_DATAH,AD_DATAH
CALL PWM_CON ;Control the output current
INC R9 ;R9 ++
CP R9,#04H ;Check whether have conversion 4times
JP ULT,VOLTAGE_CHECK1 ;If not,go on check
RL VO_DATAH
RL VO_DATAH
RL VO_DATAH
RL VO_DATAL
RL VO_DATAL
RL VO_DATAL
LD R9,VO_DATAH
AND VO_DATAL,#07H
AND VO_DATAH,#0F8H
ADD VO_DATAL,VO_DATAH ;Gain the low 8bits of charge voltage
LD VO_DATAH,R9
AND VO_DATAH,#03H ;Gain the high 2bits of charge voltage
RET
;/*---------------------------Check the temperature of battery------------------------------------*/
NTC_CHECK: ;Check whether the temperature of battery is higher than 80C
CLR FLAG_NTC
CLR FLAG_BAT_CON
CLR FLAG_5C
ADC7_CHOICE ;Select ADC7 to detect the temperature of battery
CALL AD_CONV ;read the temperature of battery
CP R2,VOLTAGE_NTC ;Check whether the temperature of battery is higher than 80C
JP ULT,NTC_UNCON ;If higher than 80C, LED_R & LED_G blink and stop charging
CP R2,VOLTAGE_NTC5
JP UGT,NTC_NEXT
LD FLAG_5C,#01H
NTC_NEXT:
CP R2,VOLTAGE_NTC0
JP UGT,SET_FLAG_BAT
RET
SET_FLAG_BAT:
CALL DELAY200mS
ADC7_CHOICE ;Select ADC7 to detect whether battery is connected
CALL AD_CONV ;read the temperature of battery
CP R2,VOLTAGE_NTC0 ;Check whether battery is connected
JP UGE,SET_FLAG_BAT1 ;If higher than the NTC VOLTAGE at 0C,Battery disconnect
RET
SET_FLAG_BAT1:
CALL DELAY200mS
ADC7_CHOICE ;Select ADC7 to detect whether battery is connected
CALL AD_CONV ;read the temperature of battery
CP R2,VOLTAGE_NTC0 ;Check whether battery is connected
JP UGE,SET_FLAG_BAT2 ;If higher than the NTC VOLTAGE at 0C,Battery disconnect
RET
SET_FLAG_BAT2:
LD FLAG_BAT_CON,#01H
RET
NTC_UNCON: ;LED_R & LED_G blink and stop charging
LD FLAG_NTC,#01H
RET
;/*---------------------------LED blink-----------------------------------------------------------*/
DELAY20mS:
LD R0,#0FH ;R0=#0FH
LOOP1_1:LD R1,#0FFH ;R1=#0FFH
LOOP1_0:DEC R1 ;R1--
JR NZ,LOOP1_0 ;Jamp to LOOP1_0 if R1!=0
LD BTCON,#02H ;Clear Basic timer counter
DEC R0 ;R0--
JR NZ,LOOP1_1 ;Jamp to LOOP1_1 if R0!=0
RET ;Return
;/*-------------------------------Delay 0.5s-------------------------------------------------------------------*/
DELAY500mS:
LD R0,#05H ;R0=#05H
LOOP2_2:LD R1,#0FFH ;R1=#0FFH
LOOP2_1:LD R2,#0AFH ;R2=#0AFH
LOOP2_0:DEC R2 ;R2--
JR NZ,LOOP2_0 ;Jamp to LOOP2_0 if R2!=0
LD BTCON,#02H ;Clear Basic timer counter
DEC R1 ;R1--
JR NZ,LOOP2_1 ;Jamp to LOOP2_1 if R1!=0
DEC R0 ;R0--
JR NZ,LOOP2_2 ;Jamp to LOOP2_2 if R0!=0
RET ;Return
;/*-------------------------------Delay 0.2s-------------------------------------------------------------------*/
DELAY200mS:
LD R0,#02H ;R0=#05H
LOOP3_2:LD R1,#0FFH ;R1=#0FFH
LOOP3_1:LD R2,#0AFH ;R2=#0AFH
LOOP3_0:DEC R2 ;R2--
JR NZ,LOOP3_0 ;Jamp to LOOP2_0 if R2!=0
LD BTCON,#02H ;Clear Basic timer counter
DEC R1 ;R1--
JR NZ,LOOP3_1 ;Jamp to LOOP2_1 if R1!=0
DEC R0 ;R0--
JR NZ,LOOP3_2 ;Jamp to LOOP2_2 if R0!=0
RET ;Return
;/*-------------------------------interrupt service subprogram-------------------------------------------------*/
INT_TIMER0:
INTER_TIMER0
IRET
;/*------------------------------------------------------------------------------------------------------------------------
;The subprogram AD_CONV is to sampling 10 data,and the greatest and least will be removed.R2=the sum of 8 data remain/8
;--------------------------------------------------------------------------------------------------------------------------*/
AD_CONV:LD R3,#00H ;Use to load the initially ADDATAH
LD R4,#00H ;Use to load the initially ADDATAL
LD R5,#00H ;Use to load the finally ADDATAH
LD R6,#10H ;Use to load the finally ADDATAH
LD R7,#00H ;Use to count the times of ADD_CONVERSION
CLR 53H ;Use to save the biggest ADDATAH
CLR 54H ;Use to save the biggest ADDATAL
LD 55H,#0FFH ;Use to save the lease ADDATAH
LD 56H,#0FFH ;Use to save the lease ADDATAL
AD_CONV1:LD ADCON,R0 ;Load the ADC channel
LD BTCON,#02H ;Clear Basic timer counter
NOP
NOP
NOP
LOOP5_1:TM ADCON,#00001000B ;Check whether ADC conversion complete
JP Z,LOOP5_1 ;go on checking if in progress
LD R3,ADDATAH ;Read ADDATAH
LD R4,ADDATAL ;Read ADDATAL
RL R3 ;In order to gain the high 2bits of ADDATA
RL R3 ;In order to gain the high 2bits of ADDATA
LD 57H,R3 ;In order to gain the low 8bits of ADDATA
AND R3,#00000011B ;Gain the high 2bits of ADDATA
AND 57H,#11111100B ;In order to gain the low 8bits of ADDATA
AND R4,#03H ;In order to gain the low 8bits of ADDATA
ADD R4,57H ;Gain the low 8bits of ADDATA
CP R3,53H ;Check whether ADDATAH>(53H)
JP ULT,CONV1 ;If ADDATAH<(53H), jamp to CONV1
JP UGT,CONV2 ;If ADDATAH>(53H), load ADDATAH to 53H
CP R4,54H ;If ADDATAH=(53H), Check whether ADDATAL>(54H)
JP ULE,CONV1 ;If ADDATAL<(54H), jamp to CONV1
CONV2: LD 53H,R3 ;If ADDATA>(53H,54H), load ADDATAH to 53H and ADDATAL to 54H
LD 54H,R4
CONV1: CP R3,55H ;Check whether ADDATAH<(55H)
JP UGT,CONV3 ;If ADDATAH>(55H), jamp to CONV3
JP ULT,CONV4 ;If ADDATAH<(55H), load ADDATAH to 55H
CP R4,56H ;If ADDATAH=(55H), check whether ADDATAL<(56H)
JP UGE,CONV3 ;If ADDATAL>(56H), jamp to CONV3
CONV4: LD 55H,R3 ;If ADDATA<(55H,56H), load ADDATAH to 55H and ADDATAL to 56H
LD 56H,R4
CONV3: ADD R6,R4 ;Adding all 10 units ADDATA and load it to (R5,R6)
ADC R5,R3
AND ADCON,#11110111B ;A/D converter is in progress
INC R7 ;The times of A/D convert increase
CP R7,#0AH ;Cheak whether ADC have been converted 10 times
JP ULT,AD_CONV1 ;If not, go on convert
SUB R6,54H ;If finished, subtract the biggest one & the lease one
SBC R5,53H
SUB R6,56H
SBC R5,55H
CP R5,#20H
JP ULT,CONV5
LD R5,#1FH
CONV5: LD AD_DATAH,R5
LD AD_DATAL,R6
RL R5 ;In order to Load the high 8bits to AD_DATAH, Load the low
RL R5 ;2bits to AD_DATAL
RL R5
RL R6
RL R6
RL R6
AND R6,#07H
ADD R5,R6 ;Gain the high 8bits of ADC
LD R2,R5 ;Load the high 8bits to R2
RET
;/*---------------------Timer0 interrupt service subprogram--------------------------------------------------------------------*/
;/*----------------------------------------------------------------------------------------------------------------------------*/
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -