                device pic16c71,hs_osc,wdt_off,pwrt_off,protect_off
                id 'sr01'
        include 'mheader.src'

bthresh	=	20

RA3         =   ra.3
RB3	    =   rb.3
RB5         =   rb.5
            
            org     0h
            jmp     5
            org 4h            
doint       jmp     rcv
            org 5h
            clr     PCLATH
            clrb    rp0
            mov     ADCON0, #10000001b
;            mov	    INTCON, #00100000b	;RTCC, INT IRQ enabled
            mov	    INTCON, #00000000b	;RTCC, INT IRQ enabled
            call    dally
            setb    rp0
            mov     TRISA, #0011b
            mov     TRISB, #00000001b
            mov     OPTION, #00000100b  ;RTCC=inst,RB pull-up, /4   
            mov     ADCON1, #00000010b
            clrb    rp0
            mov     RTCC, #fullframe
            setb    waitb
            clrb    inmsg
            clr     ra
            clr     rb
            setb    TXSWTCH
            clrb    PTX
            clr     FSR
            setb    GIE
	    clrb    RB3

main        nop
	mov	onect, 	#0
	mov	sine1, 		#0
	mov	bytect, 	#0
	clrb	inmsg

:ml
	mov	quad,	#0
	setb	RB5
	call	collect
	clrb	RB5
	mov 	tempb, 	byte1
	call 	absol
	add 	quad, 	tempa

	mov 	tempb, 	byte2
	call 	absol
	add 	quad, 	tempa

	cjb	quad, #bthresh, :cont
	inc	onect
:cont
	jnb	inmsg, :elsif
	inc	sine1
	cjb	sine1, #7, :ml
	cjb	onect, #5, :contb
	setb	c
	rr	mybyte
	jmp	:contc	
:contb
	clrb	c
	rr	mybyte
:contc
	mov	sine1, #0
	mov	onect, #0
	inc	bytect
	cjb	bytect, #8, :gowait
	clrb	inmsg
	clrb	RB3
	mov	bytect, #0
	call	sout
:gowait
	call	swait
	jmp	:ml
:elsif
	cjae	quad, #bthresh, :conta
	mov	onect, #0
:conta		
	cjb	onect, #3, :ml
	call	twait
	setb	inmsg
	setb	RB3
	mov	onect, #0
	jmp	:ml

rcv
            reti



;                    INCLUDE 'ookdmod2.src'
                    INCLUDE 'ookdmod.src'
                    INCLUDE 'collect.src'
                    INCLUDE 'adjgain.src'

twait
		mov	tempb, #11
:loopb		mov	tempa, #217
:loop		djnz	tempa, :loop
		djnz 	tempb, :loopb
		ret

swait
		mov	tempb, #10
:loopb		mov	tempa, #213
:loop		djnz	tempa, :loop
		djnz 	tempb, :loopb
		ret

dally		mov	tempa,#255
:l1		mov	tempb,#255
:l2		djnz	tempb,:l2
		djnz	tempa,:l1
		ret
                    
                    