;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#include <p16F690.inc>
     __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

        ORG    0x000            ; Program starts at 0x000

	

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	; SET ALL PORTB OUTPUT (TX=RB7)
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        BSF	STATUS,RP0          ; RAM PAGE 1
        
	MOVLW	0X00
	MOVWF	TRISB

     	BCF	STATUS,RP0     ; address Register Page 0
     
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	; CLEAR PORTB
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	MOVLW	0X00
	MOVWF	PORTB

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	; SET BAUD RATE TO COMMUNICATE WITH PC
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     	BSF	STATUS,RP0     ; address Register Page 1

	; 1. Initialize the SPBRGH, SPBRG register pair and
	; the BRGH and BRG16 bits to achieve the desired
	; baud rate (see Section 12.3 “EUSART Baud
	; Rate Generator (BRG)”).
        MOVLW	25              ; 25=2400 bps
        MOVWF	SPBRG
        BCF	TXSTA,BRGH	; BRGH=LOW
        BCF	BAUDCTL,BRG16
        
        ; 2. Enable the asynchronous serial port by clearing
	; the SYNC bit and setting the SPEN bit.
	BCF	TXSTA,SYNC
     	BCF	STATUS,RP0     ; address Register Page 0
	BSF	RCSTA,SPEN
	
	; 3. If 9-bit transmission is desired, set the TX9 control
	; bit. A set ninth data bit will indicate that the 8
	; Least Significant data bits are an address when
	; the receiver is set for address detection.	
	
	; 4. Enable the transmission by setting the TXEN
	; control bit. This will cause the TXIF interrupt bit
	; to be set.	
     	BSF	STATUS,RP0     ; address Register Page 1
     	BSF	TXSTA,TXEN
     	
	; 5. If interrupts are desired, set the TXIE interrupt
	; enable bit. An interrupt will occur immediately
	; provided that the GIE and PEIE bits of the
	; INTCON register are also set.
	
	; 6. If 9-bit transmission is selected, the ninth bit
	; should be loaded into the TX9D data bit.
	
	; 7. Load 8-bit data into the TXREG     	

LOOP:	
     	BCF	STATUS,RP0     ; address Register Page 0
	MOVLW	0X55
	MOVWF	TXREG
	
	BSF	STATUS,RP0          ; RAM PAGE 1
WtHere  BTFSS	TXSTA,TRMT        ; (1) transmission is complete if hi
        GOTO	WtHere

        BCF	STATUS,RP0          ; RAM PAGE 0
        
        GOTO	LOOP


        END 