📄 kclock.s.bak
字号:
call SendCalKey
; remark by hcy 03-11-26 10:22
; turn on all segment
LD x,90h
LCDClrf:
ldpx mx,0fh
cp xh,0bh ; LCD ram from 90 to AFH
jp nz, LCDClrf
call Dly250
call LCDClr
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
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
;-------------------------------------------------------
; 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
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
ld x,KPort
fan mx,0100b
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
ld Y,PPort
ld a,my
rlc a
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 a,0
; ld CommFlag,a ; 0--> commflag when finish receiving
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
;
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:
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
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
;
;;======================================
; 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
JP z,GetKey_ml
CP A,Key_Off
JP z,GetKey_Off
JP ProgStartLp
;
GetKey_On:
; for testing
LD X,RegKeyFlags
FAN MX,KeyHoldFlag
JP nz,ProgStartLp ; still key hold
AND MX,0fh-NewKeyFlag ; process the key & clr the flag
ld x,ModeOpt
fan mx,0fh
jp nz,GetK0 ; jmp if not clock mode
ld y,RPort ; set D_Out Hi after sending
or my,0011b ; turn on power to samsung clk_in default high
add mx,1
CALl LCDClr
LD X,AppFlags
AND MX,0fh-ReqToSendFlag ; clear the flag after sending
call Dly125ms
call Dly125ms
call ReloadCommVar
ld x,SumNumRxNibble
ld mx,0dh
ld x,RxNibbleCnt
ld mx,0
jp ProgStart ; to show Clock
GetK0:
LD SendData,B ;
LD X,AppFlags
OR MX,ReqToSendFlag
jp ProgStartLp
GetKey_ml:
LD X,RegKeyFlags
FAN MX,KeyHoldFlag
JP nz,ProgStartLp ; still key hold
AND MX,0fh-NewKeyFlag ; process the key & clr the flag
;
; process the ml key here after
; LD SendData,B ;
; LD X,AppFlags
; OR MX,ReqToSendFlag
; JP ProgStartLp
jp GetK0
;
; process the Off key here after
GetKey_Off:
; LD SendData,B ;
; LD X,AppFlags
; OR MX,ReqToSendFlag
ld x,ModeOpt
cp mx,CLOCKMODE
jp z,ProgStartLp
TurnOffPwr:
ld a,0
ld KeyCode,a
ld x,ModeOpt
ld mx,CLOCKMODE ; Reset modeOpt if not valid
CALl LCDClr
ld y,RPort ; set D_Out Hi after sending
and my,0010b ; turn off POWER_CONTROL
jp ProgStart
;
GetKey_Kg:
LD Y,ModeOpt
CP MY,CLOCKMODE
; JP nz,WeigthKey_Kg ; br if not clock mode
jp nz,GetKey_ml ; br if not clock mode
ld X,RegKeyFlags
fan MX,KeyHoldFlag
jp nz,GetKey_Kg0 ; br to check the hold time
AND MX,0fh-NewKeyFlag ; ignor the key
LD a,0
ld KeyHoldTm,a ; reset timer
jp ProgStartLp
;
; starting from here if the key hold time > 2 seconds
;
GetKey_Kg0:
ld a,KeyHoldTm
cp a,0fh ; tolerance -1/8 sec
jp nz,ProgStartLp ; br if Hold time < 2 seconds
ld x,RegKeyFlags
and mx,0fh-NewKeyFlag ; clear the flag
;
; Time setting mode from here on
ld a,Key_Nil
ld KeyCode,a ; clr key code
ld X,RegKeyFlags
AND MX,0fh-DisFlashFlag ; clr the key
ld x,RTCMinL
ld y,TmpRTCMinuteL
call Copy2Byte
calz DspColonOn
TimeSet:
ld X,RegKeyFlags
FAN MX,DisFlashFlag
jp nz,TimeSett0
ld y,TmpRTCHourL
calz FlashHour
TimeSett0:
call ChkTimer
LD A,KeyCode
CP A,Key_Kg
JP z,UTimeSet0 ;; jmp to setting minute
CP A,Key_ml
jp z,TimeSet1 ; jmp to setting increase hour
jp TimeSet
TimeSet1:
ld X,RegKeyFlags
; OR MX,DisFlashFlag
fan MX,KeyHoldFlag
jp nz,TimeSet2 ; br to check the hold time
AND MX,0fh-NewKeyFlag ; clr the key
AND MX,0fh-DisFlashFlag ; clr the key
LD a,0
ld KeyHoldTm,a ; reset timer
ld KeyCode,a ; clr the key code
HTimeSet:
call IncSetHour
jp TimeSet
TimeSet2:
;
; starting from here if the key hold time > 2 seconds
;
OR MX,DisFlashFlag
ld a,KeyHoldTm
cp a,0fh ; tolerance -1/8 sec
jp nz,TimeSet ; br if Hold time < 2 seconds
ld a,0dh
ld KeyHoldTm,a ;
jp HTimeSet
; call IncSetHour ;
; jp TimeSet
UTimeSet0:
ld X,RegKeyFlags
AND MX,0fh-DisFlashFlag ; clr the key
ld a,Key_Nil
ld KeyCode,a ; clr key code
TimeSet0:
ld y,TmpRTCHourL
calz DspHour
calz DspColonOn
ld X,RegKeyFlags
FAN MX,DisFlashFlag
jp nz,MTime0
ld y,TmpRTCMinuteL
calz FlashMinute
MTime0:
call ChkTimer
LD A,KeyCode
CP A,Key_Kg
JP z,MTimeSet0 ;; jmp to setting minute
CP A,Key_ml
jp z,MTimeSet1 ; jmp to setting increase hour
jp TimeSet0
MTimeSet1:
ld X,RegKeyFlags
; OR MX,DisFlashFlag
fan MX,KeyHoldFlag
jp nz,MTimeSet2 ; br to check the hold time
AND MX,0fh-NewKeyFlag ; clr the key
AND MX,0fh-DisFlashFlag ; clr the key
LD a,0
ld KeyHoldTm,a ; reset timer
ld KeyCode,a ; clr the key code
HTimeSet0:
call IncSetMinute
jp TimeSet0
MTimeSet2:
;
; starting from here if the key hold time > 2 seconds
;
OR MX,DisFlashFlag
ld a,KeyHoldTm
cp a,0fh ; tolerance -1/8 sec
jp nz,TimeSet0 ; br if Hold time < 2 seconds
ld a,0dh
ld KeyHoldTm,a ;
jp HTimeSet0
; call IncSetMinute ;
; jp TimeSet0
MTimeSet0:
; ld X,RegKeyFlags
; and mx,0fh-TimeFormatFlag ; default is 12 hour
ld a,Key_Nil
ld KeyCode,a ; clr key code
ORG 300H
TimeSet4:
calz FlashTimeFormat
call ChkTimer
LD A,KeyCode
CP A,Key_Kg
JP z,TTimeSet0 ;; jmp to exit setting
CP A,Key_ml
jp z,TTimeSet1 ; jmp to toggle time format
jp TimeSet4
TTimeSet1:
ld X,RegKeyFlags
fan MX,KeyHoldFlag
jp nz,TimeSet4 ; br to check the hold time
AND MX,0fh-NewKeyFlag ; clr the key
ld a,0
ld KeyCode,a
ld x,RegKeyFlags
xor mx,TimeFormatFlag
calz DspTimeFormat
jp TimeSet4
ORG 350H
TTimeSet0:
ld x,TmpRTCMinuteL
ld y,RTCMinL
call Copy2Byte ;
ld x,RTCSec
call ClrByte
ld y,RTCHourL
calz DspHour
ld y,RTCMinL
calz DspMinute
ld a,0
ld KeyHoldTm,a
ld X,RegKeyFlags
AND MX,0fh-NewKeyFlag ; clr the key
jp ProgStartLp
;
; ORG 300h
;WeigthKey_Kg:
; LD X,RegKeyFlags
; FAN MX,KeyHoldFlag
; JP nz,ProgStartLp ; still key hold
; AND MX,0fh-NewKeyFlag ; process the key & clr the flag
;;
;; process the Kg key here after
; LD SendData,B ;
; LD X,AppFlags
; OR MX,ReqToSendFlag
; JP ProgStartLp
org 370h
;
;-------------------------------------
; 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
CALL Send4Bit
;
ld y,RPort ; set D_Out Hi after sending
; or my,0010b
or my,0011b
; Check the time out if neccessary
RET
;
;-------------------------------------
; Cate : communication
; By : Hcy
; Func : send 4 data bits (LSB first)
; Desc : Send4Bit
; I/P :
; O/P :
; Destroy:
; Note :
Send4Bit:
LD X,CommCount
LD MX,4 ; 4 bits
Send4BitLp1:
LD Y,KPort
Send4BitLp0:
FAN MY,0100b ; wait for D_Clk Hi
JP z,Send4BitLp0
;
ld y,RPort
RRC A
JP C,Send4BitHi
and my,0001b
jp Send4Bit0
Send4BitHi:
; OR my,0010b
or my,0011b
Send4Bit0:
LD Y,KPort
Send4BitLp2:
FAN MY,0100b ; wait for D_Clk Lo
JP nz,Send4BitLp2
Add mx,0fh ; dec commcount
JP nz,Send4BitLp1
;
xSend4Bit:
ret
;-------------------------------------
; 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
;;-------------------------------------
; 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 z,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 z,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
;-------------------------------------
; Cate : communication
; By : Hcy
; Func : send synchronize bit(high level)
; Desc : SendSynBit
; I/P :
; O/P :
; Destroy:
; Note :
;SendSynBit:
; LD Y,KPort
;SendSyn0:
; FAN MY,0100b ; check D_Clk Hi
; JP z,SendSyn0 ; wait until D_CLK= Hi
;;
;; Samsung get the acknowledge
; NOP5
; ld x,RPort ; D_clk=Lo
; or my,0010b
;;
;SendSyn1:
; FAN MY,0100b ;
; JP nz,SendSyn0 ; wait until D_CLK= Hi
; ret
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -