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

📄 subroutine.asm

📁 本装置是一个以HT46R71D 为主芯片
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;******************File Name: Subroutine.Asm******************
;;---------------------------------------------------------
INI_RAM:		;;initial ram 
;;---------------------------------------------------------
	CLR		BP
	XMOV	MP0,		0A0H
	CLR		WDT
	CLR		R0
	INC		MP0
	EJMP	MP0,		0BFH			;;clear bank0 ram(20~3FH)
	JMP		$-6

	XMOV	BP,			01H
	XMOV	MP1,		0C0H
	CLR		WDT 
	CLR		R1
	INC		MP1 
	EJMP	MP1,		0CFH			;;clear bank1 ram(40~4FH)
	JMP		$-6                           
	
	CLR		INTC0						;;interrupt disable 
	CLR		INTC1
	XMOV	CHPRC,		63H				;;set 3.3V regular output
	XMOV	ADCR,		41H				;;set the related registor
	XMOV	ADCD,		07H
	XMOV	TMR1C,		88H			
	XMOV	R_UNIT,		01H
	RET
;;---------------------------------------------------------
INI_IO:									;;initial IO port
;;---------------------------------------------------------
	CLR		WDT
	SET		PAC
	SET		PBC
	CLR		LED_IO_C
	SET		LED_IO
	RET
;;---------------------------------------------------------
SBR_ADC:								
;;test the discharge time Tc during the charge time Ti be fixed
;;--------------------------------------------------------
	CLR		TMR1C.4
	XMOV	TMR0C,		8FH				;;32us(Fsys=4MHz)
	
	XMOV	TMR0,		00H
	XMOV	ADCR,		01001011B		;;at charge mode
	SET		TMR0C.4
	CLR		WDT
	SNZ		T0F							;;charge and let Vc work over 4/6 VDSO 
	JMP		$-2
	CLR		T0F

	CLR		TMR0C.4
	XMOV	ADCR,		01001101B		;;at discharge mode
	CLR		WDT
	SZ		ADCMPO						
	JMP		$-2

	XMOV	TMR0,		83H				

SBR_ADC_LOOP:
	CLR		WDT
	MOV		A,			00000110B		;;at charge mode
	XORM	A,			ADCR		
	SET		TMR0C.4	
	CLR		TMR1C.4
	CLR		TMR1L
	CLR		TMR1H

	CLR		WDT
	SNZ		T0F							;;charge for 3968 S
	JMP		$-2

	MOV		A,			00000110b		;;at discharge mode
	XORM	A,			ADCR	
	SET		TMR1C.4	
	CLR		TMR0C.4
	CLR		T0F								
	CLR		WDT
	SZ		ADCMPO						;;discharge
	JMP		$-2	
	
	CLR		TMR1C.4
	XMOV	R_TMR1H,	TMR1H
	XMOV	R_TMR1L,	TMR1L			;;save discharge time 
	RET
;----------------------------------------------------------
SBR_TABLE:								
;;get the opposite offset address of table with dichotomy 
;----------------------------------------------------------
	CLR		WDT
	CLR		BP
	XMOV	R_ADDR1,	LOW TABLE_START_ADDR	
										;;save the V-T table start address 
	XMOV	R_ADDR2,	LOW TABLE_START_ADDR+TABLE_NUM-1
										;;save the V-T table end address
	XMOV	TBLP,		R_ADDR1			
	TABRDL	R_TABLE1_L	
	XMOV	R_TABLE1_H,	TBLH			;;get value of the start address 	
	XMOV	TBLP,		R_ADDR2		
	TABRDL	R_TABLE2_L	
	XMOV	R_TABLE2_H,	TBLH			;;get value of the end address
	EJMP	R_TABLE1_H,	R_TMR1H			;;if discharge time(Tc)=table value of start address			
	JMP		$+6							;;unequal	
	LBRJ	R_TABLE1_L,	R_TMR1L					
	JMP		L_RET1						;;Tc>the table value of start address
	JMP		SBR_TABLE_LOOP				
	LBRJ	R_TABLE1_H,	R_TMR1H				
	JMP		L_RET1						;;Tc>the table value of start address
	
	EJMP	R_TABLE2_H,	R_TMR1H			;;if discharge time(Tc)=table value of end address			
	JMP		$+6
	LBRJ	R_TMR1L,	R_TABLE2_L		
	JMP		L_RET2						;;Tc<the table value of end address
	JMP		SBR_TABLE_LOOP
	LBRJ	R_TMR1H,	R_TABLE2_H
	JMP		L_RET2						;;Tc<the table value of end address
	
SBR_TABLE_LOOP:							;;at the testing range of sensor
	CLR		WDT
	MOV		A,			R_ADDR2
	SUB		A,			R_ADDR1
	CLR		C
	RRC		ACC
	SZ		ACC
	JMP		$+2
	JMP		L_RET_LOOP
	ADD		A,			R_ADDR1			
	MOV		TBLP,		A		
	TABRDL	R_TABLE_L					;;get the middle address between addr1 and addr2
										;;and save the table value to R_TALBE_L
L_COMPARE_H:							;;compare the high byte of Tc with table value
	NEJMP	TBLH,	R_TMR1H				
	JMP		L_COMPARE_L	
	CLR		F_TABLE_EQU
	LBRJ	TBLH,	R_TMR1H
	JMP		L_BIGGER
	JMP		L_SMALLER
L_COMPARE_L:							;;compare the low byte of Tc with table value
	EJMP	R_TABLE_L,	R_TMR1L			
	JMP		$+3
	SET		F_TABLE_EQU					
	JMP		L_EQU
	LBRJ	R_TABLE_L,	R_TMR1L
	JMP		L_BIGGER
	JMP		L_SMALLER
	
L_BIGGER:								;;Tc > table value
	XMOV	R_ADDR2,	TBLP
	XMOV	R_TABLE2_L,	R_TABLE_L
	XMOV	R_TABLE2_H,	TBLH	
	JMP		SBR_TABLE_LOOP	
L_SMALLER:								;;Tc < table value
	XMOV	R_ADDR1,	TBLP	
	XMOV	R_TABLE1_L,	R_TABLE_L
	XMOV	R_TABLE1_H,	TBLH	
	JMP		SBR_TABLE_LOOP
L_EQU:									;;Tc = table value	
	SNZ		F_TABLE_EQU
	JMP		$+3
	XMOV	R_ADDR1,	TBLP
	JMP		L_RET_LOOP
L_RET1:									;;zero output of the sensor
	CLR		F_KEY_TMP
	SET		F_ZERO_OUTPUT
	SNZ		F_ON
	RET
	CLR		F_ON
	CLR		R_ADJUST_L
	XMOV	R_ADJUST_H,		R_ADDR1		;;set the adjust value
	RET	

L_RET2:									;;full output of the sensor
	XMOV	R_ADDR1,		LOW TABLE_START_ADDR+TABLE_NUM-1
	CLR		F_KEY_TMP
	SET		F_FULL_OUTPUT
	SNZ		F_ON
	RET
	CLR		F_ON
	CLR		R_ADJUST_L
	XMOV	R_ADJUST_H,		LOW TABLE_START_ADDR+TABLE_NUM-1
	RET									;;set the adjust value
	
L_RET_LOOP:
	CLR		F_ZERO_OUTPUT
	CLR		F_FULL_OUTPUT
	CLR		F_KEY_TMP
	RET
;;---------------------------------------------------------
SBR_CALT:								
;;calculate pressure with different unit 
;;---------------------------------------------------------
	CLR		WDT
	SZ		F_ZERO_OUTPUT				
	JMP		L_CALT_LOOP4				;;for zero output of sensor
	SNZ		F_FULL_OUTPUT				
	JMP		$+8
	MOV		A,			R_ADDR1			;;for full output of sensor
	SUB		A,			R_ADJUST_H
	MOV		R_ADDR1,	A
	CLR		R_TEMP0
	CLR		R_TEMP1
	CLR		R_TEMP2
	JMP		L_CALT_LOOP5

	MOV		A,			R_TABLE1_L		
	SUB		A,			R_TMR1L
	MOV		DATA0,		A	
	MOV		A,			R_TABLE1_H
	SBC		A,			R_TMR1H
	MOV		DATA1,		A
	CLR		DATA2
	XMOV	DATA4,		100
	CLR		DATA5	
	CLR		DATA6
	CALL	UNBIN_MUL_24				;;{[R_TABLE1_H,R_TABLE1_L] - [R_TMR1_H,R_TMR1_L}*100
	
	XMOV	DATA0,		TO0
	XMOV	DATA1,		TO1
	XMOV	DATA2,		TO2
		
	MOV		A,			R_TABLE1_L
	SUB		A,			R_TABLE2_L
	MOV		DATA4,		A
	MOV		A,			R_TABLE1_H
	SBC		A,			R_TABLE2_H
	MOV		DATA5,		A
	CLR		DATA6
	CALL	UNBIN_DIV_24				;;{[R_TABLE1_H,R_TABLE1_L] - [R_TMR1_H,R_TMR1_L}*100/(R_TABLE1-R_TABLE2)
										;;and get two bits of (decimal*100)
	
	SZ		F_ON						;;if power on/wake up
	JMP		L_INI
	JMP		L_CALT_LOOP1
L_INI:									;;get the adjust value
	CLR		F_ON
	XMOV	R_ADJUST_L,	TO0
	XMOV	R_ADJUST_H,	R_ADDR1
	 
L_CALT_LOOP1:							;;calculate pressure with different unit
	SET		C
	MOV		A,			TO0
	SUB		A,			R_ADJUST_L		;;adjust
	MOV		DATA0,		A

	SZ		C
	JMP		L_CALT_LOOP3				
	SET		C							;;TO0<R_ADJUST_L
	MOV		A,			R_ADDR1
	SUB		A,			R_ADJUST_H		
	SNZ		C							;;if R_ADDR1 is bigger than R_ADJUST_H or not
	JMP		L_CALT_LOOP4				;;not
	SZ		ACC							;;if R_ADDR1-R_ADJUST_H>1?
	JMP		$+2
	JMP		L_CALT_LOOP4				;;not
	DEC		R_ADDR1						;;because 'TO0<R_ADJUST_L'

L_CALT_LOOP3:							;;TO0>R_ADJUST_L
	SET		C
	MOV		A,			R_ADDR1
	SUB		A,			R_ADJUST_H		
	SNZ		C							
	JMP		L_CALT_LOOP4				;;R_ADDR1<R_ADJUST_H
	MOV		R_ADDR1,		A			;;R_ADDR1>R_ADJUST_L
	JMP		L_CALT_LOOP2
L_CALT_LOOP4:							;;for zero output of sensor		
	CLR		R_LCD1						;;to display 0.00
	CLR		R_LCD2
	CLR		R_LCD3
	SET		F_LCD_DOT1
	CLR		F_LCD_DOT2
	RET									

L_CALT_LOOP2:											
	CLR		DATA1
	CLR		DATA2
	CALL	SBR_CALT_LOOP
	CALL	UNBIN_MUL_24				;;decimal*100*[psi/bar/kpa/kgfcm2_full]
		
	XMOV	DATA0,		TO0
	XMOV	DATA1,		TO1
	XMOV	DATA2,		TO2
	XMOV	DATA4,		100
	CLR		DATA5
	CLR		DATA6
	CALL	UNBIN_DIV_24				;;decimal*[psi/bar/kpa/kgfcm2_full]

	XMOV	R_TEMP0,	TO0
	XMOV	R_TEMP1,	TO1
	XMOV	R_TEMP2,	TO2

L_CALT_LOOP5:							
	XMOV	DATA0,		R_ADDR1                            
	CLR		DATA1
	CLR		DATA2
	CALL	SBR_CALT_LOOP
	CALL	UNBIN_MUL_24				;;integer*[psi/bar/kpa/kgfcm2_full]
	
	XADDM	R_TEMP0,	TO0
	XMOV	DATA0,		R_TEMP0
	XADCM	R_TEMP1,	TO1
	XMOV	DATA1,		R_TEMP1
	XADCM	R_TEMP2,	TO2
	XMOV	DATA2,		R_TEMP2			;;(decimal+integer)*[psi/bar/kpa/kgfcm2_full] and save
	
	XMOV	DATA4,		PER
	CLR		DATA5
	CLR		DATA6
	CALL	UNBIN_DIV_24  				;;/100
	XMOV	DATA0,		TO0
	XMOV	DATA1,		TO1
	XMOV	DATA2,		TO2
	XMOV	DATA4,		TABLE_PER		;;/TABLE_PER
	CLR		DATA5
	CLR		DATA6
	CALL	UNBIN_DIV_24
			
	XMOV	R_TO0,		TO0
	XMOV	R_TO1,		TO1

	MOV		A,			R_TO0			;;>999?
	SUB		A,			LOW 999
	XMOV	TO1,		HIGH 999
	MOV		A,			R_TO1
	SBC		A,			TO1
	SZ		C
	JMP		L_OVER_999

	MOV		A,			R_TO0
	SUB		A,			100				;;<999 & >100?
	MOV		A,			R_TO1
	CLR		TO1
	SBC		A,			TO1
	SZ		C
	JMP		L_OVER_100

	MOV		A,			R_TO0			;;<100 & >10?
	SUB		A,			10
	MOV		A,			R_TO1
	CLR		TO1
	SBC		A,			TO1
	SZ		C
	JMP		L_OVER_10

	SZ		R_TO0						;;<10 & >1?
	JMP		L_OVER_1
	SZ		R_TO1
	JMP		L_OVER_1
	
	SET		F_LCD_DOT1					;;<1
	CLR		F_LCD_DOT2
	CLR		R_LCD1						;;0.@@
	XMOV	DATA0,		R_TEMP0
	XMOV	DATA1,		R_TEMP1
	XMOV	DATA2,		R_TEMP2
	JMP		L_DEAL_LOOP1

L_OVER_1:								;;>1 & <10
	SET		F_LCD_DOT1
	CLR		F_LCD_DOT2					;;@.@@
	XMOV	DATA0,		R_TEMP0
	XMOV	DATA1,		R_TEMP1
	XMOV	DATA2,		R_TEMP2
	JMP		L_DEAL_LOOP1

L_OVER_10:								;;>10 & <100
	CLR		F_LCD_DOT1					;;@@.@
	SET		F_LCD_DOT2
	XMOV	DATA0,		R_TEMP0	
	XMOV	DATA1,		R_TEMP1
	XMOV	DATA2,		R_TEMP2
	XMOV	DATA4,		10
	CLR		DATA5
	CLR		DATA6
	CALL	UNBIN_DIV_24				
	XMOV	DATA0,		TO0
	XMOV	DATA1,		TO1
	XMOV	DATA2,		TO2
	JMP		L_DEAL_LOOP1
		
L_OVER_100:								;;>100
	CLR		F_LCD_DOT1
	CLR		F_LCD_DOT2					;;@@@
	XMOV	DATA0,		R_TO0			
	XMOV	DATA1,		R_TO1
	JMP		L_DEAL_LOOP2

L_OVER_999:								;;>999
	CLR		F_LCD_DOT1
	CLR		F_LCD_DOT2					;;---
	XMOV	R_LCD3,		10
	MOV		R_LCD2,		A
	MOV		R_LCD1,		A
	RET

L_DEAL_LOOP1:
	CLR		WDT
	XMOV	DATA4,		TABLE_PER				
	CLR		DATA5
	CLR		DATA6
	CALL	UNBIN_DIV_24				;;/TABLE_PER
	XMOV	DATA0,		TO0
	XMOV	DATA1,		TO1

⌨️ 快捷键说明

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