📄 r08clk.s.bak
字号:
call CopyByte
pop yl
ld x,DspHourBuf
SET F,0100B
RCF
sbc Mx,02h
inc x
sbc Mx,01h
RST F,1011B
RET
;
;-------------------------------------
; Cate : Clock
; By : Hcy
; Func : is che memory equ 12h
; Desc : IsEqu24
; I/P : --
; O/P : --
; Destroy:
; Note :
IsEqu12:
cp my,02h
jp z,IsEqu120
rcf
ret
IsEqu120:
push yl
inc y
cp my,01h
pop yl
jp z,IsEqu121 ; jmp if 1 minute time out
rcf
ret
IsEqu121:
call CopyByte
scf
ret
;
;-------------------------------------
; Cate : Clock
; By : Hcy
; Func : is che memory equ 0
; Desc : IsEqu24
; I/P : --
; O/P : --
; Destroy:
; Note :
IsEquZero:
cp my,0
jp z,IsEqu00
rcf
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:
ld x,KPort
fan mx,0100b
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
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 ; page 2
;
; 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(200h -- 23fh)
ld x,0
RAMClr:
ldpx mx,0
cp xh,4
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
;
; 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
;
;
;
; enable interrupts if any
;
LD Y,KPortMask
LD MY,0100b ; No key interrupt allowed, only the D_Clk
;
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
; ; 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
ld x,KPort
fan mx,IO_Key_On
jp z,ProgStart ; 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,ProgStart ; br if Key_Kg is not preseed
CalKey0:
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
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
; 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
call SendKeyData
;
Prog5:
call DspWeight
call DspIcons
call 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
;-------------------------------------
; 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
;
;;======================================
; 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -