;******************************************************************************
;***** SLAVE ******************************************************************
;******************************************************************************
     LIST      p=16F88            
     #INCLUDE <P16F88.INC>     

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

    CBLOCK  0x20
REGA
REGB
REGC
REGD
REGE
    ENDC

#DEFINE     LED     PORTB,5

    ORG     0x00

    goto    START
;******************************************************************************
;***** PODPROGRAMY ************************************************************
;******************************************************************************
    ORG     0x04
CAS1
    bcf     STATUS,RP0      ;casova slucka 58us
    bcf     STATUS,RP1
    movlw   0xEF
    movwf   REGA
    incfsz  REGA,1
    goto    $-1       
    return

CAS2
    bcf     STATUS,RP0
    bcf     STATUS,RP1
    incfsz  REGB,1
    goto    $-1
    incfsz  REGC,1
    goto    $-3
    return

;******************************************************************************
;***** HLAVNY PROGRAM *********************************************************
;******************************************************************************
START
    bsf     STATUS,RP0      
    clrf    TRISA           
    movlw   0x12
    movwf   TRISB           ;RB1 a RB4 vstupy
    
    banksel SSPCON
    movlw   0x15
    movwf   SSPCON          ;CKP=1 SLAVE, pin SS nepouzity
    call    CAS1

    banksel SSPSTAT
    bcf     SSPSTAT,7       ;SMP=0
    bcf     SSPSTAT,6       ;CKE=0
    
    bcf     STATUS,RP0
    clrf    PORTA
    clrf    PORTB

    bsf     STATUS,RP0
    clrf    ANSEL           ;analogove vstupy vypnute        
    clrf    PIE1
    clrf    INTCON          ;vsetky prerusenia zakazane

    bcf     STATUS,RP0
    bsf     LED             ;rozsviet LED
    call    CAS2
    nop
    call    CAS2

PRIJ
    bcf     SSPCON,7
    bcf     SSPCON,6
    banksel SSPSTAT
    btfss   SSPSTAT,BF      ;bol dokonceny prijem?
    goto    PRIJ            ;NIE
    bcf     LED             ;ANO, zhasni LED
    banksel SSPSTAT 
    movf    SSPBUF,W        ;vymaz buffer
    goto    $-0

          END
