;***************************************************************************
;***** 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

    errorlevel -302

    CBLOCK  0x20
REGA 
REGB  
REGC
    ENDC


#DEFINE     LED PORTB,5



	ORG		0x000		
  	goto    START		

;***************************************************************************
;***** PODPROGRAMY *********************************************************
;***************************************************************************

	ORG		0x004		

CAS1
    movlw   0xEE
    movwf   REGC
    incfsz  REGA,1
    goto    $-1
    incfsz  REGB,1
    goto    $-3
    incfsz  REGC,1
    goto    $-5
    return

;***************************************************************************
;***** HLAVNY PROGRAM ******************************************************
;***************************************************************************

START
    clrf    PORTA
    clrf    PORTB
    clrf    PORTC
 
    bcf     ADCON0,0        ;AD prevodnik vypnuty

    movlw   0x30            ;MASTER,1MHz,CKP=1    
    movwf   SSPCON

    clrf    INTCON          ;vsetky prerusenia zakazane

    bsf     STATUS,RP0      ;banka 1             

    clrf    TRISA
    movlw   0x10
    movwf   TRISB
    clrf    TRISC

    bcf     SSPSTAT,7       ;SMP=0
    bsf     SSPSTAT,6       ;CKE=1

    bcf     STATUS,RP0
    bsf     STATUS,RP1      ;banka 2

    clrf    ANSELH          ;RB4,RB5,RC6,RC7 digitalne
    clrf    ANSEL           ;vsetky digitalne

    bcf     STATUS,RP1      ;banka 0
    clrf    SSPBUF

    nop
    nop
    nop 
    nop
    nop

    bsf     LED
    call    CAS1

POSLI
    banksel SSPBUF
    movlw   0x48
    movwf   SSPBUF
    bcf     STATUS,RP0      ;banka 0
    movf    SSPBUF,W          
    bcf     SSPCON,WCOL
    bcf     LED
    goto    $-0
    
	END           