
	LIST P=16F690, R=DEC
	INCLUDE<P16F690.INC>
	

	__CONFIG _PWRTE_ON & _WDT_OFF & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT

;*****************************************************************************************
;******************      DEKLARACE PROMENNYCH A KONSTANT    ******************************
;*****************************************************************************************
	DATAL	EQU	0x20
#define	RC1	PORTC,1
	COUNT4		equ	0x24        ; CITAC PRO DELAY
	COUNT5		equ	0x25	      ; CITAC PRO DELAY
	COUNT6		equ	0x26	      ; CITAC PRO DELAY
	COUNT7		equ	0x27	      ; CITAC PRO DELAY
	COUNT8		equ	0x28	      ; CITAC PRO DELAY

;ostatni KONSTATNTY
;*******************************************************************************
;*************************    ZACATEK KODU      ********************************
;*******************************************************************************

	ORG  0x00

; ---------------- 
; INITIALIZE PORTS 
; ---------------- 
; 
	BCF STATUS,RP0 		;Bank 0
	BCF STATUS,RP1 		;
	CLRF PORTA 		;Init PORTA
	BSF STATUS,RP1 		;Bank 2
	CLRF ANSEL 		;digital I/O
	CLRF ANSELH
	BCF ANSELH,3
	BSF STATUS,RP0 		;Bank 1
	BCF STATUS,RP1 		;
	MOVLW b'00001000'	;
	MOVWF TRISA 		;
				;
	BCF STATUS,RP0 		;Bank 0
	BSF RCSTA, SPEN
	BSF RCSTA, CREN


 	BCF STATUS,RP0 		;Bank 0
	BCF STATUS,RP1 		;
	CLRF PORTB 		;Init PORTB
	BSF STATUS,RP0 		;Bank 1
	MOVLW b'01111111'	;
	MOVWF TRISB 		;
	BCF STATUS,RP0 		;Bank 0


	BCF STATUS,RP0 		;Bank 0
	BCF STATUS,RP1 		;
	CLRF PORTC 		;Init PORTC
	BSF STATUS,RP1 		;Bank 2
	CLRF ANSEL 		;digital I/O
	BSF STATUS,RP0 		;Bank 1
	BCF STATUS,RP1 		;
	MOVLW b'00000000'	;Set vse jako Output
	MOVWF TRISC 		;
				;
	BCF STATUS,RP0 		;Bank 0


        bsf STATUS,RP0          ; RAM PAGE 1 



; ------------------------------------ 
; SET BAUD RATE TO COMMUNICATE WITH PC 
; ------------------------------------ 
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit 
; 
        movlw 0x19              ; 0x19=9600 bps (0x0C=19200 bps) 
        movwf SPBRG 
        movlw b'00100100'       ; brgh = high (2) 
        movwf TXSTA             ; enable Async Transmission, set brgh 

        bcf STATUS,RP0          ; RAM PAGE 0 

        movlw b'10010000'       ; enable Async Reception 
        movwf RCSTA 
; 
; ------------------------------------ 
; PROVIDE A SETTLING TIME FOR START UP 
; ------------------------------------ 
; 
        clrf dataL 
settle  decfsz dataL,F 
        goto settle 

        movf RCREG,W 
        movf RCREG,W 
        movf RCREG,W            ; flush receive buffer 
; 
; --------- 
; MAIN LOOP 
; --------- 
; 
	BCF  STATUS,RP0
        call message            ; send "16F628 alive" 
	BCF  STATUS,RP0

	
loop    call receive            ; wait for a char 
        call send               ; send the char 

        goto loop 
; 
; ------------------------------------------- 
; RECEIVE CHARACTER FROM RS232 AND STORE IN W 
; ------------------------------------------- 
; This routine does not return until a character is received. 
; 
receive 
	BSF   PORTC,1	
	BSF   PORTC,0

	btfss PIR1,RCIF         ; (5) check for received data 
        goto  receive 
        movf RCREG,W            ; save received data in W 
	
        return 
; 
; ------------------------------------------------------------- 
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING 
; ------------------------------------------------------------- 
; 
send    movwf TXREG             ; send data in W 

TransWt bsf STATUS,RP0          ; RAM PAGE 1 
WtHere  btfss TXSTA,TRMT        ; (1) transmission is complete if hi 
        goto WtHere 

        bcf STATUS,RP0          ; RAM PAGE 0 
        return 


; 
; ------- 
; MESSAGE 
; ------- 
; 
message movlw  '1' 
        call send 
        movlw  '6' 
        call send 
        movlw  'F' 
        call send 
        movlw  '6' 
        call send 
        movlw  '9' 
        call send 
        movlw  '0' 
        call send 
        movlw  ' ' 
        call send 
        movlw  'a' 
        call send 
        movlw  'l' 
        call send 
        movlw  'i' 
        call send 
        movlw  'v' 
        call send 
        movlw  'e' 
        call send 
        movlw  0x0D ; CR 
        call send 
        movlw  0x0A ; LF 
        call send 
        return 


	END


