📄 kclock.ms
字号:
;
;
; clr RAM for Cold start here
.stabn 1399, LineInfo
ld x,0
RAMClr:
.stabn 1401, LineInfo
ldpx mx,0
.stabn 1402, LineInfo
cp xh,5
.stabn 1403, LineInfo
jp nz,RAMClr
;
; set time to 12:00 after cold start
;
.stabn 1407, LineInfo
ld x,(0x14)
.stabn 1408, LineInfo
ldpx mx,2 ; hour=12, min/sec cleared by RAMCLr
.stabn 1409, LineInfo
ldpx mx,1
;
; define I/O port
.stabn 1412, LineInfo
LD Y,(0x0FC)
.stabn 1413, LineInfo
LD MY,0b0000 ; P-port as input
;
.stabn 1415, LineInfo
LD Y,(0x0F3)
; 03-11-22 14:04 HCY
.stabn 1417, LineInfo
LD MY,0b0010 ; Power down, CLK_IN default high
;
;
;
; enable interrupts if any
;
.stabn 1425, LineInfo
LD Y,(0x0E8)
.stabn 1426, LineInfo
LD MY,0b0100 ; No key interrupt allowed, only the D_Clk
;
.stabn 1428, LineInfo
LD Y,(0x0EB)
.stabn 1429, LineInfo
LD MY,0b0000 ; No timer interrupt allowed
;
.stabn 1431, LineInfo
LD Y,(0x0F9) ; reset timer
.stabn 1432, LineInfo
LD MY,0b0100
;
.stabn 1434, LineInfo
ld y,(0x1c)
.stabn 1435, LineInfo
ld my,0
.stabn 1436, LineInfo
ld y,(0x17)
.stabn 1437, LineInfo
ld my,0x04
;
.stabn 1439, LineInfo
ld y,(0x33)
; ld my,WEIGHTMODE
.stabn 1441, LineInfo
ld my,(0)
.stabn 1444, LineInfo
ld x,(0x31)
.stabn 1445, LineInfo
ld mx,0x0d ; total receive 13 nibble data
;
; EI
;
; end of initialization
.stabn 1450, LineInfo
ld x,(0x0E0)
.stabn 1451, LineInfo
fan mx,(1)
.stabn 1452, LineInfo
jp z,ProgStart ; jmp if key_on is not pressed
.stabn 1454, LineInfo
ld B,(0b0110)
.stabn 1455, LineInfo
fan mx,(2)
.stabn 1456, LineInfo
jp nz,CalKey0 ; br if Key_off is preseed
;
.stabn 1458, LineInfo
ld b,(0b0101)
.stabn 1459, LineInfo
ld x,(0x0F6)
.stabn 1460, LineInfo
fan mx,(1)
.stabn 1461, LineInfo
jp z,ProgStart ; br if Key_Kg is not preseed
CalKey0:
.stabn 1464, LineInfo
LD Y,(0x0F3)
; 03-11-22 14:04 HCY
.stabn 1466, LineInfo
LD MY,0b0011 ; Power on, CLK_IN default high
.stabn 1467, LineInfo
call Dly125ms
.stabn 1468, LineInfo
call Dly125ms
.stabn 1470, LineInfo
ld x,(0x33)
.stabn 1471, LineInfo
ld mx,(2)
WaitSend0:
.stabn 1474, LineInfo
ld x,(0x0E0)
.stabn 1475, LineInfo
fan mx,0b0100
.stabn 1476, LineInfo
jp nz,WaitSend0 ; BR IF D_CLK is high
.stabn 1478, LineInfo
LD (M3),B
.stabn 1479, LineInfo
call SendCalKey
; remark by hcy 03-11-26 10:22
; turn on all segment
.stabn 1484, LineInfo
LD x,0x90
LCDClrf:
.stabn 1486, LineInfo
ldpx mx,0x0f
.stabn 1487, LineInfo
cp xh,0x0b ; LCD ram from 90 to AFH
.stabn 1488, LineInfo
jp nz, LCDClrf
.stabn 1490, LineInfo
call Dly250
.stabn 1491, LineInfo
call LCDClr
.stabn 1492, LineInfo
jp ProgStart
;
;
; Interrupt handling routines
;------------------------------------------------------
; RTC interrupt routine, 0.5 seconds/intr
IntRTC:
; Push A
; push F
;
; pop F
; POP A
.stabn 1504, LineInfo
EI ; because I is reset when jumping into ISR
.stabn 1505, 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
.stabn 1546, LineInfo
EI ; because I is reset when jumping into ISR
.stabn 1547, LineInfo
RET
;-------------------------------------------------------
; Key port and RTC interrupt happened at the same time
;
;=========================================================
.org 0x0200
ProgStart:
.stabn 1556, LineInfo
ld y,(0x33)
.stabn 1557, LineInfo
fan my,0b1111
.stabn 1558, LineInfo
jp nz,ProgStartLp ; jmp if not clock mode
.stabn 1559, LineInfo
ld y,(0x14)
.stabn 1560, LineInfo
calz DspHour
.stabn 1561, LineInfo
ld y,(0x12)
.stabn 1562, LineInfo
calz DspMinute
ProgStartLp:
.stabn 1564, LineInfo
ld x,(0x0EF)
.stabn 1565, LineInfo
ld a,mx ; read and clear any interrupt request flags
.stabn 1566, LineInfo
fan a,0b0010 ; chk 1/8 sec
.stabn 1567, LineInfo
jp z,ProgStartLp0
.stabn 1568, LineInfo
inc (M0) ; inc the keyhold time
ProgStartLp0:
.stabn 1571, LineInfo
fan a,0b0100 ; chk 1/2 sec
.stabn 1572, LineInfo
jp nz,UpdateSecond
ProgStartComm:
.stabn 1575, LineInfo
ld x,(0x33)
.stabn 1576, LineInfo
cp mx,(0)
.stabn 1577, LineInfo
jp z,xProgStartComm ; no comm in clock mode
.stabn 1580, LineInfo
LD X,(0x16)
.stabn 1581, LineInfo
FAN MX,(4)
.stabn 1582, 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 1589, 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 1609, LineInfo
ld x,(0x0E0)
.stabn 1610, LineInfo
fan mx,0b0100
.stabn 1611, 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 1623, LineInfo
LD Y,(0x0F3)
.stabn 1624, LineInfo
and my,0b0001 ; Pull down CLK_IN to ready receive data
.stabn 1625, LineInfo
ld Y,(0x0F6)
.stabn 1626, LineInfo
ld a,my
.stabn 1627, LineInfo
rlc a
.stabn 1629, LineInfo
ld y,(0x1c)
.stabn 1630, LineInfo
rrc my ; load data in buffer
.stabn 1632, LineInfo
LD Y,(0x0F3)
; or my,0010b ; Pull up CLK_IN to ready receive data
.stabn 1634, LineInfo
or my,0b0011 ; if '0010b' 0--> r00,
.stabn 1636, LineInfo
ld y,(0x17) ; dec count
.stabn 1637, LineInfo
ADD my,0x0F ;
.stabn 1638, LineInfo
jp nz,ProgStartLp ; don't chk key until end of a nibble
.stabn 1640, LineInfo
CALl ToRecBuffer
.stabn 1641, LineInfo
call ReloadCommVar
.stabn 1642, LineInfo
ld x,(0x1d)
.stabn 1643, LineInfo
add mx,1
.stabn 1645, LineInfo
ld x,(0x1d)
.stabn 1646, LineInfo
cp mx,1
.stabn 1647, LineInfo
jp nz,Prog3 ; jmp if not finish receiving start code
.stabn 1648, LineInfo
call IsEquStartCode
.stabn 1649, LineInfo
jp nc,xProgStartComm ; jmp if equ start code
; add by hcy 03-11-25 17:36
.stabn 1652, LineInfo
cp my,0x0D
.stabn 1653, LineInfo
jp z,TurnOffPwr
; error case
.stabn 1656, 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 1668, LineInfo
ld x,(0x31)
.stabn 1669, LineInfo
add mx,0x0f ; -1
.stabn 1670, LineInfo
jp nz,xProgStartComm ; jmp if not receive all data
; completely received a command
.stabn 1672, LineInfo
ld x,(0x31)
.stabn 1673, LineInfo
ld mx,0x0d ; total receive 13 nibble data
; ld a,0
; ld CommFlag,a ; 0--> commflag when finish receiving
.stabn 1678, LineInfo
LD X,(0x16)
.stabn 1679, LineInfo
FAN MX,(4)
.stabn 1680, LineInfo
JP z,Prog5 ; br if no send request
Comm_Tx:
.stabn 1683, LineInfo
call SendKeyData
;
Prog5:
.stabn 1686, LineInfo
calz DspWeight
.stabn 1687, LineInfo
call DspIcons
.stabn 1688, LineInfo
calz DspFraction
CommE:
.stabn 1690, LineInfo
ld x,(0x1d)
.stabn 1691, LineInfo
ld mx,0
.stabn 1692, LineInfo
JP xProgStartComm
;----------------------------------------
xProgStartComm:
;
; here for checking the keyboard
;
.stabn 1698, LineInfo
CALl KeyScan
.stabn 1699, LineInfo
LD X,(1)
.stabn 1700, LineInfo
FAN MX,(2)
.stabn 1701, LineInfo
jp z,ProgStartLp ; br if no key pressed before
;
.stabn 1703, LineInfo
JP Main_KeyHandle ; br if key press-hold and release
;
; Flash the colon per 0.5 second
;
UpdateSecond:
.stabn 1709, LineInfo
call ToggleHalfSecFlag
.stabn 1711, LineInfo
calz FlashColon
;
.stabn 1713, LineInfo
ld x,(0x16)
.stabn 1714, LineInfo
fan mx,(2)
.stabn 1715, LineInfo
jp z,ProgStartComm ; br if just 0.5 sec
;
.stabn 1717, LineInfo
and mx,0x0f-(2) ; clear the bit
; update the clock per 1 min
;
.stabn 1720, LineInfo
calz IncSecond
.stabn 1721, LineInfo
jp nc,ProgStartComm ; No display update if change in second only
.stabn 1722, LineInfo
calz IncMinute
.stabn 1723, LineInfo
jp nc,xUpdateClk
.stabn 1724, LineInfo
calz IncHour
xUpdateClk:
;
; depends on which mode to show the time
;
; remark by hcy 03-11-20 19:41
.stabn 1730, LineInfo
jp ProgStart
; add by hcy 03-11-20 19:41
; jp ProgStartLp
;
;;======================================
; 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 1751, LineInfo
LD A,(M3)
.stabn 1752, LineInfo
CP A,(0b0111)
.stabn 1753, LineInfo
JP z,GetKey_On
.stabn 1754, LineInfo
CP A,(0b1101)
.stabn 1755, LineInfo
JP z,GetKey_Kg
.stabn 1756, LineInfo
CP A,(0b1011)
.stabn 1757, LineInfo
JP z,GetKey_ml
.stabn 1758, LineInfo
CP A,(0b1110)
.stabn 1759, LineInfo
JP z,GetKey_Off
.stabn 1760, LineInfo
JP ProgStartLp
;
GetKey_On:
; for testing
.stabn 1765, LineInfo
LD X,(1)
.stabn 1766, LineInfo
FAN MX,(1)
.stabn 1767, LineInfo
JP nz,ProgStartLp ; still key hold
.stabn 1768, LineInfo
AND MX,0x0f-(2) ; process the key & clr the flag
.stabn 1770, LineInfo
ld x,(0x33)
.stabn 1771, LineInfo
fan mx,0x0f
.stabn 1772, LineInfo
jp nz,GetK0 ; jmp if not clock mode
.stabn 1774, LineInfo
ld y,(0x0F3) ; set D_Out Hi after sending
.stabn 1775, LineInfo
or my,0b0011 ; turn on power to samsung clk_in default high
.stabn 1776, LineInfo
add mx,1
.stabn 1777, LineInfo
CALl LCDClr
.stabn 1778, LineInfo
LD X,(0x16)
.stabn 1779, LineInfo
AND MX,0x0f-(4) ; clear the flag after sending
.stabn 1780, LineInfo
call Dly125ms
.stabn 1781, LineInfo
call Dly125ms
.stabn 1782, LineInfo
call ReloadCommVar
.stabn 1783, LineInfo
ld x,(0x31)
.stabn 1784, LineInfo
ld mx,0x0d
.stabn 1785, LineInfo
ld x,(0x1d)
.stabn 1786, LineInfo
ld mx,0
.stabn 1787, LineInfo
jp ProgStart ; to show Clock
GetK0:
.stabn 1790, LineInfo
LD (M4),B ;
.stabn 1791, LineInfo
LD X,(0x16)
.stabn 1792, LineInfo
OR MX,(4)
.stabn 1793, LineInfo
jp ProgStartLp
GetKey_ml:
.stabn 1798, LineInfo
LD X,(1)
.stabn 1799, LineInfo
FAN MX,(1)
.stabn 1800, LineInfo
JP nz,ProgStartLp ; still key hold
.stabn 1801, LineInfo
AND MX,0x0f-(2) ; process the key & clr the flag
;
; process the ml key here after
; LD SendData,B ;
; LD X,AppFlags
; OR MX,ReqToSendFlag
; JP ProgStartLp
.stabn 1810, LineInfo
jp GetK0
;
; process the Off key here after
GetKey_Off:
; LD SendData,B ;
; LD X,AppFlags
; OR MX,ReqToSendFlag
.stabn 1818, LineInfo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -