⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p08011-05.asm

📁 锂电保护板源代码,采用ETA的MCU,,,,实现对锂电的管理
💻 ASM
📖 第 1 页 / 共 3 页
字号:
		INCLUDE  "ADAM42K.lib"
	
  	ADDATA_V0_0	EQU		00H
		ADDATA_V0_1	EQU		01H
		ADDATA_V0_2	EQU		02H
		
		ADDATA_V1_0	EQU		03H
		ADDATA_V1_1	EQU		04H
		ADDATA_V1_2	EQU		05H
		
		ADDATA_V2_0	EQU		06H
		ADDATA_V2_1	EQU		07H
		ADDATA_V2_2	EQU		08H
		
		ADDATA_V3_0	EQU		09H
		ADDATA_V3_1	EQU		0AH
		ADDATA_V3_2	EQU		0BH
		
		ADDATA_C0_0	EQU		0CH
		ADDATA_C0_1	EQU		0DH
		ADDATA_C0_2	EQU		0EH
		
		ADDATA_C1_0	EQU		0FH
		ADDATA_C1_1	EQU		010H
		ADDATA_C1_2	EQU		011H
		
		
		VOLTAGE_OVER_COUNT	EQU		012H
		
		VOLTAGE_OVER_FLAG	EQU		013H


		CURRENT_OVER_COUNT	EQU		014H
		
		CURRENT_OVER_FLAG	EQU		015H
		
		
		
		ADDATA_C3_1	EQU		016H
		ADDATA_C3_2	EQU		017H
		
		PWM_CONTROL_BAT0_0L EQU 018H
		PWM_CONTROL_BAT0_0H EQU 019H
		PWM_CONTROL_BAT0_1L EQU 01AH
		PWM_CONTROL_BAT0_1H EQU 01BH
		
		PWM_CONTROL_BAT1_0L EQU 01CH
		PWM_CONTROL_BAT1_0H EQU 01DH
		PWM_CONTROL_BAT1_1L EQU 01EH
		PWM_CONTROL_BAT1_1H EQU 01FH
				
		PWM_CONTROL_BAT2_0L EQU 020H
		PWM_CONTROL_BAT2_0H EQU 021H
		PWM_CONTROL_BAT2_1L EQU 022H
		PWM_CONTROL_BAT2_1H EQU 023H
		
		PWM_CONTROL_BAT3_0L EQU 024H
		PWM_CONTROL_BAT3_0H EQU 025H
		PWM_CONTROL_BAT3_1L EQU 026H
		PWM_CONTROL_BAT3_1H EQU 027H
		
		TIME1_MARK EQU 028H
		
		ADCHANGE_M_0 EQU 029H
		ADCHANGE_M_1 EQU 02AH
		ADCHANGE_M_2 EQU 02BH
		ADCHANGE_M_3 EQU 02CH
		
		ADCHANGE_COUNT_0 EQU 02DH
		
		PWM_STEPS_0 EQU 02EH
		PWM_STEPS_1 EQU 02FH
		PWM_STEPS_2 EQU 030H
		
		ADDATA_C_0 EQU 031H
		ADDATA_C_1 EQU 032H
		ADDATA_C_2 EQU 033H
		ADDATA_C_3 EQU 034H
				
		TIME_COUNTS_0 EQU 035H
		TIME_COUNTS_1 EQU 036H
		TIME_COUNTS_2 EQU 037H
		TIME_COUNTS_3 EQU 038H
		TIME_COUNTS_4 EQU 039H
		
		PWM_STEPS_C0_0 EQU 03AH
		PWM_STEPS_C0_1 EQU 03BH
		PWM_STEPS_C0_2 EQU 03CH
		
		PWM_STEPS_C1_0 EQU 03DH
		PWM_STEPS_C1_1 EQU 03EH
		PWM_STEPS_C1_2 EQU 03FH
		
		PWM_STEPS_C2_0 EQU 040H
		PWM_STEPS_C2_1 EQU 041H
		PWM_STEPS_C2_2 EQU 042H
		
		PWM_STEPS_C3_0 EQU 043H
		PWM_STEPS_C3_1 EQU 044H
		PWM_STEPS_C3_2 EQU 045H
		
		DELAY0 EQU 046H
		DELAY1 EQU 047H
		DELAY2 EQU 048H
		DELAY3 EQU 049H
		DELAY4 EQU 04AH
		
		FLASH_0 EQU 04BH
		FLASH_1 EQU 04CH
		FLASH_OUT EQU 04DH		

		BAT_TEST EQU 04EH
		
		ELECT_OUT0_0 EQU 04FH 
		ELECT_OUT0_1 EQU 050H
		
		ELECT_OUT1_0 EQU 051H
		ELECT_OUT1_1 EQU 052H
		
		ELECT_OUT2_0 EQU 053H
		ELECT_OUT2_1 EQU 054H
		
		ELECT_OUT3_0 EQU 055H
		ELECT_OUT3_1 EQU 056H
		
		ELECT_END_0 EQU 057H
		ELECT_END_1 EQU 058H
		ELECT_END_2 EQU 059H
		ELECT_END_3 EQU 05AH
		
;=========================================================================
;-----------------------interrupt vectors table.--------------------------
;=========================================================================

		      ;ORG			0000H
					WDTC
					BR				!RESET
					WDTC
					BR				!RESET
					WDTC
					BR				!RESET
					WDTC
					BR				!RESET
					LDM				TIME1_MARK,#1111B		;timer1 overflow ,and make the define ram to a special data.
					RETI
					WDTC
					BR				!RESET
					WDTC
					BR				!RESET
					WDTC
					BR				!RESET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

RESET:
					DI
					SPC
					WDTC
					CALL !INI_IC_PORT_CONFIGURATION ;initialize the configuration of the MCU. 
					CALL !CL_RAM                    ;clear the ram of the MCU.
					EI
					LDM PWM_STEPS_0,#05H
					LDM PWM_STEPS_1,#05H
					LDM PWM_STEPS_2,#00H
					
				  LDM PWM_STEPS_C0_0,#05H 
					LDM PWM_STEPS_C0_1,#05H 
					LDM PWM_STEPS_C0_2,#00H 
		
					LDM PWM_STEPS_C1_0,#05H 
					LDM PWM_STEPS_C1_1,#05H 
					LDM PWM_STEPS_C1_2,#00H 
		
					LDM PWM_STEPS_C2_0,#05H 
					LDM PWM_STEPS_C2_1,#05H 
					LDM PWM_STEPS_C2_2,#00H 
		
					LDM PWM_STEPS_C3_0,#05H 
					LDM PWM_STEPS_C3_1,#05H 
					LDM PWM_STEPS_C3_2,#00H 
					
					
					LDM FLASH_0,#00H
		      LDM FLASH_1,#00H
		      
		      CALL !_DELAY
		      
;=========================================================================================;										
;                        THE MAIN PROGRAM FOR THE PROJECT.                                ;					
;					                                                                                ;
;=========================================================================================;										                            

MAIN:			
					
					WDTC    ;watch dog timer reset
					
					NOP
					NOP
					NOP
					NOP
					NOP
					CALL !BAT_0_ELECT
					
					CALL !BAT_0_PWM_ELECT		
					
					
					CALL !IF_ALL_CHARGE_END							
					
					NOP
					NOP
					NOP
										
					
					NOP
					NOP
					NOP
					CALL !DELAY
					
					CALL !DELAY
					NOP
					NOP
					NOP
					;CALL !DELAY
					
					
					NOP
					NOP
					NOP
					NOP
					NOP
							
					BR !MAIN
				
;=========================================================================================
;--------------clear the ram_map of the mcu.----------------------------------------------					
;=========================================================================================					

CL_RAM:		
					LDX				#0
					LDY				#0
CL_R_L:		EIX
					LDM				00H,#0
					DIX
					ADDC			Y,#1
					CYNE			#0
					BR				!CL_R_L
					WDTC
					ADDC			X,#0
					CXNE			#0
					BR				!CL_R_L
					RET
										
;=========================================================================================
;-------------------------initialize the I/O port of the mcu.------------------------------
;=========================================================================================

INI_IC_PORT_CONFIGURATION:
					
;--------- R1 port configuration	

		LRI	R1ST,#1111B		; R1 All port STOP-release disable.
		LRI	R1PC,#1111B		; R1 All port Pull-up disable.
		LRI	R1OD,#1011B		; R1 All port push-pull output.because the R11 is only open-drain output,
		                  ; the R11 must external push-pull resistance.
		LRI	R1DD,#1011B		; R1 All port output state.
		LRI	R1DR,#0000B		; the bat0 and bat1 is closed.
    
    LRI TOPSR,#0001B		; R13,R12,PB2 is using in I/O,PG0 IS USE IN PWM OUTPUT MODE.. 
    
    			;R13 -> the led flash 
    			;R10 -> no use
    			;R11 -> system reset input
    			;R12 -> the battery voltage A/D change

;--------- PB port configuration

		LRI	EIPSR,#0000B	; R10,PG2,PG1,PB0 general IO using.
		LRI	PBST,#1111B		; PB All port STOP-release disable.
		LRI	PBPC,#1111B		; PB All port Pull-up disable 
		LRI	PBOD,#1111B		; PB all port push-pull output
		LRI	PBDR,#1111B		; all led is close,"0" is open,"1" is close.
			
		LRI	PBDD,#1111B		; PB all port is output state

		LRI APSR2,#1011B  ;R12 and PH2 is using in I/O,PH1 and PH0 is using in A/D mode.

					;PB0~PB3 -> no use

;--------- PC port configuration

		LRI	PCOD,#0001B		; PC open-drain output,PC0 is push-pull putput.
		LRI	PCDR,#0000B		; PC All port low out/the bat3 is close.
					;PC0 -> no use
					
;--------- PG port configuration

		LRI	ADCIS,#0001B
		LRI	APSR1,#1110B	; PG1~PG3 is using in A/D mode,PG0 is use in pwm output.
		
		LRI	PGST,#1111B
		LRI	PGOD,#0001B		; PG Push-pull output state.
		LRI	PGPC,#1111B		; PG All port Pull-up disable 
		LRI	PGDD,#0001B		; port is input state.
		LRI	PGDR,#0000B		
					; PG0 -> the pwm sign output
					; PG1 -> the bat current A/D change.
					; PG2 -> the voltage of the power A/D change.
					; PG3 -> no use
									
;--------- PH port configuration

		LRI	APSR2,#1011B	; PH0~PH1 is using in  A/D mode.
		
		LRI	PHOD,#1100B		; PH1,PH0 push-pull,PH2,PH3 is push-pull output state.
		LRI	PHPC,#1111B		; PH All port pull-up disable.
		LRI	PHDD,#0100B		; port is input state. PH2 is output state.
		LRI	PHDR,#0000B		;     
					
					; PH0 -> no use
					; PH1 -> no use
					; PH2 -> no use
					; PH3 -> no use

;--------- Timer0 setup		

		LRI	T0D1H,#00H		; 
		LRI	T0D1L,#01H		; 
		LRI	T0D0H,#04H		; 
		LRI	T0D0L,#05H		; 
					; 
		LRI	T0MR,#1100B		; PWM source clock : PS1(250ns@8M)
		LRI RCR,#1010B		;ROUT is "H" when TODOL and TODOH is count,then is "L" when TOD1L and TOD1H is count~
    
    
    
    LRI T01MR,#0000B  ;PWMS IS  SELETION ON ROUT(IT MUST BE "0",OTHERWISE IT WILL NO OUTPUT)
;--------- CG Timer setup(PWM out) ->  for Timer1 source

		LRI	CGHMD,#3		; 100x0.25=25us
		LRI	CGHLD,#2
		LRI	CGLMD,#3
		LRI	CGLLD,#2	
		LRI	CGMR,#1000B
		LRI	RCR,#1010B

; -------- Timer1 setup

		LRI	T1HD,#1100B
		LRI	T1LD,#1000B		; 200x25=5000us
		LRI	T1MR,#1111B		;

;--------- Timer1 interrupt configuration	

		LRI	IEDS,#0000B		; Ext Int2 disable.				
		LRI	IENR,#1000B		; Timer1 Interrupt setup. 
		LRI	IRQR,#0000B		; All Interrupt request clear.
		LRI	IENR2,#0000B	; LVI interrupt setup.
		LRI	IRQR2,#0000B
		
;--------- ADC setup------------------------------------------------------------------------------------
	
		LRI	ADCM,#0101B		; ADC enable
		LRI	WACR,#1000B		; initialize the watch dog and the mode of A/D,16US WDT INPUT CLOCK ,ADC clock is PS1.
		RET					

;=======================================================================================================
;-------------------the pwm control for bat_0 and lasting control the voltage charging -----------------
;=======================================================================================================

BAT_0_PWM_ELECT:

;--------------------------if the current flag is "0FH",then the charging is ending----------------------
		CMNE CURRENT_OVER_FLAG,#00H
		BR !END_OF_ALL_CHARGE_1
					
;-----------------FLASH THE LED---------------------------------------		
		CLRC 
		ADDC FLASH_0,#0001B
		LDM FLASH_0,A
		
		ADDC FLASH_1,#0000B
		LDM FLASH_1,A

		CMNE FLASH_0,#04H
		BR !FLASH_END
		
		CMNE FLASH_1,#06H
		BR !FLASH_END
		
		LDM FLASH_0,#0H
		LDM FLASH_1,#0H		
		LDM FLASH_OUT,#1000B
		
;---------------"XOR" the output state--------------------------------
		LAR R1DR
		XOR FLASH_OUT
		LRA R1DR
		
FLASH_END:

;----------------------read the voltage for judge that if the voltage is over 4.2V------------------------------------------
		LRI ADCIS,#0111B
		
		LDM ADCHANGE_M_0,#0000B
		LDM ADCHANGE_M_1,#0000B
		LDM ADCHANGE_M_2,#0000B
		LDM ADCHANGE_M_3,#0000B
	
		CALL !AD_CHANGE
		
;-----save the result of A/D for bat_V_1.-----

		LDA ADCHANGE_M_1
		LDM ADDATA_V1_0,A
		
		LDA ADCHANGE_M_2
		LDM ADDATA_V1_1,A
		
		LDA ADCHANGE_M_3
		LDM ADDATA_V1_2,A 
		WDTC

;------------------judge the flag of voltage,if "0FH",than enter the mode of lasting voltage charging,
;-------------------------and if "00H",than enter the mode of lasting current charging--------------------		
		CMNE VOLTAGE_OVER_FLAG,#00H
		BR !LASTING_VOLTAGE_CHARGE_0
		
;-------------------judge the voltage of the battery is over 4.2V or not---------------------------		
		CMLE ADDATA_V1_2,#03H
		BR !VOLTAGE_0
		BR !OVER_0
		
VOLTAGE_0:
		CMNE ADDATA_V1_2,#03H		
		BR !NOT_OVER_0
		
		CMLE ADDATA_V1_1,#0BH
		BR !VOLTAGE_1
		BR !OVER_0
		
VOLTAGE_1:		
		CMNE ADDATA_V1_1,#0BH		
		BR !NOT_OVER_0
		
		CMLE ADDATA_V1_0,#00H
		BR !VOLTAGE_2
		BR !OVER_0
		
VOLTAGE_2:
		CMNE ADDATA_V1_0,#00H
		BR !NOT_OVER_0
		BR !OVER_0

;-------------if the voltage is not over 4.2V,and redue the count,because when the count is reach to 16 times,---------
;----------------------that will set the flag to ensure the mode of lasting voltage charging---------------------------				
NOT_OVER_0:

    CMNE VOLTAGE_OVER_COUNT,#00H
    BR !REDUCE_0
		BR !NOT_REDUCE_0
		
REDUCE_0:
    CLRC
    SUBC VOLTAGE_OVER_COUNT,#01H
    LDM VOLTAGE_OVER_COUNT,A
    
NOT_REDUCE_0:
    BR !IF_OVER_0    

;----------------if the voltage is over 4.2V,and increase the count,and when the count is reach to 16 times,
;-----------------------that will set the flag to ensure the mode of lasting voltage charging---------------------------
OVER_0:		
		
		CMNE VOLTAGE_OVER_COUNT,#0FH
		BR !INCR_0		
		BR !IF_OVER_0
		
INCR_0:
   CLRC
   ADDC VOLTAGE_OVER_COUNT,#01H
   LDM VOLTAGE_OVER_COUNT,A
;-------------------judge the count for set the flag "00H" or "0FH"-------------------------
IF_OVER_0:		
		
		CMNE VOLTAGE_OVER_COUNT,#0FH
		BR !IT_IS_NOT_OVER
		
;------------------is reach to 16 times,than set the flag is "0FH"--------------------------
		LDM VOLTAGE_OVER_FLAG,#0FH
					
		BR !LASTING_VOLTAGE_CHARGE_0

;----------is not reach to 16 times,than set the flag is "00H"---------------------------

IT_IS_NOT_OVER:		

		LDM VOLTAGE_OVER_FLAG,#00H
		

TEST_VOLTAGE_END:		
		BR !LASTING_CURRENT_CHARGE_0
		
;----------------------lasting voltage charging ,if the voltage is over 4.2V(base the voltage of the battery)-----------------
;----------------------------this function is be to change the pwm for the lasting voltage charging---------------------------
LASTING_VOLTAGE_CHARGE_0:		
		
		
		LDA PWM_STEPS_C0_0
		LDM PWM_STEPS_0,A
		
		LDA PWM_STEPS_C0_1                   ; 
		LDM PWM_STEPS_1,A                    ;  
		
		LDA PWM_STEPS_C0_2
		LDM PWM_STEPS_2,A
			
		NOP
		NOP
		NOP
		NOP
		NOP
		CALL !PWM_DATA_DEAL_1
		
		LDA PWM_STEPS_0
		LDM PWM_STEPS_C0_0,A
		
		LDA PWM_STEPS_1                     ;
		LDM PWM_STEPS_C0_1,A
		
		LDA PWM_STEPS_2
		LDM PWM_STEPS_C0_2,A



    LRI RCR,#1000B
		CLRR1 T0MR.#3
		
		LAR DBR0
		LDM PWM_CONTROL_BAT0_0L,A
		LRA T0D0L
		LAR DBR1
		LDM PWM_CONTROL_BAT0_0H,A
		LRA T0D0H
		LAR DBR2
		LDM PWM_CONTROL_BAT0_1L,A
		LRA T0D1L
		LAR DBR3
		LDM PWM_CONTROL_BAT0_1H,A
		LRA T0D1H		
		
		LRI RCR,#1010B
		SETR1 T0MR.#3



LASTING_CURRENT_CHARGE_0:
	
END_OF_ALL_CHARGE_1:		
		RET

;----------------------------------------------------------------------------------------------
;----------the pwm control for bat_0 and lasting control the current charging -----------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -