📄 main.src
字号:
;************************************************************************
;************************************************************************
;Company: Shenzhen Speedy-Tech Electronics Co.,Ltd
;Title: NiMN_Battery_21A.asm
;Description: This program is for NiMN_Battery charger.
;Author: John Lin
;Date: Software section of project started on 02/01/07
;Revision: P3
;Revision Date: 06/25/07
;Hardware: P3
;Flowchart: 5407-0801_flowchart_P1
;---------------------------------------------------------------------------------------------------*/
;----------------------------------------------REVISION CONTROL------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------
;Revision | Description |Date
;-----------|-----------------------------------------------------------------------------------------------|---------
;NiMN_Battery_P1: The MCU is S3F9454
;-----------|-----------------------------------------------------------------------------------------------|---------
;NiMN_Battery_P2: The MCU is changed to S3F84K4
;-----------|-----------------------------------------------------------------------------------------------|---------
INCLUDE "S3C84K4.REG"
INCLUDE "ram.hea"
INCLUDE "Timer0.hea"
INCLUDE "PWM.hea"
INCLUDE "ADC.hea"
ORG 0000H
ORG 003CH
DB 0FFH ;Must be initialized to 0FFh
DB 0FFH ;Must be initialized to 0FFh
DB 0BFH ;LVR level=3.9v
DB 0FCH ;Internal RC(1MHz)
VECTOR 0F6H,INT_TIMER0
ORG 0100H
RESET: DI ;disable interrupt
LD CLKCON,#00011000B ;one 16-bit timer, select fxx/8 CPU clock
LD SPL,#0C0H ;stack point must be set /********************
LD BTCON,#0A3H ;enable watch dog function
LD P0CONH,#0DCH ;Set P0.7&P0.5 ADC_Input,P0.6 PWM output,P0.4 Push_pull output
LD P0CONL,#00H ;Set P0.0-P0.3 Schmitt trigger input
LD P1CON,#00H ;Set P1.0~P1.2 Schmitt trigger input
LD P2CONH,#3AH ;set P2.6 ADC8 Input,P2.4-P2.5 Push_pull output
LD P2CONL,#80H ;set P2.0-P2.3 pull_up input
LD CHARGE_I1,#0EH ;FLOAT=75mA CURRENT(V_ADC8=0.275V)
LD CHARGE_I2,#8DH ;BULK=750mA CURRENT(V_ADC8=2.75V)
LD CHARGE_I_730mA,#60H ;I=730mA
LD CHARGE_I_770mA,#0B5H ;I=770mA
LD CHARGE_I_50mA,#04H
LD CHARGE_I_100mA,#16H
LD CHARGE_I_800mA,#9AH ;I=800mA(V_ADC8=2.904V)
LD VOLTAGE_NTC0,#0F5H ;The voltage of NTC at -10C(V_-10C=4.78V,R_NTC=40.29K)
LD VOLTAGE_NTC5,#0E8H
LD VOLTAGE_NTC70,#8CH ;The voltage of NTC at 70C(V_70C=2.73V,R_NTC=2.40K)
LD V_NTC80_750mA,#7BH ;The voltage of NTC at 80C When I=750mA(V_80C=2.40V,R_NTC=1.82K)
LD V_NTC80_75mA,#73H ;The voltage of NTC at 80C When I=75mA(V_80C=2.255V,R_NTC=1.82K)
LD VO_H_BATTERY,#0CDH ;The voltage of Battery at 10.0V(V_ADC5=4.0V,75mA)
LD VO_H_BATTERY_B,#0D3H ;The voltage of Battery at 10.0V(V_ADC5=4.0V,750mA)
LD VO_L_BATTERY,#2AH ;The voltage of Battery at 2.0V+0.075*0.33(V_ADC5=0.9V)
LD VO_L_BATTERY_B,#2FH ;The voltage of Battery at 2.0V+0.75*0.33(V_ADC5=0.9V)
LD VO_4V_BATTERY,#51H ;The voltage of Battery at 4.0V(V_ADC5=1.6V)
LD VO_5V_BATTERY,#5BH ;The voltage of Battery at 5.0V(V_ADC5=2.0V)
LD VO_8V_BATTERY,#0A3H ;The voltage of Battery at 8.0V(V_ADC5=3.2V)
CLR FLAG_NTC ;Clear FLAG_NTC80C
CLR KIND_TIMER0 ;Clear KIND_TIMER0
CLR FLAG_BAT_CON
CLR FLAG_FULL
CLR FLAG_I_BIG
OR P2,#30H ;Turn off R_LED
AND P2,#0DFH ;Turn on G_LED
OR P2,#08H ;Turn off MOSFET
LD IMR,#00000111B
LD IPR,#00010011B
INIT_PWM ;Setup PWM_frequency to 50kHz,Make Vo=0V
INIT_TIMER0 ;Setup a 50ms timer refere
EI ;enable interrupt
MAIN: LD BTCON,#02H ;Clear Basic timer counter
CLR FLAG_NTC ;Clear FLAG_NTC80C
CLR KIND_TIMER0 ;Clear KIND_TIMER0
CLR FLAG_BAT_CON
CLR FLAG_FULL
CLR FLAG_I_BIG
CLR FLAG_5C
OR P2,#30H ;Turn off R_LED
AND P2,#0DFH ;Turn on G_LED
OR P2,#08H ;Turn off MOSFET
STOP_TIMER0
LD DATA_PWM,#00H ;Vo=0V
LD PWMDATA,DATA_PWM ;data register setting
BAT_CHECK: ;Check whether Battery is connected
LD BTCON,#02H ;Clear Basic timer counter
ADC7_CHOICE ;Select ADC7 to detect VOLTAGE_NTC
CALL AD_CONV ;Read VOLTAGE_NTC
CP R2,VOLTAGE_NTC0 ;Check whether Battery is connected
JP UGT,BAT_CHECK ;If Battery is disconnected goto MAIN
CALL DELAY20mS ;Delay 20ms for waiting battery connect
ADC7_CHOICE ;Select ADC7 to detect VOLTAGE_NTC
CALL AD_CONV ;Read VOLTAGE_NTC
CP R2,VOLTAGE_NTC0 ;Check whether Battery is connected again
JP UGT,BAT_CHECK ;If Battery is disconnected goto MAIN
CALL DELAY200mS ;Delay 200ms for waiting battery connect
ADC7_CHOICE ;Select ADC7 to detect VOLTAGE_NTC
CALL AD_CONV ;Read VOLTAGE_NTC
CP R2,VOLTAGE_NTC0 ;Check whether Battery is connected again
JP UGT,BAT_CHECK ;If Battery is disconnected goto MAIN
BAT_CONNECT: ;Battery have been connected
OR P2,#30H ;Turn off G_LED
AND P2,#0EFH ;Turn on R_LED
AND P2,#0F7H ;Turn on MOSFET
LD COUNTER0,#064H ;setup COUNTER=30S
LD COUNTER1,#06H
LD COUNTER2,#01H
CLR KIND_TIMER0 ;Precharge
CLR FLAG_TIMER0 ;Clear FLAG_TIMER0
STATR_TIMER0 ;Run TIMER0
LD CHARGE_I_1,CHARGE_I_730mA ;I=730mA
LD CHARGE_I_2,CHARGE_I_770mA ;I=770mA
CALL PWM_CON_0 ;Control the output current
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_H_BATTERY_B ;Check whether the battery voltage is higher than 10V
JP UGT,BAT_FALL_10V ;If Vo>10V, Jamp to BAT_NTC_FALL
CHARGE_I_CON: ;Control the output current use 750mA
LD BTCON,#02H ;Enable watch dog function
CALL PWM_CON_0
LD CHARGE_I,CHARGE_I2 ;Charge Battery use bulk current(750mA)
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CP FLAG_I_BIG,#01H ;Check whether the charge current is higher than 800mA
JP EQ,I_BIG_FAIL ;If Yes,Jamp I_BIG_FAIL
CP R2,#0BBH
JP ULT,CHARGE_I_NEXT
LD DATA_PWM,#02H
CONTROL_PWM
CALL DELAY20mS
CHARGE_I_NEXT:
LD VOLTAGE_NTC,V_NTC80_750mA
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 Battery is connected
JP EQ,MAIN ;If Battery is disconnected,Jamp to MAIN
ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_H_BATTERY_B ;Check whether the battery voltage is higher than 10V
JP UGT,BAT_FALL_10V ;If Vo>10V, Jamp to BAT_NTC_FALL
CP FLAG_TIMER0,#00H ;Check whether 30s overflow
JP EQ,CHARGE_I_CON ;If no,go on loop
SET_3H_TIMER:
STOP_TIMER0
LD COUNTER0,#28H ;setup COUNTER0=2S
LD COUNTER1,#1EH ;setup COUNTER1=1*30S=1min
LD COUNTER2,#0A9H ;setup COUNTER2=2*30*180S=1*180min=3H
LD KIND_TIMER0,#03H ;setup COUNTER=3H
CLR FLAG_TIMER0 ;Clear FLAG_TIMER0
CLR FLAG_COUNT1 ;Clear FLAG_COUNT1
CLR FLAG_5C
CLR VO_DATAH1
CLR VO_DATAL1
STATR_TIMER0 ;Run TIMER0
BULK_CHARGE: ;Enter Bulk charge status
LD BTCON,#02H ;Enable watch dog function
CP FLAG_5C,#01H
JP NE,NEXT1
CP FLAG_COUNT1,#00H ;Check whether 1S timer have overflowed
JP EQ,NEXT1 ;If not go to NEXT1
CLR FLAG_COUNT1 ;Clear 1S timer flag
CALL VO_CHECK
CP FLAG_FULL,#01H ;Check whether the charge voltage is decrease
JP NE,NEXT1 ;If YES,Jamp to FLOAT_CHARGE
FULL_CHECK:
LD R10,#20H
FULL_CHECK1:
CLR FLAG_FULL
CALL VO_CHECK
CP FLAG_FULL,#01H ;Check whether the charge voltage is decrease
JP NE,NEXT1 ;If YES,Jamp to FLOAT_CHARGE
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
DEC R10
JP NZ,FULL_CHECK1
JP FLOAT_CHARGE
NEXT1: ADC5_CHOICE ;Select ADC5 to detect the charge voltage
CALL AD_CONV ;Read the Voltage
CP R2,VO_H_BATTERY_B ;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_B ;Check whether the battery voltage is lower than 2V
JP ULT,BAT_FALL ;If Vo<2V,Jamp to BAT_NTC_FALL
LD CHARGE_I,CHARGE_I2 ;Charge Battery use bulk current(750mA)
CALL PWM_CON_0
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CALL PWM_CON ;Control the output current
CP FLAG_I_BIG,#01H ;Check whether the charge current is higher than 800mA
JP EQ,I_BIG_FAIL ;If Yes,Jamp I_BIG_FAIL
LD VOLTAGE_NTC,VOLTAGE_NTC70
CALL NTC_CHECK ;Check whether the Battery temperature higher than 70C
CP FLAG_NTC,#01H ;
JP EQ,FLOAT_CHARGE ;If T_bat>70C,go to FLOAT_CHARGE
CP FLAG_BAT_CON,#01H ;Check whether the Battery is connected
JP EQ,MAIN ;If Battery is connected,go to MAIN
CP FLAG_TIMER0,#01H ;Check whether 3H timer is overflow
JP EQ,FLOAT_CHARGE ;If 3H timer is overflow,go to FLOAT_CHARGE
JP BULK_CHARGE ;Go on Bulk charge
JP HERE
FLOAT_CHARGE:
LD CHARGE_I_1,CHARGE_I_50mA ;I=730mA
LD CHARGE_I_2,CHARGE_I_100mA ;I=770mA
CALL PWM_CON_0 ;Control the output current
FLOAT_CHARGE1:
LD BTCON,#02H ;Enable watch dog function
STOP_TIMER0
CLR FLAG_FULL
CLR FLAG_TIMER0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -