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

📄 samtestc.src.bak

📁 用SAM72N9写的电子秤文档
💻 BAK
📖 第 1 页 / 共 5 页
字号:
	BTSF	STOPCNT_PIN	; Loop until STOPCNT_PIN is low
	JR	ADInit_1	;
;-----^ ------------------------------ ^-----

ADInit_2
	REF	RSMB_LCD 	;
	BITR	DISCHARGE_PIN	; Set Charging when STOPCNT_PIN is high
ADInit_3
	CALLS	ChkADInitErr	;
	CALLS	ChkOffButton	;
;-----v Remark to bypass A/D circuitry v-----
	REF	RSMB_MemMapIO	;
	BTST	STOPCNT_PIN	; Loop until STOPCNT_PIN is high
	JR	ADInit_3	;
;-----^ ------------------------------ ^-----

ADInit_6
	REF	RSMB_Variable	;
	LD	EA,#DischargeDelay
	LD	CntTCNT,EA	; Reload CntTCNT
	BITR	CntPeriodNow	;

	REF	RSMB_MemMapIO	;
 	BITS	TCRESTART	; Clear TCNT0, IRQT0 & TOL0 & resume counting immediately
	BITS	IET0		; Enable Timer/Counter Interrupt Request(INTT0)

	BITR	IRQ0		; Clear INT0 Interrupt Request Flag
	BITS	IE0		; Enable INT0 pin Interrupt

	REF	RSMB_LCD 	;
	BITS	KEYROW1_PIN	; Turn off keymap row 1

	REF	RSMB_Variable	;
	RET

ChkADInitErr
	REF	RSMB_Variable	;
	LD	EA,SleepTimL	; compare low byte only, 
	LD	HL,#Idle1minL_RL+10
	SBS	HL,EA		; check 10s timeout?
	RET			; if more than 10s can't init A/D,
SetADInitErr
		
	LD	EA,#Idle1minL_RL	;
	LD	SleepTimL,EA	; reload 1 min sleep low byte 
	LD	SleepTimLRL,EA	;
	
	LD	A,#IdleminH_RL	;
	LD	SleepTimH,A	; reload 1 min sleep high nibble
	LD	SleepTimHRL,A	;

	CALLS	ADStop		;
	CALLS	DspADInitErr	;
	REF	RSMB_LCD 	;
	BITR	KEYROW1_PIN	; Turn on keymap row 1
	REF	RSMB_Variable	;
ChkADInitErr1
	CALLS	Dly2		; 20ms delay
	CALLS	ChkOffButton	;
	JR	ChkADInitErr1	; Dead loop until "Off" is pressed

;***********************************************************
;	F: Stop A/D Convertor (include INT0 int, INTT0 int)
;	O: SMB = Variable_Bank
;	N: If STOPCNT_PIN(Pt C on sch.) is high,
;	   set DISCHARGE_PIN(Pt A on sch.) to high and vice versa.
;
ADStop	REF	RSMB_MemMapIO	;
	BITR	IET0		; Disable Timer/Counter Interrupt Request(INTT0)
	BITR	IRQT0		; Clear Timer/Counter Request Flag
	BITR	IE0		; Disable INT0 pin Interrupt
	BITR	IRQ0		; Clear INT0 Interrupt Request Flag
	REF	RSMB_LCD	;
	BITR	DISCHARGE_PIN	;
	REF	RSMB_Variable	;
	RET

;***********************************************************
;	F: Take Zero Point
;	O: ZeroCount, ZeroBound, DspWeightCnt, NewWeightCnt
;	N: Take 2 samples & compare;
;	   If difference is less than 10 counts, accept Zero point
ReadZero
ReadZero_1
	CALLS	ChkADInitErr	;
	BTST	HaveSample0	; Got 2 Samples?
	JR	ReadZero_1	;
	BTST	HaveSample1	;
	JR	ReadZero_1	;
	REF	RAverageSample	;

	LD	HL,#HexBuf
	REF	RGetAverageCnt	; Take 1st Zero Reading

ReadZero_2
ReadZero_3
	CALLS	ChkADInitErr	;
	BTSF	CntOvrflow	;
	JPS	SetADInitErr	; if CntOvrflow set, jump to A/D Init Error

	CALLS	Dly1		; Tricky statement ???? - if missing this delay
				; the sample count is wrong & thus, the zero
				; is wrong.
	BTST	HaveSample0	; Got 2 Samples?
	JR	ReadZero_3	;
	BTST	HaveSample1	;
	JR	ReadZero_3	;
	REF	RAverageSample	;

	LD	HL,#ZeroCount
	REF	RGetAverageCnt

	LD	HL,#ZeroCount	; if difference between 2 samples
	LD	WX,#HexBuf	; larger than 10count, take sample
	REF	RCmpHex		; again.
	JR	ReadZero_5	;
	RCF			;
	LD	EA,ZeroCount+2	;
	REF	RLD_HLEA	;
	LD	EA,HexBuf+2	;
	SBS	EA,HL		;
	JPS	ReadZero_8	;
	JR	ReadZero_7	; Take again
ReadZero_5			;
	LD	EA,HexBuf+2	;
	REF	RLD_HLEA	;
	LD	EA,ZeroCount+2	;
	SBS	EA,HL		;
	JR	ReadZero_8	;

ReadZero_7
	LD	EA,ZeroCount+2	; Store ZeroCount to HexBuf
	LD	HexBuf+2,EA	; and then take zero again
	LD	EA,ZeroCount	;
	LD	HexBuf,EA	;
	JPS	ReadZero_2	;

ReadZero_8
	LD	HL,#TolerantZero;
	SBS	EA,HL		; More than 10count difference
	JR	ReadZero_7	; Take again
	REF	RSetBnd		;
	REF	RCalWeightCnt	;
	
	LD	EA,ZeroCount+2	; ZeroCount ---> StartZero
	LD	StartZero+2,EA
	LD	EA,ZeroCount
	LD	StartZero,EA

	BITS	ZeroRdNow	; Update OperFlg8      
	 
	; add the instruction by hcy 03-11-19 9:39
	; remark by hcy 03-12-9 16:04
;	bits	PermitSend      
	RET

;***********************************************************
;	F: Clear RAM(1e0..1f7, 020..0ef)
;	O: SMB = Variable Bank
ClearRAM
	CALL	ClearRAM1	; Clear LCD Ram

	REF	RSMB_Variable	; Select Variable

	LD	HL,#20H		; from 020h..0efh
RAMCL1	LD	A,#00h		; all fill 0
	LD	@HL,A		;
	INCS	HL		;
	LD	EA,#0efh	;
	REF	RCPSE_EAHL	;
	JR	RAMCL1		;
	RET
;-----------------------------------
ClearRAM1
	REF	RSMB_LCD 	; Select LCD Memory Bank1
	LD	HL,#0e0h	; from 1e0h .. 1f7h
RAMCL0	LD	A,#0h		; all fill 0
	LD	@HL,A		;
	INCS	HL		;
	LD	EA,#0f8h	;
	REF	RCPSE_EAHL	;
	JR	RAMCL0		;
	RET

;====== ARITHMETIC =================================================
;	F: 1 Nibble Multiplication
;	I: WX = Number 1 buf end pointer
;	   HL = Number 2 buf end pointer
;	   Y
;	   HexCalFlg = 1 : Use Hexadecimal calculation algorithm
;	               0 : Use Decimal calculation algorithm
;	O: @HL[] = @WX[] * Y
;	D: Y
;
Mul_1N	PUSH	EA
Mul_1N1	PUSH	HL
	PUSH	WX

	JPS	Mul_1N8

Mul_1N2	RCF
Mul_1N3	LD	A,@WX
	CALLS	AddA2HL
Mul_1N5	XCHD	A,@HL
	JR	Mul_1N6
	JR	Mul_1N7
Mul_1N6	DECS	X
	JR	Mul_1N3

Mul_1N7	POP	WX
	POP	HL
	JPS	Mul_1N1

Mul_1N8	DECS	Y
	JPS	Mul_1N2

Mul_1NE	REF	RRET_WXHLEA

;***********************************************************
;	F: 5-Digit Multiplication
;	I: YS_F_REG[] = Number 1
;	   YS_L_REG[] = Number 2
;	   HexCalFlg = 1 : Use Hexadecimal calculation algorithm
;	               0 : Use Decimal calculation algorithm
;	O: YS_R_REG[] = Multiple of Number 1 & 2
;	N: YS_R_REG[] = YS_F_REG[] * YS_L_REG[]
;	   No Overflow checking
;
Mul_YS	PUSH	EA
	PUSH	HL
	PUSH	WX
	PUSH	YZ

Mul_0	LD	HL,#YS_R_REG_4	;
Mul_1	LD	A,#0		; Clear all YS_R_REG
	XCHD	A,@HL		;
	JR	Mul_1		;

	LD	HL,#YS_L_REG_4	; 5 Digits multiple
Mul_2	LD	A,@HL		;
	REF	RCPSE_A0	;
	JR	Mul_4		;
Mul_3	DECS	L		;
	JR	Mul_2		;
Mul_E	REF	RRET_YZWXHLEA	;

Mul_4	LD	WX,#YS_F_REG_4	;
	LD	H,#((YS_R_REG_4 & 0F0h) / 16)
	LD	Y,A		;
	CALLS	Mul_1N		;
	LD	H,#((YS_L_REG_4 & 0F0h) / 16)
	JR	Mul_3		;

;***********************************************************
;	F: Multiplication 1byte x 4bit
;	I: EA = EA * Y
;	O: EA
;          C = 1: Overflow error
;	     = 0: Correct Result
;	N: Y <> 0
;
HexMul	PUSH	HL
	PUSH	YZ

	RCF
	LD	HL,#0
	DECS	Y
	JR	HexMul2
	JR	HexMul4

HexMul2	ADC	HL,EA
HexMul3	DECS	Y
	JR	HexMul2
HexMul4	LD	EA,HL

HexMulE	POP	YZ
	POP	HL
	RET

;***********************************************************
;	F: 5-Digit Addition
;	I: WL = Number 1 buf end pointer
;	   HL = Number 2 buf end pointer
;	   HexCalFlg = 1 : Use Hexadecimal calculation algorithm
;	               0 : Use Decimal calculation algorithm
;	O: HL = Result pointer
;
Add	PUSH	EA
	PUSH	HL

Add_1	RCF			; Clear carry flag
Add_2	LD	A,@WL		;
	CALLS	AddA2HL		;
Add_4	XCHD	A,@HL		; A <--> (HL),L <-- L - 1
	JR	Add_2		;

	REF	RRET_HLEA	;

;***********************************************************
;	F: Add digit array by 1 digit
;	I: HL = Array LSB pointer
;	   A = Digit to add
;	O: @HL
;	   EA, HL
;	D: HL, A
;
AddByLSB
	RCF			;
	JR	AddLSB2		;
AddLSB1	LD	A,#0		;
AddLSB2	CALLS	AddA2HL		;
	XCHD	A,@HL		;
	JR	AddLSB1		;
	RET

;***********************************************************
;	F: Double Array
;	I: HL = Array LSB pointer
;	O: @HL
;	   C = 1: Overflew
;	D: HL, A
;
Double_YS
	RCF			;
Dbl_YS1	LD	A,@HL		;
	CALLS	AddA2HL		;
	XCHD	A,@HL		;
	JR	Dbl_YS1		;
	RET

;***********************************************************
;	F: Add A and @HL with C
;	I: C, A, HL, HexCalFlg
;	O: A = Result
;	   C = overflow
;	N: HexCalFlg = 1, Hexadecimal addition
;	             = 0, Decimal addition
;
AddA2HL	BTST	HexCalFlg	;
	JR	AddA2HL_1	;
	ADC	A,@HL		; Hexadecimal addition
	RET
AddA2HL_1
	ADS	A,#6		; Decimal addition
	ADC	A,@HL		; If carry,skip next instruction
	ADS	A,#10		; This instruction have not skip function
	RET
;***********************************************************
;	F: 5-Digit Hexa-Decimal Division
;	I: YS_F_REG[] = Dividend
;	   YS_L_REG[] = Divisor
;	   HexCalFlg = 1 : Use Hexadecimal calculation algorithm
;	               0 : Use Decimal calculation algorithm
;	O: YS_F_REG[] = Quotient
;	   YS_R_REG[] = Remainder
;	N: YS_F_REG[] / YS_L_REG[] = YS_F_REG[]...YS_R_REG[]
;
Div_YS	PUSH	EA
	PUSH	HL
	PUSH	WX
	PUSH	YZ

	JPS	Div_8

Div_0	LD	HL,#YS_R_REG_4	;
Div_1	LD	A,#0		; Clear all YS_R_REG
	XCHD	A,@HL		;
	JR	Div_1		;
	LD	Z,#4		; 5 Digits division
Div_2	LD	HL,#YS_F_REG_4	; Shift YS_F_REG 1 digit right
	LD	A,#0		;
Div_3	XCHD	A,@HL		;
	JR	Div_3		; 0 --> (65),(65) --> (64),...,(61) --> (60)
				; (60) --> A
	LD	HL,#YS_R_REG_4	;
Div_4	XCHD	A,@HL		; A --> (85),(85) --> (84),...,(81) --> (80)
	JR	Div_4		; (80) --> A
Div_5	LD	WX,#YS_R_REG_4	;
	LD	HL,#YS_L_REG_4	;
	RCF			; Clear carry
Div_6	LD	A,@WL		; YS_R_REG <-- YS_R_REG - YS_L_REG
	BTST	HexCalFlg	;
	JR	Div_61		;
	SBC	A,@HL		;
	JR	Div_62		;

Div_61	SBC	A,@HL		;
	ADS	A,#0AH		; Decimal adjustment

Div_62	XCH	A,@WL		;
	DECS	L		;
	JR	Div_6		;
	BTST	C		; Check borrow
	JPS	Div_7		; Borrow is not generated
	LD	WX,#YS_L_REG_4	; Borrow is generated by subtraction
	LD	HL,#YS_R_REG_4	; YS_R_REG <-- YS_R_REG + YS_L_REG
	CALLS	Add		;
Div_64	DECS	Z		;
	JPS	Div_2		; Next digit selection
	LD	HL,#YS_F_REG	;

	REF	RRET_YZWXHLEA

Div_7	LD	HL,#YS_F_REG_4	;
	INCS	@HL		; Increment quotient by 1
	NOP			;
	JPS	Div_5		; and subtract until a borrow is generated

Div_8	LD	HL,#YS_L_REG_4	;
	LD	A,#0		;
Div_9	OR	A,@HL		;
	DECS	L		;
	JR	Div_9		;

	REF	RCPSE_A0	;
	JPS	Div_0		;

Div_ERR	REF	RRET_YZWXHLEA	; DIVIDE BY ZERO

;***********************************************************
;	F: Decimal Round off
;	I: YS_L_REG[] = Divisor
;	   YS_R_REG[] = Remainder
;	   HexCalFlg = 1 : Use Hexadecimal calculation algorithm
;	               0 : Use Decimal calculation algorithm
;	O: YS_F_REG[] = Quotient
;
Round_YS
	PUSH	EA
	PUSH	HL
	PUSH	WX

	LD	HL,#YS_L_REG_4	;
	REF	RDouble_YS	;
	LD	HL,#YS_L_REG_4	; YS_L_REG[] = YS_L_REG * 4
	REF	RDouble_YS	;

	LD	HL,#DecBuf4	;
Rnd_24	LD	A,#0		; Clear DecBuf[]
	XCHD	A,@HL		;
	JR	Rnd_24		;

	LD	Y,#10		;
	LD	WX,#YS_R_REG_4	; YS_R_REG[] = YS_R_REG[] * 10
	LD	HL,#DecBuf4	;
	CALLS	Mul_1N		;
	LD	WX,#DecBuf4	; Copy DecBuf[] to YS_R_REG[]
	LD	HL,#YS_R_REG_4	;
	REF	RCpyBuf		;

	LD	WX,#YS_L_REG_0	; Compare YS_L_REG[] & YS_R_REG[]
	LD	HL,#YS_R_REG_0	;
	CALL	CmpDig		; skip return if YS_L_REG[] < YS_R_REG[]
	JR	Rnd_E		; Not Round

	LD	A,#1		; Round up YS_F_REG[] by 1
	LD	HL,#YS_F_REG_4	;
	CALLS	AddByLSB	;

Rnd_E	REF	RRET_WXHLEA	;
	RET

;***********************************************************
;	F: Convert 4-digit array to 16-bit word
;	I: WX = Source (End buf pointer)
;	   HL = Destination (lsb 8-bit pointer)
;	O: HL = Result
;	D: EA, HL, WX
;
Ary2Wrd	PUSH	YZ
	LD	Y,#1		;
Ay2Wd1	LD	A,@WX		;
	DECS	X		; (Shouldn't skip)
	XCHI	A,@HL		;
	LD	A,@WX		;
	DECS	X		; (Shouldn't skip)
	XCHD	A,@HL		;
	REF	RDECS_HL	;
	REF	RDECS_HL	;
	NOP			;
	DECS	Y		;
	JR	Ay2Wd1		;
	POP	YZ
	RET


;====== SLEEP TIME SETTING ROUTINE ==================================

;***********************************************************
;	F: EnIdle....  - if Sleep mode is not enabled, enable it
;	   RstIdle.... - reset sleep timer whatever it have enabled or not
;	D: EA
;
RL_BLT					; Battery low
RL_ZRT					; zero reading
RL_OWT	LD	EA,#Idle1minL_RL	; overweight
	LD	SleepTimL,EA		; load low byte
	LD	SleepTimLRL,EA	
	JR	RL_COMM1
RL_CRT					; normal 
RL_UWT					; under weight
	BTST	PowerOffTim		; check sleep time 
	LD	EA,#Idle3minL_RL	; load low byte
	LD	EA,#Idle10minL_RL	
	LD	SleepTimL,EA
	LD	SleepTimLRL,EA
	
	BTST	PowerOffTim
RL_COMM1
	LD	A,#IdleminH_RL		; load high nibble
	LD	A,#Idle10minH_RL
RL_COMM	
	LD	SleepTimH,A
	LD	SleepTimHRL,A
	RET

;***********************************************************
;	F: Set Zero reading sleep timer count down timer mode
;	I: LDigit1xxx, LDigitx1xx, LDigitxx1x, LDigitxxx1
;	   SDigitx_8
;	D: EA, HL, WX
;
SetSleepTimer
	BTSF	IdleBatLowNow	; if Battery low now, exit
	RET			;
SetST1
	LD	HL,#LDigit1xxx+1; Chk display value is zero or not
SetST2	DECS	L		;
	LD	EA,#LDsp_0	;
	CPSE	EA,@HL		; Digit = 0?
	JPS	SetST4		;
SetST3	REF	RDECS_HL	;
	NOP			;
	CPSE	L,#0dh		; Check large digit except decimal
	JR	SetST2		;

	LD	A,SDigitx_8	;
	CPSE	A,#SDsp_Nul	;
	JR	SetST5		;

	BTSF	Icon_One	; Check for 10kg pace

⌨️ 快捷键说明

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