;***************************************************************************
;***** MASTER **************************************************************
;***************************************************************************

	list		p=16f690	
	#include	<P16F690.inc>	
	
	__CONFIG    _CP_OFF & _CPD_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF


    CBLOCK  0x20
REGA 
REGB  
REGC
REGD
    ENDC


#DEFINE     LED PORTB,5

	ORG		0x000		
  	goto    START		

;***************************************************************************
;***** PODPROGRAMY *********************************************************
;***************************************************************************
	ORG		0x004		

CAS1
    banksel REGA        ;casova slucka 3,5s
    movlw   0xEE
    movwf   REGC
    incfsz  REGA,1
    goto    $-1
    incfsz  REGB,1
    goto    $-3
    incfsz  REGC,1
    goto    $-5
    return

CAS2
    banksel REGD        ;casova slucka 70us
    movlw   0xEB
    movwf   REGD
    incfsz  REGD,1
    goto    $-1 
    return

;***************************************************************************
;***** HLAVNY PROGRAM ******************************************************
;***************************************************************************
START 
    bsf     STATUS,RP0
    clrf    TRISA
    movlw   0x10            
    movwf   TRISB
    clrf    TRISC

    bcf     STATUS,RP0
    clrf    PORTA
    clrf    PORTB
    clrf    PORTC
 
    bcf     ADCON0,0        ;AD prevodnik vypnuty

    movlw   0x10
    movwf   SSPCON          ;CKP=1 MASTER f=1MHz
    call    CAS2 
    bsf     SSPCON,5        ;SSP modul povolenı  

    clrf    INTCON          ;vsetky prerusenia zakazane
    
    banksel PIE1
    clrf    PIE1
    clrf    PIE2

    bsf     STATUS,RP0
    bcf     SSPSTAT,7       ;SMP=0
    bcf     SSPSTAT,6       ;CKE=0

    bcf     STATUS,RP0
    bsf     STATUS,RP1      ;banka 2

    clrf    ANSELH          ;RB4,RB5,RC6,RC7 digitalne
    clrf    ANSEL           ;vsetky digitalne

    bcf     STATUS,RP1      ;banka 0

    bsf     LED
    call    CAS1

POSLI
    banksel SSPBUF
    movlw   0xAA
    movwf   SSPBUF
    banksel PIR1            ;banka 0
    btfss   PIR1,3          ;bol prenos uspesny?
    goto    $-1             ;nie         
    banksel SSPBUF 
    movf    SSPBUF,W        ;vymaz buffer
    bcf     LED
    goto    $-0
    
	END           