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

📄 kclock.s.bak

📁 用SAM72N9写的电子秤文档
💻 BAK
📖 第 1 页 / 共 3 页
字号:
;	calz	ClrByte
;IncSet0:
;	ld	y,TmpRTCHourL
;	calz	DspHour
;	ret
	
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : inc setting minute
; Desc   : IncSetMinute
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
;IncSetMinute:
;	ld	x,TmpRTCMinute
;	calz	IncByteD
;	ld	x,TmpRTCMinute
;	calz	IsEqu60
;	ld	y,TmpRTCMinuteL
;	calz	DspMinute
;	ret
;-------------------------------------
; Cate   : Common
; By     : Hcy
; Func   : copy 2-byte to other memory, (buffer1) --> (buffer2)
; Desc   : Copy2Byte
; I/P    : x(buffer 1 low address), y(buffer 2 low address)
; O/P    :
; Destroy:
; Note   :
;Copy2Byte:
;	ld	a,4
;Copy0:
;	ld	my,mx
;	inc	x
;	inc	y
;	add	a,0fh		; dec a
;	jp	nz,Copy0
;	ret	
;---------------------------------------
;---------------------------------------
;	Communication Routine
;---------------------------------------
;---------------------------------------
;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : reload the communication variable
; Desc   : ReloadCommVar
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
;ReloadCommVar:
;	ld	y,CommBufferL
;	ld	my,0		; clr the communication buffer
;	ld	y,CommCount
;	ld	my,04h		; reload the communication bit counter
;	ret

;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : store to the receive buffer
; Desc   : ToRecBuffer
; I/P    : --
; O/P    : --
; Destroy:
; Note   :	
;ToRecBuffer:
;	ld	y,RxStartBufL
;	ld	x,RxNibbleCnt
;	ld	a,mx
;Prog1:
;	ld	YL,a
;Prog2:
;	ld	x,CommBufferL
;	ld	my,mx		; store receive data to receive buffer
;	ret

;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : is che memory equ 1bh
; Desc   : IsEquStartCode
; I/P    : Y(start code address)
; O/P    : --
; Destroy:
; Note   : c=1 if not equal 1bh, c=0 if equal 1bh	
;IsEquStartCode:
;	ld	y,RxStartBufL
;	cp	my,0Bh
;	jp	z,IsEquEE
;IsEquE:
;	scf	
;	ret                                            
;IsEquEE:
;	rcf
;	ret   


                                           
;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : is receive command right ? 
; Desc   : IsRightCmd
; I/P    : --
; O/P    : --
; Destroy:
; Note   : c=1 if undefined command, c=0 if defined command
;IsRightCmd:
;	ld	x,RxCommand
;	cp	mx,SHOWLDIGITCMD
;	jp	nz,IsRight0
;	; show Ldigit command
;	ld	x,SumNumRxNibble
;	ld	mx,0ch
;	jp	IsRight8
;IsRight0:
;	cp	mx,SHOWSDIGITCMD
;	jp	nz,IsRight1
;	; show Sdigit command
;	ld	x,SumNumRxNibble
;	ld	mx,1
;IsRight8:
;	rcf
;	ret
;IsRight1:
;	cp	mx,SHOWICONCMD
;	jp	nz,IsRight2
;	; show icon command
;	ld	x,SumNumRxNibble
;	ld	mx,4
;	ld	x,RxNibbleCnt
;	ld	mx,0ch			; 
;	jp	IsRight8
;IsRight2:
;	cp	mx,SHOWMSGCMD
;	jp	nz,IsEquE
;	; show msg command
;	jp	IsRight8

;;-------------------------------------
; Cate   : Display
; By     : Kwan
; Func   : Clear the LCD ram including digits/icons
; Desc   :
; I/P    :
; O/P    :
; Destroy:
; Note   :
;LCDClr:
;	LD	x,90h
;LCDClr0:
;	ldpx	mx,0
;	cp	xh,0bh		; LCD ram from 90 to AFH
;	jp	nz, LCDClr0
;	ret
;
;;-------------------------------------
; Cate   : KeyBoard
; By     : Kwan
; Func   : Key board scan, set NewKey flag if new key found
;	   set  keyhold flag if the new key is still in-held
; Desc   :
; I/P    :
; O/P    : 
; Destroy:
; Note   : After calling subr, the newkey flag should be 
;	   checked.
;	   For MaB key, the Keyholdkey should be cleared before
;	   activating the corresponding function
;          For MbB key, no need to check the KeyHoldFlag before
;          activating the corr. function
;	   For MaH, the hold time must be checked to be 255 before
;	   activating the corr. function.
;
;KeyScan:	
;	ld	b,Key_On
;	ld	x,KPort
 ;       fan	mx,IO_Key_On
;	jp	z,KeyFound0		; br if Key_on is preseed (=1)
;	call	Dly17ms
;	fan	mx,IO_Key_On
;	jp	nz,KeyFound
;KeyFound0:
;	ld	b,Key_Off
;	fan	mx,IO_Key_Off
;	jp	z,KeyFound1		; br if Key_off is preseed
;	call	Dly17ms
;	fan	mx,IO_Key_Off
;	jp	nz,KeyFound
;;
;KeyFound1:	
;	ld	b,Key_Kg
;	ld	x,PPort
;	fan	mx,IO_Key_Kg
;	jp	nz,KeyFound2		; br if Key_Kg is preseed
;	call	Dly17ms
;	fan	mx,IO_Key_Kg
;	jp	nz,KeyFound
;;
;KeyFound2:
;	ld	b,Key_ml
;	fan	mx,IO_Key_ml
;	jp	nz,KeyFound3		; br if Key_ml is preseed
;	call	Dly17ms
;	fan	mx,IO_Key_ml
;	jp	nz,KeyFound
;;
;KeyFound3:
;	LD	X,RegKeyFlags
;	AND	MX, 0fh-KeyHoldFlag
;NotNewKey:
;	RZF				; return with Z=0 
;	RET
;KeyFound:
;	LD	X,RegKeyFlags
;	FAN	MX,KeyHoldFlag
;	JP	nz,NotNewKey		; br if not new Key
;	OR	MX,NewKeyFlag+KeyHoldFlag	; set key flag
;	LD	KeyCode,B
;	SZF				; return with Z-1 if new key MbB
;	RET

;===============================================	
; Reset vectors are located at page 1
	ORG	100H
	JP	Init		; reset vector
	JP	IntRTC		; clock interrupt -- may only be used to set flag
;
	ORG	104H
	JP	IntKPort	; Key port interrupt 
;	JP	IntRTC_KPort	; timer and key port interrupt both
;
; All reset, clock and Key port interrupt should be located in 100H page

	ORG 110h
;-------------------------------------
; Cate   : System
; By     : Hcy
; Func   : check the interrupt timer 1/8 sec and 1/2 sec
; Desc   : ChkTimer
; I/P    : --
; O/P    : --
; Destroy:
; Note   :	
ChkTimer:
	ld	x,TIntFactor
	ld	a,mx		; read and clear any interrupt request flags
	fan	a,0010b		; chk 1/8 sec
	jp	z,TimeSet00
	inc	KeyHoldTm	; inc the keyhold time
	call	KeyScan
TimeSet00:	
	fan 	a,0100b			; chk 1/2 sec
	jp	z,TimeSet01
	call	ToggleHalfSecFlag	
	ld	x,AppFlags
	fan	mx,SecClickFlag
TimeSet01:
	jp	z,TimeS0		; br if just 0.5 sec
;	
	and	mx,0fh-SecClickFlag	; clear the bit
; update the clock per 1 min
;	
	calz	IncSecond
	jp	nc,TimeS0		; No display update if change in second only
	calz	IncMinute
	jp	nc,TimeS0
	calz	IncHour
TimeS0:	
	ret

;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : toggle the half sec flag
; Desc   : ToggleHalfSecFlag
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
ToggleHalfSecFlag:
	ld	x,AppFlags
	xor	mx,HalfSecFlag
	fan	mx,HalfSecFlag
	jp	nz,xToggleHalfS
	or	mx,SecClickFlag	; set flag if from 1->0
xToggleHalfS:
	ret

;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : inc setting HOUR
; Desc   : IncSetHour
; I/P    : --
; O/P    : --
; Destroy:
; Note   : 
IncSetHour:
	ld	x,TmpRTCHour
	calz	IncByteD
	ld	x,TmpRTCHour
	calz	IsEqu24
	jp	nc,IncSet0
	ld	x,TmpRTCHour
	call	ClrByte
IncSet0:
	ld	y,TmpRTCHourL
	calz	DspHour
	ret
	
;-------------------------------------
; Cate   : Common
; By     : Hcy
; Func   : copy 2-byte to other memory, (buffer1) --> (buffer2)
; Desc   : Copy2Byte
; I/P    : x(buffer 1 low address), y(buffer 2 low address)
; O/P    :
; Destroy:
; Note   :
Copy2Byte:
	ld	a,4
Copy0:
	ld	my,mx
	inc	x
	inc	y
	add	a,0fh		; dec a
	jp	nz,Copy0
	ret		

;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : reload the communication variable
; Desc   : ReloadCommVar
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
ReloadCommVar:
	ld	y,CommBufferL
	ld	my,0		; clr the communication buffer
	ld	y,CommCount
	ld	my,04h		; reload the communication bit counter
	ret
;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : store to the receive buffer
; Desc   : ToRecBuffer
; I/P    : --
; O/P    : --
; Destroy:
; Note   :	
ToRecBuffer:
	ld	y,RxStartBufL
	ld	x,RxNibbleCnt
	ld	a,mx
Prog1:
	ld	YL,a
Prog2:
	ld	x,CommBufferL
	ld	my,mx		; store receive data to receive buffer
	ret
;;-------------------------------------
; Cate   : Display
; By     : Kwan
; Func   : Clear the LCD ram including digits/icons
; Desc   :
; I/P    :
; O/P    :
; Destroy:
; Note   :
LCDClr:
	LD	x,90h
LCDClr0:
	ldpx	mx,0
	cp	xh,0bh		; LCD ram from 90 to AFH
	jp	nz, LCDClr0
	ret
	
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : inc setting minute
; Desc   : IncSetMinute
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
IncSetMinute:
	ld	x,TmpRTCMinute
	calz	IncByteD
	ld	x,TmpRTCMinute
	calz	IsEqu60
	ld	y,TmpRTCMinuteL
	calz	DspMinute
	ret

;-------------------------------------
; Cate   : Application
; By     : Hcy
; Func   : 
; Desc   : CopyByte
; I/P    : y(ram address)
; O/P    :
; Destroy:
; Note   :
CopyByte:
	ld	x,DspHourBuf
	ld	mx,my
	inc	y
	inc	x
	ld	mx,my		; ram --> dsphourbuf
	ret
;-------------------------------------
; Cate   : Application
; By     : Hcy
; Func   : -0ch   by decimal
; Desc   : Sub12D
; I/P    : y(address of buffer)
; O/P    :  
; Destroy:
; Note   :
Sub12D:
	push	yl
	call	CopyByte
	pop	yl
	ld	x,DspHourBuf
	SET	F,0100B     
	RCF                 
	sbc     Mx,02h      
	inc	x           
	sbc     Mx,01h      
	RST	F,1011B     
	RET
	
;
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : is che memory equ 12h
; Desc   : IsEqu24
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
IsEqu12:    
	cp	my,02h
	jp	z,IsEqu120
	rcf	
	ret               
            
IsEqu120:
	push	yl
	inc	y                                                      
	cp	my,01h  
	pop	yl                                    
	jp	z,IsEqu121		; jmp if 1 minute time out  
	rcf
	ret  
IsEqu121:      
	call	CopyByte            
	scf                                      
	ret 	

;
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : is che memory equ 0
; Desc   : IsEqu24
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
IsEquZero:    
	cp	my,0
	jp	z,IsEqu00
	rcf	
	ret               
            
IsEqu00:
	push	yl
	inc	y                                                      
	cp	my,0  
	pop	yl                                    
	jp	z,IsEqu01		; jmp if 1 minute time out  
	rcf
	ret  
IsEqu01:      
	ld	x,DspHourBuf     
	ld	a,02h
	ld	mx,a
	inc	x
	ld	a,01h
	ld	mx,a     
	scf                                      
	ret 

;-------------------------------------
; Cate   : Display
; By     : Hcy
; Func   : display the icons from the samsung
; Desc   : DspIcons
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
DspIcons:
	ld	y,RxIcon0
	ld	x,09ch
	ld	b,4
DspI0:
	ld	mx,my
	inc	y
	inc	x
	ADD	b,0FH		; b-1
	jp	nz,DspI0
	; add by hcy 03-11-24 12:02
	ld	y,RxIcon1
	fan	my,0010b
	jp	nz,DspI1
	
;	ld	y,0a0h
;	and	my,1110b
	calz	DspColonOff
	ret
DspI1:	
;	ld	y,0a0h
;	or	my,01h			; display ':'
	calz	DspColonOn
	ret

	
;
SendKeyData:
	ld	x,KPort
	fan	mx,0100b		
	jp	nz,Send0	; BR IF D_CLK is high
SendCalKey:	
 	LD	X,RPort
;	LD	MX,0001b	; D_out low
	and	mx,0001b	; D_out low

 	CALL	SendKey
 	LD	X,AppFlags
 	AND	MX,0fh-ReqToSendFlag	; clear the flag after sending
Send0:
 	RET
;
;-------------------------------------
; Cate   : delay
; By     : Hcy
; Func   : delay 2.5s
; Desc   : Dly250
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
Dly125:
	ld	y,0efh
Dly250:
	ld	y,0d8h
Dly1:
	call	Dly125ms
	inc	y
	cp	yh,0fh
	jp	nz,Dly1
	ret

;-------------------------------------
; Cate   : Delay
; By     : Hcy
; Func   : delay 125ms
; Desc   : Dly125ms
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
;
Dly125ms:
	ld	x,0
Dlym0:
	inc	x
	cp	xh,0fh
	jp	nz,Dlym0
	ret
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : clear the byte
; Desc   : ClrByte
; I/P    : x(ram address)
; O/P    : --
; Destroy:
; Note   :
ClrByte:
	ld	a,0
	ld	mx,a
	inc	x
	ld	mx,a
	ret	

;-------------------------------------
; Cate   : communication
; By     : Hcy
; Func   : is che memory equ 1bh
; Desc   : IsEquStartCode
; I/P    : Y(start code address)
; O/P    : --
; Destroy:
; Note   : c=1 if not equal 0bh, c=0 if equal 1bh	
IsEquStartCode:
	ld	y,RxStartBufL
	cp	my,0Bh
	jp	z,IsEquEE
	scf	
	ret                                            
IsEquEE:
	rcf
	ret   
		
Init:
	DI			; reset interrupt mask
	RST	F,0011b
;	LD	A,0	
;	LD	xp,a		; reset XP
;	LD	YP,A

	LD	A,0fh		; define SP
	LD	B,04h
	LD	SPL,A
	LD	SPH,B
;
	NOP5
	NOP5
;
; Cold start from here
;
	call	LCDClr
;	LD	x,90h
;LCDClr0:
;	ldpx	mx,0
;	cp	xh,0bh		; LCD ram from 90 to AFH
;	jp	nz, LCDClr0

;		
; Check the warm start words if necessary
; 
; 
; clr RAM for Cold start here
	ld	x,0
RAMClr:
	ldpx	mx,0
	cp	xh,5
	jp	nz,RAMClr
;
; set time to 12:00 after cold start
;
	ld	x,RTCHour
	ldpx	mx,2		; hour=12, min/sec cleared by RAMCLr
	ldpx	mx,1	
;
; define I/O port
	LD	Y,PPortDir
	LD	MY,0000b	; P-port  as input
;
	LD	Y,RPort
	; 03-11-22 14:04 HCY
	LD	MY,0010b	; Power down, CLK_IN default high
	
	
;
;
;
; enable interrupts if any
;
	LD	Y,KPortMask
	LD	MY,0100b	; No key interrupt allowed, only the D_Clk
;
 	LD	Y,TimerMask
 	LD	MY,0000b	; No timer interrupt allowed
;
	LD	Y,TimerCR	; reset timer
	LD	MY,0100b
;
	ld	y,CommBufferL
	ld	my,0
	ld	y,CommCount
	ld	my,04h
;
	ld	y,ModeOpt
;	ld	my,WEIGHTMODE		
	ld	my,CLOCKMODE
	
	
	ld	x,SumNumRxNibble
	ld	mx,0dh			; total receive 13 nibble data
;	
;	EI
;
; end of initialization
	ld	x,KPort
        fan	mx,IO_Key_On
        jp	z,ProgStart		; jmp if key_on is not pressed
	
	ld	B,Key_OnOff
	fan	mx,IO_Key_Off
	jp	nz,CalKey0		; br if Key_off is preseed
;	
	ld	b,Key_OnKg
	ld	x,PPort
	fan	mx,IO_Key_Kg
	jp	z,ProgStart		; br if Key_Kg is not preseed
CalKey0:
	
	LD	Y,RPort
	; 03-11-22 14:04 HCY
	LD	MY,0011b	; Power on, CLK_IN default high
	call	Dly125ms
	call	Dly125ms
	
	ld	x,ModeOpt
	ld	mx,CALIBRATEMODE

WaitSend0:	
	ld	x,KPort
	fan	mx,0100b		
	jp	nz,WaitSend0	; BR IF D_CLK is high
	
	LD	KeyCode,B

⌨️ 快捷键说明

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