#include <p12f629.inc>
 __CONFIG (_MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT)  ;Internal osc.

 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
 c1 equ 25   ;variable for delays
 c2 equ 26   ;variable for delays
 c3 equ 27   ;variable for 0-15 minutes
 c4 equ 28   ;variable for 1/4 hours

 org 0

 goto Start
  org 04
  goto INT_ROUTINE

Start
 BCF   STATUS,RP0  ; select bank 0
 CLRF  GPIO       ; set GPIO pins equal to 0 volts
 ;movlw b'11111111'
 ;movwf CMCON
 BSF   STATUS,RP0  ; select bank 1
 CLRF  TRISIO      ; make GPIO pins all output
 BCF   STATUS,RP0  ; select bank 0
 movlw b'10100000' ; enables trm0 interupt
 movwf INTCON
 bsf STATUS,RP0; sets bank 1
 movlw b'00000000'
 movwf OPTION_REG; fastest timer rate
 bcf STATUS,RP0; set bank 0
 movwf TMR0 ; reset timer0
 movwf k1   ; start k1 at 0
 movwf k2   ; start k2 at 0
 movwf k3   ; start k3 at 0
 movwf c3   ; start off at zero
 movwf c4   ; start off at zero

loop
 call buzzer ; beep the tones for the time
 call delay2 ;wait for two minutes
 movlw b'00000000'
 bcf STATUS,RP0; set bank 0
; movwf TMR0 ; reset timer0
 movwf k1   ; start k1 at 0
 movwf k2   ; start k2 at 0
 movwf k3   ; start k3 at 0
 incf c3,1  ; increment c3 by one
 movlw b'00001111'  ; the number 15
 subwf c3,w  ;subtract 15 from c3
 btfss STATUS,Z  ; check if c3 is 15 if so then skip
 goto loop
 incf c4,1  ; add a quarter hour to c4
 clrf c3  ; start minutes at zero
 goto loop

buzzer
 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b0
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c4,1  ;check if the second bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec (for 4 kHz)
 bcf GPIO,2  ; piezo pressure off
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c4,1  ;check if the second bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec
 decfsz c2,1
 goto b0
 call delay1 ;wait one tenth second

 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b1
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c4,0  ;check if the first bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec (for 4 kHz)
 bcf GPIO,2  ; piezo pressure off
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c4,0  ;check if the first bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec
 decfsz c2,1
 goto b1
 call delay1 ;wait one tenth second

 call delay1 
 call delay1

 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b2
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,3  ;check if the third bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec (for 2 kHz)
 bcf GPIO,2  ; piezo pressure off
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,3  ;check if the third bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec
 decfsz c2,1
 goto b2
 call delay1 ;wait one tenth second

 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b3
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,2  ;check if the second bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec (for 4 kHz)
 bcf GPIO,2  ; piezo pressure off
 movlw b'11111111'
 bcf STATUS,RP0
 btfsc c3,2  ;check if the second bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 128 microsec
 decfsz c2,1
 goto b3
 call delay1 ;wait one tenth second

 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b4
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,1  ;check if the first bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec (for 2 kHz)
 bcf GPIO,2  ; piezo pressure off
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,1  ;check if the first bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec
 decfsz c2,1
 goto b4
 call delay1 ;wait one tenth second

 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
b5
 bsf GPIO,2  ; piezo pressure on
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,0  ;check if the zeroth bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec (for 2 kHz)
 bcf GPIO,2  ; piezo pressure off
 bcf STATUS,RP0
 movlw b'11111111'
 btfsc c3,0  ;check if the zeroth bit is 0
 movlw b'10000000'  ;if it is 0 then skip  
 movwf c1
 call delay0  ; delay around 256 microsec
 decfsz c2,1
 goto b5
 call delay1 ;wait one tenth second
 return

delay0
lc0
 decfsz c1,1
 goto lc0
 return

delay1
 movlw b'11111111'
 bcf STATUS,RP0
 movwf c2
lc1
 movlw b'11111111'
 movwf c1
lc2
 decfsz c1,1
 goto lc2
 decfsz c2,1
 goto lc1
 return

delay2
 bcf STATUS,RP0
lc3
 movlw b'00000010' ; the number 2
 subwf k3,w    ; subtract w from k3
 btfss STATUS,Z  ;check if k3 has reached 2
 goto lc3
lc4 
 movlw b'00100000' ;the number 32
 subwf k2,w   ; subtract w from k2
 btfss STATUS,Z  ;check if k2 has reached 32
 goto lc4
;lc5
; movlw b'11000011'  ; the number 195
; subwf k1,w  ; subtract w from k1
; btfss STATUS,Z  ; check if k1 has reached 135
; goto lc5
 return

INT_ROUTINE
   bcf STATUS,RP0 ;set bank 0
   movwf dum ;save W
   movf STATUS, W ;save Status in W
   movwf dum2   ;save status in dum2
   clrf TMR0 
   bcf INTCON,T0IF
   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
   retfie
 end
