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

📄 samtestc.src.bak

📁 用SAM72N9写的电子秤文档
💻 BAK
📖 第 1 页 / 共 5 页
字号:
;----------------------------------------------------------------------------
;
;	Project		:	High Resolution Kitchen SCALE
;	File		:	HighRes.src
;			:	HighRes.inc
;			:	57c2304.reg
;	Creation Date	:	10 Oct 2000
;	By		:	KP Yiu (Oriental Skill Ltd.)
;       Modified By     :       KL Tsang (Oriental Skill Ltd.)
;	Release Date	:	
;	Release Version	:	v.1.01.0000
;	Version Notes	:	v.1.01.0000
;;	                	- improve count fructration problem by adding PermitUpdate & modified
;;	                	  AverageSample function.
;;	                 	v.2.02.0000
;;	                	- improve auto-revert to zero feature to make the 2s counting more accurate.
;;	Develop Notes	:	High Resolution Scale
;;				v.0.6.0000
;;				- improve count taken problem after pull the scale
;;				- add 1s delay between Totalling and Tare for get stable count
;;				- zero bound change from fix 30 counts to 2 display step
;;				v.0.7.0000
;;				- add 3s delay before get zero 
;;				- after creeping & 8s, if display weight = 0, put current count into zero
;;				- add 1.5s delay after press keys
;;                              - change power control logic
;;                              v.0.8.0000
;;                              - after creeping and display zero, the time is changed from 8s to 2s
;;                              - use new LCD
;;                              v.0.9.0000
;;                              - display 1x.xxx kg use new LCD
;;                              - hold any keys, no display change
;;                              v.0.10.0000
;;                              - solve the sleep time problem -- scale don't sleep in 1 min after display is zero
;;                              - add mode 1 - calculate the display
;;                              - add display method for mode 1
;;                              v.0.11.0000 (By Pang - 18 Feb 2002)
;;                              - merge with Dennis program
;;                              - Correct the mode table to display accurate 115% weight limit.
;;                              - Correct the power up display as "8888 7/8" for mode 1-5,
;;                                "18888 7/8" for mode 6 & 7 and "8888" for mode 8
;;                              - Optimize the routine "SetFactoryMode"
;;                              - Correct On/Zero button to MaB
;;                              - Remark dummy instructions in routine "Sleep"
;;                              v.0.12.0000 (By Pang - 25 Feb 2002)
;;                              - update the program according to the email dated 25 Feb 2002 from Dennis
;;                                -> Changed back power up display on mode 6 & 7 to "8888 7/8"
;;                                -> Fix the power up click sound problem
;;                                -> Fix a underweight bug
;;				v.1.5.0000 (By Dennis Wong - 3 Apr 2003)
;;				- Remove emulator rountine
;;				- Debug auto power off problem that sleep timer cannot reset at least 5sec
;;				v.1.6.0000 (By Dennis Wong - 28 Apr 2003)
;;				- Add fl.oz mode for all resolution
;;				v.1.6.0001 (By Dennis Wong - 28 May 2003)
;;				- Update the maximum capacity of fl.oz mode
;;				v.1.7.0000 (By Dennis Wong - 3 Jun 2003)
;;				- Use 'HoldEn' to be hold function enable flag to elimate calibration hold problem
;;				- Use 'TareNow' to be tare function enable flag
;;				- Modify clear icon rountine to free space
;;				- Debug fl.oz mode of 200g x 0.1g resolution
;; 
;;				03-12-2 (By Hcy )
;;				- add 'bits PermitSend' in the label 'UMainCalculate6' for minus weight and tare
;;				- replace 'RDspSymbol' to 'RDsp4LDigit' in the subroutine 'ChkBatteryLow' for check battery low 
;;				; v02 03-12-4 14:14 
;  1. after battery insert to the scale, the display time should be 12:00 a.m.
;  2. the scale can enter calibration moe at anytime during clock display
;  3. to avoid abnormal operarion, program EPSON IC so that it cann't turn on
;     within 2s after the scale turn off.
;  4. run-time unit change havn't now
;  5. resolutin 2.8 no decimal point
;  6. press 2s to start time adjustment
;  7. add display version for EPSON IC at calibration mode
;  8. scale cann't change from '----' to '0'
;  9  low battery warning.
;;				v03(03-12-9 (By Hcy))
;  1. add the function that program return to the view clock mode if no key 
;     pressed in the setting clock mode wihin 15 second
;  2. take away 'PermitSend' flag, when the under weight 'LDsp__' --> PrevWeightBCD
;	v50 03-12-11 10:08 about 60R01
;  1. lcd return to the original setting.
;  2. key board for new key assignment
;  3. 

;;---------------communication protocal----------------------
;;
;;---------------Communication protocol:
; Name	Samsung 	          EPSON	Name
; MS_CLK	P60	--->	P00		Clk_In
; SL_DIN	P11	<---	R01		SL_Dout
; MS_DOUT	P62	--->	P01		SL_Din		;
;
; Write to EPSON		
;1. Synchronized serial, 4 bit data, with master control		
;2. Samsung is the master of the communication		
;3. The LS bit will be sent first in a byte.		
;4. The clock bit is normal low and SL_Dout is normal high when no transmission.
;   Rising edge of clock bit to make attention to EPSON and place the data bit to MS_Dout.
;   Wait until EPSON response SL_Dout to Low and the clock bit goes to low to start
;   a bit cycle and EPSON received a bit ,it pull high the SL_DIN, Samsung 
;   will pull high MS_CLK when SL_DIN is high.and the MS_Dout should return to high also.
;   The data bit is sent out on the falling edge of the clock		
;5. The data bit is assumed to be read out by EPson on the falling edge of the SL_Dout.		
;6. The clock line will keep on low when all 8 bits data has been sent out		
;
;7. The clock rate is around 0.5KHz						
;8. no time out 
;
; Data return to Samsung (master)
;1. Synchronized serial, 4 bit data, with master control		
;2. Samsung is the master of the communication		
;3. The LS bit will be sent first in a byte.	
;4. epson pull down the SL_DIN when have any key pressed to tell samsung to ready receive key 	
;   then send data will be put the SL_DIN ,first send 0AH, then send key code.
;5. The clock rate is around 400Hz						
;
; Command codes of the communication
;1. The communication begins with code (0BH) normally				
;2. If send auto off , the start code is '0DH' 
;4. The Epson should ignor all un-defined commands		
;5. all communication operation is in foreground.
;
;6. A counter is used to indicate number of bits received or number of bits left to send.
;----------------------------------------------------------------------------

                .include "57c2304.reg"
                .include "HighRes.inc"

	.list on

;-----------------
VerD1		.equ	5
VerD2		.equ	0

;----------------------------------------------------------------------------

	.origin	VectorTable
ResetVector
	VENT0	1,0,Reset	; Reset Vector
	VENT1	1,1,INTB_Int	;
	VENT2	1,1,INT0_Int	;
	VENT3	1,1,INT1_Int	;
	ORG	00ah		;
	VENT5	1,1,INTT0_Int	;

;----------------------------------------------------------------------------
;
	.origin	Main1Loop

;----------------------------------------------------------------------------
IRETSB	POP	SB
	IRET
;----------------------------------------------------------------------------
RETHLEA	POP	HL
	POP	EA
	RET
;----------------------------------------------------------------------------
RETWXHLEA
	POP	WX
	POP	HL
	POP	EA
	RET
;----------------------------------------------------------------------------
RETYZWXHLEA
	POP	YZ
	POP	WX
	POP	HL
	POP	EA
	RET

;***********************************************************
;	F: Copy Buf to Buf from xyH to x0H where x & y are any hex num
;	I: HL = Destination Buf(Buf end pointer)
;	   WL = Source Buf(Buf end pointer)
;	O: HL = Duplicated Buf
;	D: A, HL
;
CpyBuf	LD	A,@WL		;
	XCHD	A,@HL		;
	JR	CpyBuf		;
	RET

;----------------------------------------------------------------------------
;
	.origin	LookupTable

RSMB_Variable	SMB	VariableBank
RSMB_MemMapIO	SMB	MemMapIOBank
RSMB_LCD	SMB	LCDBank

RINCS_2HL	INCS	HL		;
		INCS	HL		;
RDECS_HL	DECS	HL		;
RLD_HLEA	LD	HL,EA		;
RLD_WXEA	LD	WX,EA		;
RLD_EA0		LD	EA,#0		;
RLD_E0		LD	E,#0		;
RCPSE_A0	CPSE	A,#0		;
RCPSE_EAHL	CPSE	EA,HL		;
RADC_EAHL	ADC	EA,HL		;


RLD_LDIGxxx1EA	LD	LDigitxxx1,EA
RLD_LDIGxx1xEA	LD	LDigitxx1x,EA

RDiv_YS		TCALL	Div_YS
RRound_YS	TCALL	Round_YS
RMul_10_FReg	TCALL	Mul_10_FReg
RDiv_10_FReg	TCALL	Div_10_FReg
RDouble_YS	TCALL	Double_YS

RCmpHex		TCALL	CmpHex
RCpyBuf		TCALL	CpyBuf
RHex2BCD_16	TCALL	Hex2BCD_16
RSubHex		TCALL	SubHex

RSkipSRC_YZ	TCALL	SkipSRC_YZ
RByteAry	TCALL	ByteAry
RWrd2Ary	TCALL	Wrd2Ary
RStoreWordCode	TCALL	StoreWordCode
RStoreByteCode	TCALL	StoreByteCode

RDspSDigit	TCALL	DspSDigit
RDsp4LDigit	TCALL	Dsp4LDigit
RDspSymbol	TCALL	DspSymbol

RKScanDelay	TCALL	KScanDelay

RCalWeightCnt	TCALL	CalWeightCount
RActCurStp2Ary	TCALL	ActlCurStep2Ary
RCurStep2Ary	TCALL	CurStep2Ary
RSetBnd		TCALL	SetBnd
RGetAverageCnt	TCALL	GetAverageCnt
RAverageSample  TCALL   AverageSample

RNWCnt2FReg	TCALL	NWCnt2FReg
RHxFReg2Dec	TCALL   HxFReg2Dec
RCpy_R2FReg	TCALL	Cpy_R2FReg
RCpy_F2LReg	TCALL	Cpy_F2LReg
RPutDec		TCALL	PutDec

RPush_SB	PUSH	SB

RRET_HLEA	TJP	RETHLEA
RRET_WXHLEA	TJP	RETWXHLEA
RRET_YZWXHLEA	TJP	RETYZWXHLEA
RIRET_SB	TJP	IRETSB

;----------------------------------------------------------------------------
;
	.origin	Main2Loop

;----------------------------------------------------------------------------
;	F: On/Zero Button(MaB)
;	I: WeightTareNow
;	O: WeightTareNow
;	N: Rising edge when release key(MaB)
;	   When enter INT1_Int, IS0, IS1 = 1, 0
;
INT1_Int
        BITR    IRQ1            ;
        BITR    IS0             ;        
;	REF	RPush_SB	;
;	REF	RSMB_Variable	;
;	BTSF	CalibrateOn	;
;	BITR	CntDspNow	;
;;	REF	RSMB_MemMapIO	;
;;INT1_Int1
;;	BTST    ONZERO_PIN
;;        JR      INT1_Int1
;;	REF	RSMB_Variable	;	
;	BITS	WeightTareNow	; Set flag to weight tare	
;	REF	RIRET_SB	;
	IRET

;----------------------------------------------------------------------------
;	F: INTB Interrupt for Basic Timer Overflow
;	N: Interrupt interval = 2.2886.ms
;	   when enter into INTB_Int, IS0, IS1 = 1, 0
INTB_Int
        BITR    IRQB            ;
        BITR    IS0             ;

	REF	RPush_SB	;
	SRB	RegisterINTB	;
	REF	RSMB_Variable	;

	BTSF	CalibrateOn	; If Calibrate On, skip sleep time
	JPS	INTB_Int0_2	; & Timer counting

	LD	EA,BCNT_1s_M	;
	ADS	EA,#1		;
	JPS	INTB_Int0_1	;
	INCS	BCNT_1s_H	; never skip
	BTSF	BCNT_1s_H.0	;
	JPS	INTB_Int0_1	;
INTB_1000ms

	BTST	HoldRd		; Check for hold reading in progress
	JR	INTB_IntA	;

	INCS	HoldTimer	; Check hold reading timeout
	JR	INTB_IntA	;
	BITR	HoldRd		; 
	BITR	HoldStableChk	;
	BITS	HoldNotAllow	; Hold is not allow unless reading change
	LD	A,#HoldChkTime	; Reset timer
	LD	HoldTimer,A	;
INTB_IntA
INTB_IntB
	BTSF	AutoOffEn	; Chk Auto-power off enabled or not
	JPS	INTB_IntC	; if not, jump
	BTSF	Chge4stepNow	; Chk 4 step changing
	JPS	INTB_IntC	; if change, jump
	BTSF	SleepNow	; Goto Sleep if timeout
	; remark it by hcy 03-12-2 18:03
;	JPS	Sleep1		;
	bits	PermitSendAPO
	INCS	SleepTimL	;
	JR	INTB_IntC	;
	INCS	SleepTimL+1	;
	JR	INTB_IntC	
	INCS	SleepTimH	;
	JR	INTB_IntC	
	BITS	SleepNow	; SleepTim overflow, then set sleep flag
	nop
	nop
; end kwan.
;
INTB_IntC
	LD	A,#0		;
	LD	BCNT_1s_H,A	; Reload 1s timer
	LD	EA,#BCNT1s_RL&0ffh
INTB_Int0_1
	LD	BCNT_1s_M,EA	;

INTB_Int0_2
	INCS	BCNT_36ms	; BCNT Count from 0 -> 15 -> 0 -> 15 ....
	REF	RIRET_SB	;
INTB_36ms
;-----
INTB_Int1_1
	INCS	BCNT_183ms	; Check 183ms interval reached?
	JPS	INTB_Int2_1	;

INTB_183ms
	LD	A,#BCNT183ms_RL	;
	LD	BCNT_183ms,A	; Reload 183ms timer

INTB_Int1_2
	BTST	AutoZeroEn	; Chk Auto-revert to zero enabled or not
	JR	INTB_Int1_3	; if not, jump
	BTST	UdrWtNow	; Is Now UnderWeight
	JR	INTB_Int1_3	;
	INCS	AutoZeroTim	;
	JR	INTB_Int1_3	;
	BITS	AutoZeroNow	; Enable Reset to Zero

INTB_Int1_3
	
;	LD	A,Tag2sec	;
;	REF	RCPSE_A0	; if Tag2sec <> 0,
;	INCS	Tag2sec		; Incs Tag2sec
;--------------------------
INTB_Int2_1
	INCS	BCNT_500ms	; chk 512ms reached?
	REF	RIRET_SB	;

INTB_500ms
	LD	A,#BCNT500ms_RL	; Reload 512ms Timer
	LD	BCNT_500ms,A	;
;--------------------------        
	BTST	Chge4stepNow
	JR	INTB_Int3_1
	INCS	Chge4stepTimer
	JR	INTB_Int3_1
	BITR	Chge4stepNow	; Set sleep timer delay end
	BITS	ChgeSlpTmrNow
INTB_Int3_1
	BTST	HoldEn		; Check for hold enable
	JR	INTB_Int3_2	; 
	BTSF	HoldRd		; Check the reading is not hold
	JR	INTB_Int3_2	;
	BTSF	HoldStableChk	; whether the routine executed or not
	JR	INTB_Int3_2	;
	INCS	HoldTimer	;
	JR	INTB_Int3_2	;
	BITS	HoldStableChk	; chk hold stable time interval reach
INTB_Int3_2
        INCS    Tag2sec
        JR      INTB_Int3_3
        BITS	CreepZero	;	

INTB_Int3_3
	INCS	CreepTimer	; CREEPING TIMER
	REF	RIRET_SB	
	BITS	TimrFinished	;	
	REF	RIRET_SB	;
;----------------------------------------------------------------------------
;
Sleep
	CALLS	Dly20		; simlute the Buzzer tone delay
;	REF	RKeyTone	;
Sleep1
	DI			;
Sleep2
	REF	RSMB_MemMapIO	;

	LD	A,#0		;
	LD	INTA,A		; Disable Basic Timer Interrupt(INTB)
	LD	INTB,A		; Disable Watch Timer
	LD	INTC,A		; Disable Timer/Counter Interrupt(INTT0)
	LD	INTE,A		; Disable INT0 Pin Interrupt
				; Disable INT1 Pin Interrupt
	LD	LCON,A          ; Display off
	

	REF	RSMB_LCD 	; Select LCD Memory Bank1
;	BITR	POWERON_PIN	; Power Off  for Chip

	call	Send_AutoOffCode

	
	NOP
	JR	$-1		; Dead loop until no power supply
	
;----------------------------------------------------------------------------
;	F: Chk "Off" key press
;	O: SMB = Variable Bank
;	D: A
ChkOffButton
; remark by hcy 03-11-21 15:06

;	REF	RSMB_MemMapIO	;
;	LD	A,KEYCOL	;
;	REF	RSMB_Variable	;
;	AND	A,#0001b	;
;	DECS	A		;
;	RET			;
;	JPS	Sleep		; Off button
	RET

;----------------------------------------------------------------------------
;	F: External INT0 pin Interrupt
;	N: When enter INT0_Int, IS0, IS1 = 1, 0
INT0_Int
	REF	RPush_SB	;

;v***** IMPORTANT TO DO FIRST *****v
	SRB	RegisterCount	;
	REF	RSMB_MemMapIO	;
	LD	EA,#01110000b	; Stop TCNT0
	LD	TMOD0,EA	;
	REF	RSMB_LCD 	;
	BITR    DISCHARGE_PIN	;
;^*********************************^

	REF	RSMB_MemMapIO	;
	LD	EA,TCNT0	; Load LSB
	REF     RLD_WXEA        ; Store LSB to WX
	LD	EA,#01111100b	; Enable T/C0
	LD	TMOD0,EA        ; clear TCNT0 & Restart

	REF	RSMB_Variable	;
	BITR	CntPeriodNow	;

	BTST	IRQT0		;
	JR	StoreSample	;
	INCS	YZ		;
	JR	StoreSample	;
	INCS	L		;	
	BITR	IRQT0		; Clear Timer/Counter Request Flag
	
StoreSample
	PUSH	HL		;
	LD	HL,#HaveData	;
	
	LDB	C,@H+PermitUpdate
	BTST	C		; Chk Permit to update sample or not?
	JR	StorePermit	;
	JPS	INT0_Int1	;
StorePermit	
	LDB	C,@H+UpdateSample0
	CCF			;
	LDB	@H+UpdateSample0,C
	BTST	C		; Chk where Sample to store?
	JR	StoreSample0	;

StoreSample1
	LD	EA,WX		; LSB
	LD	SampleCount1+2,EA
	LD	EA,YZ		; MSB
	LD	SampleCount1,EA	;
	BITS	HaveSample1	; Set Flag for Sample 1 reach
	JR	INT0_Int1	;

StoreSample0			;
	LD	EA,WX		; LSB
	LD	SampleCount0+2,EA
	LD	EA,YZ		; MSB
	LD	SampleCount0,EA	;
	BITS	HaveSample0	; Set Flag for Sample 0 reach

INT0_Int1
	POP	HL		;
	BITS	OvrAbMaxNow	; Exact absolute max
	CPSE	L,#0		;
	JR	INT0_Int3	;

	LD	EA,#AbsMaxCnt/256-1
	SBS	EA,YZ		; Chk MSB
	JR	INT0_Int2	;
	REF     RLD_HLEA
	INCS	HL		; if MSB = AbsMaxCnt/256,
	JR	INT0_Int3	; chk LSB
	LD	EA,#AbsMaxCnt%256

	SBS	EA,WX		;
INT0_Int2
	BITR	OvrAbMaxNow	; Not Exact absolute max
INT0_Int3
	BITR	IRQ0		; Clear INT0 Interrupt Request Flag
	REF	RIRET_SB	;

;----------------------------------------------------------------------------
;	F: INTT0 Interrupt for Timer/Counter 0 Compare Match
;	I: CntPeriodNow = 0: DischargePeriod
;	                  1: CountingPeriod
;	N: When enter INTT0_Int, IS0, IS1 = 0, 1
INTT0_Int
	REF	RPush_SB	;

	SRB	RegisterCount	;
	REF	RSMB_Variable	;
	BTST	CntPeriodNow	;
	JPS	DischargePeriod	;

;v***** IMPORTANT - COUNTING PART *****v
CountingPeriod			;
	INCS	YZ		; MSB for Counting Value

⌨️ 快捷键说明

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