;********************************************************************
;                     	     u_alarm_16F628.ASM
;*********************************************************************
;cidlo: mikrovlnne, typ HFS-DC06H (Doppler radar)
;napajeni 5V
;nastavitelna citliost a doba sepnuti
;vystup: TTL
;klidova uroven = L
;aktivni uroven = H
;indikace pohybu: LED dioda (seriovy odpor 330R) nebo piezo menic,
;trojice bliknuti, opakujici se po dobu aktivace cidla
;Vstup cidla = RA0 (pin 17)
;Vystup pro LED = RB0 (pin 6)
;***************************************************************************

	list F=inhx8m,P=16F628,R=hex,N=0
	__config 3F78h	  ; Configuration Word (Fuses)
	errorlevel -302      ; switch off Message [302]:
        ; Register in operand not in bank 0

;Definice specialnich funkcnich registru
#INCLUDE	<P16F628.INC>

#define CIDLO PORTA,0	;signal z u-vlnneho cidla. Aktivni v H.	
#define	LED	PORTB,0		;vystup pro LED diody. Aktivni v H.

; Definice uzivatelskych registru
w       equ     0       ; instruction result to W, register unchanged
f       equ     1       ; instruction result to register, W unchanged
RAM     equ     0x20	;pocatek oblasti uzivateskych registru v pameti
						;(datasheet str. 17
tm1     equ     RAM
citac	equ     RAM+1
citac1	equ	RAM+2
citac2	equ	RAM+3
citac3	equ	RAM+4
w       equ     0       ; instruction result to W, register unchanged
f       equ     1       ; instruction result to register, W unchanged
     
		org		0
		      
;************************ HLAVNÍ PROGRAM **********************************
START	CALL	init

ST	NOP
	NOP
	BTFSS	CIDLO	;pohyb?
	GOTO	ST		;ne
    	CALL	ALARM	;ano - vyvolej alarm
ST1	BTFSC	CIDLO	;stale pohyb?
	call	ALARM	;ano - pokracuj v alarmu
	goto	ST1
	
;PODPROGRAMY: ***********************************************************	
init
    	clrf	PORTA
	clrf	PORTB
	movlw	b'00000111'	; digitalni vstupy na PORTu A
	movwf	CMCON
		
	banksel	TRISA
	Movlw	b'11111111'
	Movwf	TRISA
	Movlw	b'00000000'
	Movwf	TRISB
	banksel	PORTA	
	return
;================

ALARM
	movlw	.3		;pocet bliknuti led diody
	movwf	citac
zpet	BSF	LED
	call	t_50ms
	bcf		LED
	call	t_150ms
	decfsz	citac
	goto	zpet
	call	t_150ms
	call	t_150ms	
	RETURN
;=====================

t_50ms
	movlw   .173     ;
        movwf   citac1
	movlw   .95    ;
        movwf   citac2    
        decfsz  citac2,f
        goto    $-1
	decfsz	citac1,f
	goto	$-5
        return
;=====================

t_150ms
	movlw   .195     ;
        movwf   citac1
	movlw   .205    ;
        movwf   citac2    
        decfsz  citac2,f
        goto    $-1
	decfsz	citac1,f
	goto	$-5
        return
;===================
	
	END

