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

📄 01lcdclk.s

📁 用SAM72N9写的电子秤文档
💻 S
📖 第 1 页 / 共 4 页
字号:
	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
	
	calz	DspColonOff
	ret
DspI1:	
	calz	DspColonOn
	ret

	
;
SendKeyData:
; remark for new keyboard
;	ld	x,KPort
;	fan	mx,0100b		
	
	ld	x,PPort
	fan	mx,0001b	
	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
 	; add by hcy for receive data after send key 
 	ld	x,CommCount
	ld	mx,4
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
	
;	ld	a,02h
;	ld	xp,a
;	ld	yp,a
;
; 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		; default 12:00 p.m.

	ldpx	mx,0
	ldpx	mx,0		; default 12:00 a.m.
;
; 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
	LD	MY,0000B	; POWER DOWN ,CLK_IN LOW
 	
	
;
;
;
; enable interrupts if any
;
	LD	Y,KPortMask
	LD	MY,0000b	; No key interrupt allowed, 
;
 	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
	
	LD	a,0
	ld	KeyHoldTm,a		; 

	jp	ProgStart
	
	
;	; for test
;	ld	x,RxIcon0
;	ld	a,0fh
;	ld	mx,a
;	inc	x
;	ld	mx,a
;	inc	x
;	ld	mx,a
;	inc	x
;	ld	mx,a
;	call	DspIcons
;	
;	EI
;
; end of initialization
; c =1 if not press'on and off' or 'on and kg'
; c =0 if enter calibrate mode
;ChkCalibrateMode:
;	ld	x,KPort
 ;       fan	mx,IO_Key_On
  ;      jp	z,Calib0		; 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,Calib0		; br if Key_Kg is not preseed
;CalKey0:
;	call	LCDClr
;	call	TurnOnLCD
;	call	Dly125ms
;	ld	x,KPort
 ;       fan	mx,IO_Key_On
  ;      jp	nz,CalKey0		; jmp if key_on is hold
;	
;	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
;	call	SendCalKey
;	
;	; remark by hcy 03-11-26 10:22
;	; turn on all segment
;TurnOnLCD:	
;	LD	x,40h
;LCDClrf:
;	ldpx	mx,0fh
;	cp	xh,07h		; LCD ram from 90 to AFH
;	jp	nz, LCDClrf	
;	call	Dly250
;	call	LCDClr
;	rcf
;	ret
;Calib0:
;	scf
;	ret

;	
; 
; Interrupt handling routines
;------------------------------------------------------
; RTC interrupt routine, 0.5 seconds/intr
IntRTC:
;	Push	A
;	push	F
;	
;	pop	F
;	POP	A
;	EI			; because I is reset when jumping into ISR
	RET
;------------------------------------------------------	
; Key port interrupt routine
IntKPort:
;	PUSH	F
;	PUSH	A
;	PUSH	YL
;	PUSH    YH
;IntKPort0:	
;	ld	Y,KIntFactor
;	ld	a,my		; read and clear the IRQ
	
;	LD	Y,RPort
;	and	my,1101b	; Pull down CLK_IN to ready receive data
;	rcf
;	ld	Y,PPort
;	fan	my,1000b	; only remain P0.3
;	jp	z,IntK0			
;	scf
;IntK0:
;	ld	y,CommBufferL
;	rrc	my
;	ld	y,CommCount
;	rcf
;	sbc	my,1
;	jp	nz,IntK1
	
	
;	ld	y,AppFlags
;	or	my,Rx4BitFlag	; set the 'rx4bitflag'
;	
;	calz	ToDoubleBuffer
;	calz	ReloadCommVar

;IntK1:	
;	LD	Y,RPort
;	or	my,0010b	; Pull up CLK_IN to ready receive data
;	POP	YH
;	POP	YL
;	POP	A
;	POP	F
;	EI			; because I is reset when jumping into ISR
	RET
	
GetIcons:	
	rrc	a
	ld	DigitHBuf,a
	ld	a,0
	rlc	a
	ld	ComDigHBuf,a	
	ret
	
;-------------------------------------
; Cate   : Communication
; By     : Kwan
; Func   : SendKey
; Desc   : Send the key code to Samsung
; I/P    : 
; O/P    :
; Destroy:
; Note   : 1. Wait for the D_Clk=low to place the 
;             data bit to D_Out
;	   2. Wait for the D_Clk = hi again
;	   3. Wait the D_Clk=low to place the data
;		to D_Out until all 4 bit send
;	   4. the sync nibble (0AH) will be sent
;		first and followed by the keycode
;	   5. syn-nibble (=A) will be sent first and 
;		followed by a 4 bit data --> total 8 bits
SendKey:
;	call	SendSynBit
	LD	A,0ah
	CALL	Send4Bit
; Check the time out if neccessary

;	ld	x,RegKeyCode
;	ld	a,mx
	ld	a,KeyCode
	CALL	Send4Bit
;
	ld	y,RPort		; set D_Out Hi after sending
;	or	my,0010b
	or	my,0011b
; Check the time out if neccessary
	RET	
;-------------------------------------------------------	
; Key port and RTC interrupt happened at the same time
;
;=========================================================	
	

	ORG	0200H
ProgStart:
	ld	y,ModeOpt
	fan	my,1111b
	jp	nz,ProgStartLp	; jmp if not clock mode
	ld	y,RTCHourL
	calz	DspHour
	ld	y,RTCMinL
	calz	DspMinute
ProgStartLp:	
	ld	x,TIntFactor
	ld	a,mx		; read and clear any interrupt request flags
	fan	a,0010b		; chk 1/8 sec
	jp	z,ProgStartLp0
	ld	b,KeyCode
	cp	b,Key_Kg
	jp	nz,ProgStartLp0
	inc	KeyHoldTm	; inc the keyhold time
	
ProgStartLp0:	
	fan 	a,0100b			; chk 1/2 sec
	jp	nz,UpdateSecond

ProgStartComm:
	ld	x,ModeOpt
	cp	mx,CLOCKMODE
	jp	z,xProgStartComm	; no comm in clock mode


	LD	X,AppFlags
	FAN	MX,ReqToSendFlag
	JP	z,Comm_Rx
	
	; add these by hcy 03-11-22 10:32
;	ld	a,CommFlag
;	fan	a,1111b	
;	jp	nz,Comm_Rx		; jmp if receiving 
	; add these by hcy 03-11-19 10:50
	call	SendKeyData
	; remark 03-11-22 11:55
;	jp	ProgStartComm
	
;
; Send the data after receiving a command
; remark it by hcy 03-11-13 16:30 for test communication
; 	ld	x,KPort
 ;	fan	mx,0100b	; chk CLK pin
 ;	jp	nz,Comm_Rx	; clk hi-> data send from Samsung
 	
; 	LD	X,RPort
;	LD	MX,0001b	; D_out low

;	CALL	SendKey
 ;	LD	X,AppFlags
 ;	AND	MX,0fh-ReqToSendFlag	; clear the flag after sending

Comm_Rx:
; remark it by hcy 03-11-13 16:32 for test communication
; remark for new keyboard
;	ld	x,KPort
;	fan	mx,0100b	
	
	ld	x,PPort
	fan	mx,0001b		
	jp	z,xProgStartComm	; BR IF low EDGE

;	ld	Y,KIntFactor
;	ld	a,my		; read nad clear the IRQ
;	fan	a,0100b		; chk K02 
;	jp	z,NewProg0
	
	; find a rising edge
	
;	ld	a,1
;	ld	CommFlag,a	; 1--> commflag when receiving 
	
	LD	Y,RPort
	and	my,0001b	; Pull down CLK_IN to ready receive data
; remark by hcy for new keyboard

;	ld	Y,PPort
;	ld	a,my
;	rlc	a

; add hcy for new keyboard
	ld	Y,PPort
	ld	a,my
	rrc	a
	rrc	a		; p0.1 --> c

	ld	y,CommBufferL
	rrc	my		; load data in buffer

	LD	Y,RPort
;	or	my,0010b	; Pull up CLK_IN to ready receive data
	or	my,0011b	; if '0010b' 0--> r00, 

	ld	y,CommCount	; dec count
	ADD	my,0FH		;
	jp	nz,ProgStartLp	; don't chk key until end of a nibble
	
	CALl	ToRecBuffer
	call	ReloadCommVar
	ld	x,RxNibbleCnt
	add	mx,1		

	ld	x,RxNibbleCnt
	cp	mx,1		
	jp	nz,Prog3	; jmp if not finish receiving start code
	call	IsEquStartCode
	jp	nc,xProgStartComm ; jmp if equ start code
	
	; add by hcy 03-11-25 17:36
	cp	my,0Dh
	jp	z,TurnOffPwr
	
	; error case 
	jp	CommE		; give up this communication
Prog3:
; remark by hcy 03-11-20 10:34
;	cp	mx,2
;	jp	nz,Prog4	; jmp if not or already finish receiving command
;	calz	IsRightCmd
;	jp	nc,xProgStartComm
	
	; error case
;	jp	CommE		; give up this communication
Prog4:		
;	jp	c,xProgStartComm	; jmp if not finish receiving command
	ld	x,SumNumRxNibble
	add	mx,0fh		; -1
	jp	nz,xProgStartComm	; jmp if not receive all data
; completely received a command
	ld	x,SumNumRxNibble
	ld	mx,0dh			; total receive 13 nibble data

	LD	X,AppFlags
	FAN	MX,ReqToSendFlag
	JP	z,Prog5		; br if no send request

Comm_Tx:
	call	SendKeyData
;       
Prog5:	
	calz	DspWeight
	call	DspIcons
	calz	DspFraction

CommE:
	ld	x,RxNibbleCnt
	ld	mx,0
;	JP	xProgStartComm
;----------------------------------------
xProgStartComm:
;
; here for checking the keyboard
;
	; add by hcy disable enter calbrate mode from weighting mdoe
	
	ld	x,ModeOpt
	cp	mx,CLOCKMODE
	jp	nz,NewCalM0	; jmp if not clock mode
	; add by hcy 03-12-4 11:02 for calibrate mode
	call	ChkCalibrateMode
	jp	nc,ProgStart	; jmp if enter calibrate mode
	
NewCalM0:	
	CALl	KeyScan
	LD	X,RegKeyFlags
	FAN	MX,NewKeyFlag
	jp	z,ProgStartLp		; br if no key pressed before
;
	JP	Main_KeyHandle		; br if key press-hold and release
;
; Flash the colon per 0.5 second
;
UpdateSecond:
	; add by hcy 03-12-4 14:19
	ld	a,Tmr2s
	fan	a,1111b
	jp	z,UpdateS0
	dec	Tmr2s
UpdateS0:
	call	ToggleHalfSecFlag

	calz	FlashColon
	
	ld	x,AppFlags
	fan	mx,SecClickFlag
	jp	z,ProgStartComm		; br if just 0.5 sec
;	
	and	mx,0fh-SecClickFlag	; clear the bit
; update the clock per 1 min
;	
	calz	IncSecond
	jp	nc,ProgStartComm		; No display update if change in second only
	calz	IncMinute
;	jp	nc,xUpdateClk
	jp	nc,ProgStart
	calz	IncHour
xUpdateClk:
;
; depends on which mode to show the time
;
	; remark by hcy 03-11-20 19:41
	jp	ProgStart
	; add by hcy 03-11-20 19:41
;	jp	ProgStartLp

;-------------------------------------
; Cate   : Delay
; By     : Hcy
; Func   : delay 20 ms
; Desc   : Dly20ms
; I/P    : 32*17*0.03125 = 17ms
; O/P    : --
; Destroy: y
; Note   :
;Dly17ms:
;	ld	y,0
;Dlym1:
;	inc	y
;	cp	yh,02h
;	jp	nz,Dlym1
;	ret

;SetTmr1s:
;	ld	x,RegKeyFlags
;	or	mx,DisFlashFlag		; disable flash 
;	ld	a,2
;	ld	Tmr1s,a
;	ret

ClrKeyVar:
	LD	a,0
	ld	KeyCode,a		; clr the key code
	
ClrKeyHoldTm:
	ld	a,0
	ld	KeyHoldTm,a		; reset timer
	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


;
;;======================================
; Key handling from here after
;
; Press and hold Kg > 2 seconds to enter the clock setting mode
; the Hour digits will be firstly flashed and use the ekys
; 1. Key_ml to toggle 12/24 mode
; 2. Key_kg to select  hour-adjusting
; 3. press the Key_ml to increment the hour
; 4. Press the Key_Kg to confirm the hour and select minute-adjusting
; 5. Press the Key_ml to increment the minute
; 6. Press the Key_Kg to complete the time setting.
; 
; Remark: turn off the ADC power in Clock/Clock setting  mode
; 	  no colon/second counting during clock setting mode
;         clear the second register after setting
;
Main_KeyHandle:
	LD	A,KeyCode
	CP	A,Key_On
	JP	z,GetKey_On
	CP	A,Key_Kg
	JP	z,GetKey_Kg
	CP	A,Key_ml

⌨️ 快捷键说明

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