;#include <p16F690.inc>
  ; __config (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

#include <p16F690.inc>
  __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
 
  k1 equ 20   ;assign memory addresses for k1
  k2 equ 21   ;assign memory addresses for k2
  k3 equ 22   ;assign memory addresses for k3
  dum equ 23  ;dummy variable
  dum2 equ 24  ;dummy for saving status reg

 org 00

 goto Start
  org 04
  goto INT_ROUTINE

Start

 BCF   STATUS,RP0   ;set bank 1 for registers
 movlw b'10010000' ;enables serial port, continuous receive  
 movwf RCSTA
 BSF   STATUS,RP0  ;sets bank 2 registers 
 movlw  b'00100100' ;sets serial transfer parameters
 movwf TXSTA
 movlw b'00011001' ;sets baud rate
 movwf SPBRG
 BSF   TRISC,0   ;set portc pin c3 as input     
 bcf STATUS,RP0 ;set bank 1 registers
; bcf PIR1,RCIF ;sets receive interupt flag
 movlw b'10100000' ; enables trm0 interupt
 movwf INTCON 
 bsf STATUS,RP0; sets bank 2
 movlw b'00000000'
 movwf OPTION_REG; fastest timer rate
 bcf STATUS,RP0; set bank one
 movwf k1   ; start k1 at 0
 movwf k2   ; start k2 at 0
 movwf k3   ; start k3 at 0

loop
  movf TMR0,W; load clock into w
  bsf STATUS,RP0 ;set bank 2 registers
  btfss TXSTA,TRMT ;check if txreg is empty
  goto $-1
  bcf STATUS,RP0 ;set bank 1 registers
  movwf TXREG ;put W data into txreg
  movf k1,W ;load counter into w
  bsf STATUS,RP0 ;set bank 2 registers
  btfss TXSTA,TRMT ;check if txreg is empty
  goto $-1
  bcf STATUS,RP0 ;set bank 1 registers
  movwf TXREG ;put W data into txreg
  movf k2,W ;load counter k2 into w
  bsf STATUS,RP0 ;set bank 2 registers
  btfss TXSTA,TRMT ;check if txreg is empty
  goto $-1
  bcf STATUS,RP0 ;set bank 1 registers
  movwf TXREG ;put W data into txreg
  movf k3,W ;load counter k3 into w
  bsf STATUS,RP0 ;set bank 2 registers
  btfss TXSTA,TRMT ;check if txreg is empty
  goto $-1
  bcf STATUS,RP0 ;set bank 1 registers
  movwf TXREG ;put W data into txreg
  goto loop






INT_ROUTINE
   movwf dum ;save W
   movf STATUS, W ;save Status in W
   bcf STATUS,RP0 ;set bank 0
   movwf dum2   ;save status in dum2
   movlw b'11111111'
   subwf k1,W   ;subtract k1
   btfsc STATUS,Z  ;see if k1=255
   goto minute
   goto hour
minute
   movlw b'11111111'
   subwf k2,W   ;subtract k2
   btfsc STATUS,Z  ;see of k2=255
   incf k3,1
   incf k2,1  ;increment k2
hour  incf k1,1
   movf dum2, W ;returning Status to original value
   movwf STATUS
   movf dum,W ; returning dum to W
   bcf INTCON,T0IF
   retfie
 end

