
#include <p16F690.inc>
     __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
     org 0
W_save	equ	20h	; zaloha pri preruseni
Sta_sav	equ	21h	; zaloha pri preruseni
PCL_sav	equ	22h	; zaloha pri preruseni
FSR_sav	equ	23h	; zaloha pri preruseni
CISLO	equ	24h

;-----------------------------------------------------------------------------------------------

	org	00h
	goto	INIT

	org	04h
	movwf	W_save		; W
	movf	STATUS,W
	clrf	STATUS		; Banka 0
	movwf	Sta_sav		; STATUS
	movf	PCLATH,w
	movwf	PCL_sav		; PCLATH
	movf	FSR,w
	movwf	FSR_sav		; FSR
	goto	PRERUS


;************************************************************************************************
;************************************************************************************************
;************************************************

INIT:
 	bsf     STATUS,RP0      
	bcf		STATUS,RP1
    clrf    TRISC        ; nastaveni PORTC jako vystup
	bcf     STATUS,RP0        
	clrf   PORTC         ; zhasnuti vsech LED na PORTC
   

    
	
	BSF	STATUS,RP0	; nastaveni In / Out
	MOVLW	B'10100000'
	MOVWF	TRISB
	MOVLW	B'00100110'
	MOVWF	TXSTA
	MOVLW	12
	MOVWF	SPBRG
	MOVLW	B'00100000'
	MOVWF	PIE1
	BCF	STATUS,RP0
	MOVLW	B'10010000'
	MOVWF	RCSTA
	MOVLW	B'11000000'
	MOVWF	INTCON

	MOVLW	B'01011111'		; odesle data pres USART
	MOVWF	TXREG

	NOP


     MOVLW	CISLO
     movwf   PORTC         ; turn on LED C0 (DS1)

     



PRERUS	BTFSC	PIR1,5		; zjisti typ preruseni
	GOTO	PREUSAR
	GOTO	PRERKON		; nezname = nic

PREUSAR	BCF	PIR1,5		; prislo neco na USART
	MOVF	RCREG,0		; nacte prijmuty byte
	MOVWF	CISLO		; a ulozi do CISLO


PRERKON	BSF	STATUS,RP0	; konec preruseni
	MOVLW	B'11000000'	; povoleni zpet pozadovanych preruseni
	MOVWF	INTCON
	MOVLW	B'00100000'
	MOVWF	PIE1
	BCF	STATUS,RP0
	clrf	STATUS		; Banka 0	obnoveni ulozenych registru
	movf	FSR_sav,w	; FSR
	movwf	FSR
	movf	PCL_sav,w	; PCLATH
	movwf	PCLATH
	movf	Sta_sav,w	; Status
	movwf	STATUS
	swapf	W_save,f	; W
	swapf	W_save,w
	retfie


	END