#include <p16F648a.inc>
__config (_EXTCLK_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOREN_OFF)
radix dec
pclath_temp equ 0x70
w_temp equ 0x71
status_temp equ 0x72
digcount equ 0x73
digit1 equ 0x74
digit2 equ 0x75
digit3 equ 0x76
digit4 equ 0x77
seccount equ 0x78
flags equ 0x79
mincount equ 0x7A
keycount equ 0x7B
#define fminute flags,0
#define fkeyrpt flags,1
#define dp portb,7
#define button porta,4
maxdigits equ d'4'
keytime equ d'250'
keyrepeattime equ d'30'
set_disp macro d4, d3, d2, d1
movlw d4
movwf digit4
movlw d3
movwf digit3
movlw d2
movwf digit2
movlw d1
movwf digit1
clrf seccount
bcf fminute
endm
org 0x000
goto Init
Irq org 0x004
movwf w_temp
movf status,w
movwf status_temp
movf pclath,w
movwf pclath_temp
banksel pir1
btfss pir1,tmr2if
goto restore
btfsc button
goto button_no
btfsc fkeyrpt
goto button_set
movlw keytime
xorwf keycount,w
btfsc status,z
goto button_2
incf keycount,f
movlw keyrepeattime
xorwf keycount,w
btfss status,z
goto button_end
goto button_inc2
button_2 bsf fkeyrpt
goto button_inc
button_set incf keycount,f
movlw keyrepeattime
xorwf keycount,w
btfsc status,z
goto button_inc
goto button_end
button_no bcf fkeyrpt
clrf keycount
goto button_end
button_inc clrf keycount
button_inc2 clrf seccount
clrf mincount
bsf fminute
button_end
incf seccount,f
movf seccount,w
xorlw d'250'
btfss status,z
goto irq_disp
clrf seccount
incf mincount
movf mincount,w
xorlw d'60'
btfss status,z
goto irq_disp
clrf mincount
bsf fminute
irq_disp movf digcount,w
call digtab
movwf porta
movlw digit1
movwf fsr
movf digcount,w
addwf fsr,f
movf indf,w
call segtab
movwf portb
movf digcount,w
xorlw d'2'
btfss status,z
goto irq_disp_nodp
movf seccount,w
sublw d'125'
btfss status,c
bsf dp
irq_disp_nodp incf digcount,f
movf digcount,w
xorlw maxdigits
btfsc status,z
clrf digcount
banksel pir1
bcf pir1,tmr2if
goto restore
segtab addwf pcl,f
dt 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
digtab addwf pcl,f
dt 0x1,0x2,0x4,0x8
restore movf pclath_temp,w
movwf pclath
movf status_temp,w
movwf status
swapf w_temp,f
swapf w_temp,w
retfie
Init
banksel pie1
bsf pie1,tmr2ie
clrf digcount
banksel t2con
movlw b'00100111'
movwf t2con
banksel pr2
movlw d'124'
movwf pr2
bsf intcon,gie
bsf intcon,peie
banksel cmcon
movlw 0x07
movwf cmcon
clrf seccount
clrf mincount
clrf keycount
banksel trisa
movlw b'00010000'
movwf trisa
movlw b'00000000'
movwf trisb
main set_disp 0,0,0,0
loop btfss fminute
goto loop
update incf digit1,f
movlw d'10'
xorwf digit1,w
btfss status,z
goto loop_end
clrf digit1
incf digit2,f
movlw d'6'
xorwf digit2,w
btfss status,z
goto loop_end
clrf digit2
incf digit3,f
movlw d'10'
xorwf digit3,w
btfss status,z
goto loop_end
clrf digit3
incf digit4,f
loop_end bcf fminute
movlw d'2'
xorwf digit4,w
btfss status,z
goto loop
movlw d'4'
xorwf digit3,w
btfsc status,z
goto main
goto loop
end