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

📄 r08cnvlcdclk.ms

📁 用SAM72N9写的电子秤文档
💻 MS
📖 第 1 页 / 共 5 页
字号:
.stabn 1529, LineInfo
	call	LCDClr

;		
; Check the warm start words if necessary
; 
; 
; clr RAM for Cold start here(200h - 23fh)
.stabn 1536, LineInfo
	ld	x,0
RAMClr:
.stabn 1538, LineInfo
	ldpx	mx,0
.stabn 1539, LineInfo
	cp	xh,4
.stabn 1540, LineInfo
	jp	nz,RAMClr
;
; set time to 12:00 after cold start
;
.stabn 1544, LineInfo
	ld	x,(0x14)
.stabn 1545, LineInfo
	ldpx	mx,2		; hour=12, min/sec cleared by RAMCLr
.stabn 1546, LineInfo
	ldpx	mx,1	
;
; define I/O port
.stabn 1549, LineInfo
	LD	Y,(0x0EE)
.stabn 1550, LineInfo
	LD	MY,0b0000	; P-port  as input
;
.stabn 1552, LineInfo
	LD	Y,(0x0EB)
	; 03-11-22 14:04 HCY
.stabn 1554, LineInfo
	LD	MY,0b0010	; Power down, CLK_IN default high
	
	
;
;
;
; enable interrupts if any
;
.stabn 1562, LineInfo
	LD	Y,(0x0E5)
.stabn 1563, LineInfo
	LD	MY,0b0100	; No key interrupt allowed, only the D_Clk
;
.stabn 1565, LineInfo
 	LD	Y,(0x0E8)
.stabn 1566, LineInfo
 	LD	MY,0b0000	; No timer interrupt allowed
;
.stabn 1568, LineInfo
	LD	Y,(0x0EE)	; reset timer
.stabn 1569, LineInfo
	LD	MY,0b0100
;
.stabn 1571, LineInfo
	ld	y,(0x1c)
.stabn 1572, LineInfo
	ld	my,0
.stabn 1573, LineInfo
	ld	y,(0x17)
.stabn 1574, LineInfo
	ld	my,0x04
;
.stabn 1576, LineInfo
	ld	y,(0x31)
;	ld	my,WEIGHTMODE		
.stabn 1578, LineInfo
	ld	my,(0)
	
.stabn 1580, LineInfo
	ld	x,(0x30)
.stabn 1581, LineInfo
	ld	mx,0x0d			; total receive 13 nibble data
	
	
;	; 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
.stabn 1599, LineInfo
	ld	x,(0x0E3)
.stabn 1600, LineInfo
        fan	mx,(1)
.stabn 1601, LineInfo
        jp	z,ProgStart		; jmp if key_on is not pressed
	
.stabn 1603, LineInfo
	ld	B,(0b0110)
.stabn 1604, LineInfo
	fan	mx,(2)
.stabn 1605, LineInfo
	jp	nz,CalKey0		; br if Key_off is preseed
;	
.stabn 1607, LineInfo
	ld	b,(0b0101)
.stabn 1608, LineInfo
	ld	x,(0x0ED)
.stabn 1609, LineInfo
	fan	mx,(1)
.stabn 1610, LineInfo
	jp	z,ProgStart		; br if Key_Kg is not preseed
CalKey0:
	
.stabn 1613, LineInfo
	LD	Y,(0x0EB)
	; 03-11-22 14:04 HCY
.stabn 1615, LineInfo
	LD	MY,0b0011	; Power on, CLK_IN default high
.stabn 1616, LineInfo
	call	Dly125ms
.stabn 1617, LineInfo
	call	Dly125ms
	
.stabn 1619, LineInfo
	ld	x,(0x31)
.stabn 1620, LineInfo
	ld	mx,(2)

WaitSend0:	
.stabn 1623, LineInfo
	ld	x,(0x0E3)
.stabn 1624, LineInfo
	fan	mx,0b0100		
.stabn 1625, LineInfo
	jp	nz,WaitSend0	; BR IF D_CLK is high
	
.stabn 1627, LineInfo
	LD	(M3),B
.stabn 1628, LineInfo
	call	SendCalKey
	
	; remark by hcy 03-11-26 10:22
	; turn on all segment
	
.stabn 1633, LineInfo
	LD	x,0x040
LCDClrf:
.stabn 1635, LineInfo
	ldpx	mx,0x0f
.stabn 1636, LineInfo
	cp	xh,0x07		; LCD ram from 40 to 6FH
.stabn 1637, LineInfo
	jp	nz, LCDClrf
	
.stabn 1639, LineInfo
	call	Dly250
.stabn 1640, LineInfo
	call	LCDClr
.stabn 1641, LineInfo
	jp	ProgStart
;	
; 
; 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
.stabn 1654, LineInfo
	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
.stabn 1696, LineInfo
	RET
	
GetIcons:	
.stabn 1699, LineInfo
	rrc	a
.stabn 1700, LineInfo
	ld	(M7),a
.stabn 1701, LineInfo
	ld	a,0
.stabn 1702, LineInfo
	rlc	a
.stabn 1703, LineInfo
	ld	(M6),a	
.stabn 1704, LineInfo
	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
.stabn 1725, LineInfo
	LD	A,0x0a
.stabn 1726, LineInfo
	CALL	Send4Bit
; Check the time out if neccessary
.stabn 1728, LineInfo
	LD	X,(3)
.stabn 1729, LineInfo
	LD	A,MX
.stabn 1730, LineInfo
	CALL	Send4Bit
;
.stabn 1732, LineInfo
	ld	y,(0x0EB)		; set D_Out Hi after sending
;	or	my,0010b
.stabn 1734, LineInfo
	or	my,0b0011
; Check the time out if neccessary
.stabn 1736, LineInfo
	RET	
;-------------------------------------------------------	
; Key port and RTC interrupt happened at the same time
;
;=========================================================	
	

	.org	0x0200
ProgStart:
.stabn 1745, LineInfo
	ld	y,(0x31)
.stabn 1746, LineInfo
	fan	my,0b1111
.stabn 1747, LineInfo
	jp	nz,ProgStartLp	; jmp if not clock mode
.stabn 1748, LineInfo
	ld	y,(0x14)
.stabn 1749, LineInfo
	calz	DspHour
.stabn 1750, LineInfo
	ld	y,(0x12)
.stabn 1751, LineInfo
	calz	DspMinute
ProgStartLp:	
.stabn 1753, LineInfo
	ld	x,(0x0E9)
.stabn 1754, LineInfo
	ld	a,mx		; read and clear any interrupt request flags
.stabn 1755, LineInfo
	fan	a,0b0010		; chk 1/8 sec
.stabn 1756, LineInfo
	jp	z,ProgStartLp0
.stabn 1757, LineInfo
	inc	(M0)	; inc the keyhold time
	
ProgStartLp0:	
.stabn 1760, LineInfo
	fan 	a,0b0100			; chk 1/2 sec
.stabn 1761, LineInfo
	jp	nz,UpdateSecond

ProgStartComm:
.stabn 1764, LineInfo
	ld	x,(0x31)
.stabn 1765, LineInfo
	cp	mx,(0)
.stabn 1766, LineInfo
	jp	z,xProgStartComm	; no comm in clock mode


.stabn 1769, LineInfo
	LD	X,(0x16)
.stabn 1770, LineInfo
	FAN	MX,(4)
.stabn 1771, LineInfo
	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
.stabn 1778, LineInfo
	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	
.stabn 1798, LineInfo
	ld	x,(0x0E3)
.stabn 1799, LineInfo
	fan	mx,0b0100		
.stabn 1800, LineInfo
	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 
	
.stabn 1812, LineInfo
	LD	Y,(0x0EB)
.stabn 1813, LineInfo
	and	my,0b0001	; Pull down CLK_IN to ready receive data
.stabn 1814, LineInfo
	ld	Y,(0x0ED)
.stabn 1815, LineInfo
	ld	a,my
.stabn 1816, LineInfo
	rlc	a

.stabn 1818, LineInfo
	ld	y,(0x1c)
.stabn 1819, LineInfo
	rrc	my		; load data in buffer

.stabn 1821, LineInfo
	LD	Y,(0x0EB)
;	or	my,0010b	; Pull up CLK_IN to ready receive data
.stabn 1823, LineInfo
	or	my,0b0011	; if '0010b' 0--> r00, 

.stabn 1825, LineInfo
	ld	y,(0x17)	; dec count
.stabn 1826, LineInfo
	ADD	my,0x0F		;
.stabn 1827, LineInfo
	jp	nz,ProgStartLp	; don't chk key until end of a nibble
	
.stabn 1829, LineInfo
	CALl	ToRecBuffer
.stabn 1830, LineInfo
	call	ReloadCommVar
.stabn 1831, LineInfo
	ld	x,(0x1d)
.stabn 1832, LineInfo
	add	mx,1		

.stabn 1834, LineInfo
	ld	x,(0x1d)
.stabn 1835, LineInfo
	cp	mx,1		
.stabn 1836, LineInfo
	jp	nz,Prog3	; jmp if not finish receiving start code
.stabn 1837, LineInfo
	call	IsEquStartCode
.stabn 1838, LineInfo
	jp	nc,xProgStartComm ; jmp if equ start code
	
	; add by hcy 03-11-25 17:36
.stabn 1841, LineInfo
	cp	my,0x0D
.stabn 1842, LineInfo
	jp	z,TurnOffPwr
	
	; error case 
.stabn 1845, LineInfo
	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
.stabn 1857, LineInfo
	ld	x,(0x30)
.stabn 1858, LineInfo
	add	mx,0x0f		; -1
.stabn 1859, LineInfo
	jp	nz,xProgStartComm	; jmp if not receive all data
; completely received a command
.stabn 1861, LineInfo
	ld	x,(0x30)
.stabn 1862, LineInfo
	ld	mx,0x0d			; total receive 13 nibble data
	
;	ld	a,0
;	ld	CommFlag,a	; 0--> commflag when finish receiving 
	
.stabn 1867, LineInfo
	LD	X,(0x16)
.stabn 1868, LineInfo
	FAN	MX,(4)
.stabn 1869, LineInfo
	JP	z,Prog5		; br if no send request

;	LD	X,RPort
;	LD	MX,0001b	; D_out low
Comm_Tx:

; Send the data after receiving a command
; 	CALL	SendKey
;	LD	X,AppFlags
 ;	AND	MX,0fh-ReqToSendFlag	; clear the flag after sending
 
.stabn 1880, LineInfo
 	call	SendKeyData
;       
Prog5:	
.stabn 1883, LineInfo
	call	DspWeight
.stabn 1884, LineInfo
	call	DspIcons
.stabn 1885, LineInfo
	call	DspFraction
CommE:
.stabn 1887, LineInfo
	ld	x,(0x1d)
.stabn 1888, LineInfo
	ld	mx,0
.stabn 1889, LineInfo
	JP	xProgStartComm
;----------------------------------------
xProgStartComm:
;
; here for checking the keyboard
;
.stabn 1895, LineInfo
	CALl	KeyScan
.stabn 1896, LineInfo
	LD	X,(1)
.stabn 1897, LineInfo
	FAN	MX,(2)
.stabn 1898, LineInfo
	jp	z,ProgStartLp		; br if no key pressed before
;
.stabn 1900, LineInfo
	JP	Main_KeyHandle		; br if key press-hold and release
;
; Flash the colon per 0.5 second
;
UpdateSecond:
	
.stabn 1906, LineInfo
	call	ToggleHalfSecFlag

.stabn 1908, LineInfo
	calz	FlashColon
;
.stabn 1910, LineInfo
	ld	x,(0x16)
.stabn 1911, LineInfo
	fan	mx,(2)
.stabn 1912, LineInfo
	jp	z,ProgStartComm		; br if just 0.5 sec
;	
.stabn 1914, LineInfo
	and	mx,0x0f-(2)	; clear the bit
; update the clock per 1 min
;	
.stabn 1917, LineInfo
	calz	IncSecond
.stabn 1918, LineInfo
	jp	nc,ProgStartComm		; No display update if change in second only
.stabn 1919, LineInfo
	calz	IncMinute
.stabn 1920, LineInfo
	jp	nc,xUpdateClk
.stabn 1921, LineInfo
	calz	IncHour
xUpdateClk:
;
; depends on which mode to show the time
;
	; remark by hcy 03-11-20 19:41
.stabn 1927, LineInfo
	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:
.stabn 1941, LineInfo
	ld	y,0
Dlym1:
.stabn 1943, LineInfo
	inc	y
.stabn 1944, LineInfo
	cp	yh,0x02
.stabn 1945, LineInfo
	jp	nz,Dlym1
.stabn 1946, LineInfo
	ret

SetTmr1s:
.stabn 1949, LineInfo
	ld	x,(1)
.stabn 1950, LineInfo
	or	mx,(4)		; disable flash 
.stabn 1951, LineInfo
	ld	a,2
.stabn 1952, LineInfo
	ld	(M8),a
.stabn 1953, LineInfo
	ret

;-------------------------------------
; Cate   : Delay
; By     : Hcy
; Func   : delay 125ms
; Desc   : Dly125ms
; I/P    : --
; O/P    : --
; Destroy:
; Note   :
;
Dly125ms:
.stabn 1966, LineInfo
	ld	x,0
Dlym0:
.stabn 1968, LineInfo
	inc	x
.stabn 1969, LineInfo
	cp	xh,0x0f
.stabn 1970, LineInfo
	jp	nz,Dlym0
.stabn 1971, LineInfo
	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:
.stabn 1991, LineInfo
	LD	A,(M3)
.stabn 1992, LineInfo
	CP	A,(0b0111)
.stabn 1993, LineInfo
	JP	z,GetKey_On
.stabn 1994, LineInfo
	CP	A,(0b1101)
.stabn 1995, LineInfo
	JP	z,GetKey_Kg
.stabn 1996, LineInfo
	CP	A,(0b1011)
.stabn 1997, LineInfo
	JP	z,GetKey_ml
.stabn 1998, LineInfo
	CP	A,(0b1110)
.stabn 1999, LineInfo
	JP	z,GetKey_Off
.stabn 2000, LineInfo
	JP	ProgStartLp

⌨️ 快捷键说明

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