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

📄 kclock.s.bak

📁 用SAM72N9写的电子秤文档
💻 BAK
📖 第 1 页 / 共 3 页
字号:
;
; Copy right Oriental Skill (Asia) Ltd 
; October 24, 2003
;
; Created by Kwan for Testing
;
;
; Scratch Pad memory from 0H ~ 0FH (M0~MF)
; User RAM from 10H ~ 2FH (32 nibbles)
; Stack from 30H~4FH
; LCD RAM from 90H ~ AFH -- However A4H~AFH may be used
; as user RAM because S13~S19 segment are not used
; in this application.
;
SHOWLDIGITCMD	EQU	2
SHOWSDIGITCMD	EQU	3
SHOWICONCMD	EQU	4
SHOWMSGCMD	EQU	5

CLOCKMODE	EQU	0
WEIGHTMODE	EQU	1
CALIBRATEMODE	EQU	2

KeyHoldTm	EQU	M0
KeyFlags	EQU	M1
RegKeyFlags	EQU	1	; same as KeyFlags
;CommCount	EQU	M2	; bit count for comm
KeyHoldFlag	EQU	1
NewKeyFlag	EQU	2
DisFlashFlag	EQU	4
TimeFormatFlag	EQU	8	; 0: 12 hour, 1: 24 hour
KeyCode		EQU	M3
RegKeyCode	EQU	3
SendData	EQU	M4
RegSendData	EQU	4

Tmr30s		EQU	M5
;CommFlag	EQU	M6



;
RTCSec		EQU	10H
RTCSecL		EQU	10H
RTCSecH		EQU	11H
RTCMin		EQU	12H
RTCMinL		EQU	12H
RTCMinH		EQU	13H
RTCHour		EQU	14H
RTCHourL	EQU	14H
RTCHourH	EQU	15H
;


RxStartBufL	equ	20h	; start code 
;RxCommand	equ	21h
RxBuffer0	EQU	21H	; LSBL, ___1, decimal place
RxBuffer1	EQU	22H	; LSBH
RxBuffer2	EQU	23H	; xxx1
RxBuffer3	EQU	24H
RxBuffer4	EQU	25H	; xx1x
RxBuffer5	EQU	26H
RxBuffer6	EQU	27H	; x1xx
RxBuffer7	EQU	28H
;RxBuffer8	EQU	2aH	; MSBL
;RxBuffer9	EQU	2bH	; MSBH

;RxIcon0		EQU	2ch	; LSB
;RxIcon1		EQU	2dh	; 
;RxIcon2		EQU	2eh	
;RxIcon3		EQU	2fh	; MSB

RxIcon0		EQU	29h
RxIcon1		EQU	2ah
RxIcon2		EQU	2bH
RxIcon3		EQU	2cH
RxSBuffer	EQU	2dH	; SDIGIT

RxBuffer8	equ	2eh
RxBuffer9	equ	2fh

SumNumRxNibble	equ	31h	; 
;

ModeOpt		equ	33h	; 0: Clock Mode, 1: weighting Mode, 2: Calibration Mode

DspHourBuf	EQU	34H
DspHourLBuf	EQU	34H
DspHourHBuf	EQU	35H	


AppFlags		EQU	16H	
HalfSecFlag	EQU	1
SecClickFlag	EQU	2
ReqToSendFlag	EQU	4	; set when 4 bits has been sent in background
Rx4BitFlag	EQU	8	; set when 4 bits has been received in background

;b0 -- Half second (0->1 0.5 sec, 1->0 1 sec)
;b1 -- second click
;b2 -- RxReady

CommCount	EQU	17H	; bit count for comm
TmpRTCMinute	EQU	18H
TmpRTCMinuteL	EQU	18H	; for the use of time adjustment
TmpRTCMinuteH	EQU	19H
TmpRTCHour	EQU	1AH
TmpRTCHourL	EQU	1aH
TmpRTCHourH	EQU	1bH
;
CommBufferL	EQU	1cH	; Tx/Rx Buffer

;RxNibbleCnt	equ	00h	; 

RxNibbleCnt	equ	1dh
KeyFlag		EQU	1eH
;NewKey		bit	1eh.0
;KeyHold		bit	1eh.1

RTC1SecCnt	equ	1fh

;
;
;===========================================================
; Registers
; IC: 6001
KPort		EQU	0E0H
IO_Key_On	EQU	1
IO_Key_Off	EQU	2
IO_DClk		EQU	4
;
Timer		EQU	0E4H	; timer data register
KPortMask	EQU	0E8H	; interrupt mask for K-port
TimerMask	EQU	0EBH	
KIntFactor	EQU	0EDH	; interrupt request flags for Kport
TIntFactor	EQU	0EFH	; interrupt request flags for Timer
;
RPort		EQU	0F3H	; R0 data port
IO_PowerCtl	EQU	1
IO_DataOut	EQU	2
;
PPort		EQU	0F6H	; P0 data port
IO_Key_Kg	EQU	1
IO_Key_ml	EQU	2
IO_DataIn	EQU	8
;
TimerCR		EQU	0F9H
;b2=1 to reset clock timer
;
HeavyLoad	EQU	0FAH	; heavy load protection register
;b3=1 if heavy load, b3=0 if normal load
;
LCDSwitch	EQU	0FBH	;
;b3=1 if static, b3=0 if dynamic
;
PPortDir	EQU	0FCH	; P-port direction register
;b0=1 if whole P-port as output, b0=0 if as inout 
;
BuzzerFreq	EQU	0FDH	; Buzzer freq


;===========================================================
; Registers
; IC: 60R08
;KPort		EQU	2E3H
;IO_Key_On	EQU	1
;IO_Key_Off	EQU	2
;IO_DClk		EQU	4
;
;Timer		EQU	2E0H	; timer data register
;KPortMask	EQU	2E5H	; interrupt mask for K-port
;TimerMask	EQU	2E8H	
;KIntFactor	EQU	2EAH	; interrupt request flags for Kport
;TIntFactor	EQU	2E9H	; interrupt request flags for Timer
;
;RPort		EQU	2EBH	; R0 data port
;IO_PowerCtl	EQU	1
;IO_DataOut	EQU	2
;
;PPort		EQU	2EDH	; P0 data port
;IO_Key_Kg	EQU	1
;IO_Key_ml	EQU	2
;IO_DataIn	EQU	8
;
;TimerCR		EQU	2EEH
;b2=1 to reset clock timer
;
;HeavyLoad	EQU	2E6H	; heavy load protection register
;b3=1 if heavy load, b3=0 if normal load
;
;LCDSwitch	EQU	2E8H	;
;b3=1 if static, b3=0 if dynamic
;
;PPortDir	EQU	2EEH	; P-port direction register
;b0=1 if whole P-port as output, b0=0 if as inout 



;
; constants defintion
;
Key_On		EQU	0111b	; key code corr. to Samsung's code
Key_Off		EQU	1110b
Key_Kg		EQU	1101b
Key_ml		EQU	1011b
Key_Nil		EQU	0

; define by hcy
Key_OnOff	EQU	0110b
Key_OnKg	EQU	0101b

;===========================================================
	ORG	0
	
;-----------------------------------------------------------
;-----------------------------------------------------------
;	Display routine
;-----------------------------------------------------------
;-----------------------------------------------------------
;	hgfe dcba
	retd	3fh		; 0
	retd	06h		; 1
	retd	5bh		; 2
	retd	4fh		; 3
	retd	66h		; 4
	retd	6dh		; 5
	retd	7dh		; 6
	retd	27h		; 7
	retd	7fh		; 8
	retd	6fh		; 9
	retd	77h		; A
	retd	7ch		; b
	retd	39h		; C
	retd	5eh		; d
	retd	79h		; E
	retd	71h		; F
	retd	76h		; H
	retd	38h		; L
	retd	50h		; r
	retd	73h		; P
	retd	78h		; t
	retd	3eh		; U
	retd	40h		; -
	retd	00h		; ' '
	
	
	; fraction table
	retd	18h		; 
	retd	14h
	retd	38h
	retd	12h
	retd	58h
	retd	34h
	retd	78h
	retd	98h
	
DspPattern:
	ld	b,0
	jpba

DspPattern1:
	ld	b,1
	jpba	
;-------------------------------------
; Cate   : Display
; By     : Hcy
; Func   : display the digit(0--9)
; Desc   : DspDigit
; I/P    : A(0--9),X(address of digit address)
; O/P    : --
; Destroy: A,
; Note   :
DspDigit:
	calz	DspPattern
	ret
DspDigit1:
	calz	DspPattern1
	ret	
;-------------------------------------
; Cate   : Display
; By     : loren
; Func   : display the icon 
; Desc   : DspColonOn
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
DspColonOn:
	ld	y,0a0h
	or	my,01h			; display ':'
	ret
	
;-------------------------------------
; Cate   : Display
; By     : loren
; Func   : display off the icon 
; Desc   : DspColonOff
; I/P    : --
; O/P    : --
; Destroy:
; Note   : 
DspColonOff:
	ld	y,0a0h
	and	my,1110b
DspCO:
	ret

;-------------------------------------
;-------------------------------------
; Cate   :Dosplay
; By     :Kwan
; Func   :Flash the colon
; Desc   :
; I/P    :---
; O/P    :
; Destroy:
; Note   : turn on/off the colon according to 
; 	   HalfSecFlag
;
FlashColon:
	ld	y,ModeOpt
	fan	my,1111b
	jp	nz,DspCO		; jmp if not clock mode
	
	ld	y,AppFlags
	FAN	my,HalfSecFlag
	Jp	z,DspColonOff
	jp	DspColonOn

FlashHour:
	ld	x,AppFlags
	FAN	mx,HalfSecFlag
	Jp	z,DspHourOff
;-------------------------------------
; Cate   : Display
; By     : Hcy
; Func   : Display the time
; Desc   : DspTime
; I/P    : y(ram address)
; O/P    : --
; Destroy:
; Note   :
DspTime:
DspHour:
	; display hour xx
;	ld	x,RTCHourH
	ld	x,RegKeyFlags
	fan	mx,TimeFormatFlag
	jp	nz,DspH0			; jmp if 24 hour format
	call	IsEquZero
	jp	c,NDspH00
	call	IsEqu12
	jp	c,DspH00		; jmp if hour =12
	call	Sub12D
	jp	nc,DspH00		; current time > 12
	call	CopyByte
;	ld	a,0ah
;	ld	x,098h
;	calz	DspPattern		; 'A'
NDspH00:
	ld	a,01h
	ld	x,0a1h
	ld	mx,a			; 'AM'
	jp	DspH1
DspH00:
;	ld	a,03h
;	ld	x,098h
;	calz	DspPattern1		; 'P'
	ld	a,02h
	ld	x,0a1h
	ld	mx,a			; 'PM'
	jp	DspH1
DspH0:
	ld	a,7
	ld	x,0a1h
	calz	DspPattern1		; ' ' 	
	call	CopyByte
	jp	NDspH0
DspH1:
;	ld	x,DspHourBuf
;	calz	IncByteD
NDspH0:
	ld	y,DspHourBuf
	ld	a,my
DspH2:
	ld	x,092h
	calz	DspDigit              
	ld	y,DspHourHBuf
	ld	a,my
	fan	a,1111b
	jp	nz,NewDspH2
	jp	NewDspH22
NewDspH2:
	ld	x,090h
	calz	DspDigit
	ret
DspHourOff:
	; off minute xx
	ld	a,07h	
	ld	x,092h
	calz	DspDigit1
NewDspH22:
	ld	a,07h
	ld	x,090h
	calz	DspDigit1
	ret
	
FlashMinute:
	ld	x,AppFlags
	FAN	mx,HalfSecFlag
	Jp	z,DspMinuteOff	

DspMinute:
	; display min xx
;	ld	x,RTCMinH
	ld	a,my
	ld	x,096h
	calz	DspDigit
;	ld	x,RTCMinL
	inc	y
	ld	a,my
	ld	x,094h
	calz	DspDigit
	ret
DspMinuteOff:
	; off minute xx
	ld	a,07h
	ld	x,094h
	calz	DspDigit1	
	ld	x,096h
	calz	DspDigit1
	ret

	
		
;-------------------------------------
; Cate   : Display
; By     : Hcy
; Func   : dislay the fraction
; Desc   : DspFraction
; I/P    : RxSBuffer(0--9) --> nul,1/8,1/4,3/8,1/2,5/8,3/4,7/8,9/8,nul
; O/P    : --
; Destroy:
; Note   :
DspFraction:
	ld	y,RxSBuffer
	cp	my,0
	jp	z,DspF0
	cp	my,9
	jp	z,DspF0
	ld	a,my
	add	a,07h		; a+7
	ld	x,RxBuffer8
	calz	DspPattern1
	ld	y,RxBuffer8
	ld	a,my
	ld	x,098h
	calz	DspPattern
	inc	y
	ld	a,my
	calz	DspPattern
	ret
DspF0:
	; display nul/nul
	ld	a,7
	ld	x,098h
	calz	DspPattern1	; display ' ' in 5th digit
	calz	DspPattern1	; display ' ' in 6th digit
	ret	
		
;-------------------------------------
; Cate   : Display
; By     : Hcy
; Func   : display the weight from the samsung
; Desc   : DspWeight
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
DspWeight:
	ld	y,RxBuffer6
	ld	x,090h
	ld	b,4
DspW0:
	ld	a,my
	push	b
	ld	b,a
	inc	y
	fan	my,0fh
	jp	nz,DspW1
	ld	a,b
	calz	DspDigit    
	jp	DspW2
DspW1:
	ld	a,b
	calz	DspDigit1
DspW2:
	ld	b,YL
	rcf
	sbc	b,3		; get next digit
	ld	YL,b		
	pop	b
	ADD	b,0FH		;
	jp	nz,DspW0
	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
;;	rcf
;;	sbc	b,1		; get next digit
;	ADD	b,0FH		;
;	jp	nz,DspI0
;	ret

;---------------------------------------
;---------------------------------------
; 	calculate the clock
;---------------------------------------
;---------------------------------------
;-------------------------------------
; Cate   : Application
; By     : Hcy
; Func   : increase byte by decimal
; Desc   : IncByteD
; I/P    : X(address of buffer)
; O/P    :  
; Destroy:
; Note   :
IncByteD:
	SET	F,0100B     
	RCF                 
	ADD     MX,01h      
	inc	x           
	ADC     MX,00h      
	RST	F,1011B     
	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   : check if up to 1 minute
; Desc   : IncSecond
; I/P    : --
; O/P    : --
; Destroy:
; Note   : c=0 if not up to 1 minute, c=1 if up to 1 minute
IncSecond:
	ld	x,RTCSec
	calz	IncByteD
	ld	x,RTCSec
	calz	IsEqu60
	ret
	
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : is che memory equ 60h
; Desc   : IsEqu60
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
IsEqu60:       
	cp	mx,00h
	jp	z,IsEqu0
;	rcf	
;	ret        
;	jp	IsEqu2      
	jp	IsRight8                              
IsEqu0:
	inc	x                                                      
	cp	mx,06h                                      
	jp	z,IsEqu1		; jmp if 1 minute time out  
IsRight8:
	rcf
	ret 
IsEqu1:                                                      
	ld	mx,0			; clr the memory 
IsEquE:  
	scf                                      
	ret              
                               
;
;-------------------------------------
; Cate   : Clock
; By     : Hcy
; Func   : is che memory equ 24h
; Desc   : IsEqu24
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
IsEqu24:       
	cp	mx,04h
	jp	z,IsEqu240
	jp	IsRight8                     
IsEqu240:
	push	xl
	inc	x 
	cp	mx,02h            
	pop	xl                           
	jp	z,IsEqu241		; jmp if 1 minute time out  
	jp	IsRight8                                               
IsEqu241:    
        ldpx	mx,0
        ld	mx,0 
	jp	IsEquE

FlashTimeFormat:   
	ld	x,AppFlags
	FAN	mx,HalfSecFlag
	Jp	z,DspHourOff                                             
;-------------------------------------
; Cate   : display
; By     : Hcy
; Func   : display '24:H' or '12:H'
; Desc   : DspTimeFormat
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
DspTimeFormat:
	ld	x,RegKeyFlags
	fan	mx,TimeFormatFlag
	jp	nz,DspTime0		; jmp if 24 hour
	ld	a,1
	ld	x,090h
	calz	DspPattern
	ld	a,2
	calz	DspPattern
	jp	DspTime1
DspTime0:
	ld	a,2
	ld	x,090h
	calz	DspPattern
	ld	a,4
	calz	DspPattern
DspTime1:
	ld	a,0
	calz	DspPattern1		; display 'H'
	ld	a,7
	calz	DspPattern1		; display ' '
	jp	DspColonOn
;-------------------------------------                        
; Cate   : Clock                                              
; By     : Hcy                                                
; Func   : check if up to 1 hour                            
; Desc   : IncMinute                                        
; I/P    : --                                                 
; O/P    : --                                                 
; Destroy:                                                    
; Note   : c=0 if not up to 1 minute, c=1 if up to 1 minute   
IncMinute:                                                   
	ld	x,RTCMin      
	calz	IncByteD    
	ld	x,RTCMin                    
	calz	IsEqu60                    
	ret                                
;
;-------------------------------------                        
; Cate   : Clock                                              
; By     : Hcy                                                
; Func   : check if up to 1 hour                            
; Desc   : IncHour                                        
; I/P    : --                                                 
; O/P    : --                                                 
; Destroy:                                                    
; Note   : c=0 if not up to 24 hour, c=1 if up to 24 hour   
IncHour:                                                   
	ld	x,RTCHour      
	calz	IncByteD    
	ld	x,RTCHour                    
	calz	IsEqu24                    
	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   : 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

⌨️ 快捷键说明

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