	LIST    P = 16F84A
;	115200 full duplex (send delayed up to 8us) 
;		115200 = 
;		20 MHz = .2 us/instruction
;
	INCLUDE         <P16F84A.INC>
	__CONFIG _PWRTE_OFF & _HS_OSC & _WDT_OFF   ;  configuration switches
;
SP      equ     0       ; Send Pin ( Bit 0 of Port A )
GP      equ     1       ; Get Pin ( Bit 1 of Port A )
GR	equ	0xc      ;byte to get
SR	equ	0xd      ; byte to send
GF	equ	0xe		;get flag
SF	equ	0xf		;send flag
GK	equ	0x10		;get count
SK	equ	0x11		;send count
TGR	equ	0x12
;
	ORG	0
;
	bsf	STATUS,RP0	;select reg bank 1
	movlw	0x2			
	movwf	TRISA		;set port A pin 0 as out, pin 1 as in
	movlw	0x0
	movwf	TRISB		;set PORTB to output
	bcf	STATUS,RP0	;select reg bank 0
	bsf     PORTA,SP	;set send pin
;
;
	clrf	GR
	clrf	SR
	clrf	GF
	clrf	SF
	movlw	0x30
	movwf	SR
	;bsf	SF,0
	movlw	0xa
	movwf	SK
	movlw	0x9
	movwf	GK
TOP	btfss	GF,0
	goto	SB1	;check for start bit
	decfsz	GK,1
	goto	GB1	;get bit
	movlw	9	;stop bit - no need to get
	movwf	GK
	movlw	3
	movwf	SF
	movf	GR,0
;	movlw	0x30
	movwf	SR	;10 inst
	bcf	GF,0	;11
	nop	;12
	nop	;13
	nop	;14

NEXT	btfss	SF,0
	goto	GF1
	btfsc	SF,1	
	goto	SEND1	;send start bit
	decfsz	SK,1
	goto	NEXTB
	goto	SENDSB
NEXTB	movf	PORTA,0	;8
	btfsc	SR,0
	iorlw	0x1
	btfss	SR,0
	andlw	0xfe
	movwf	PORTA	;13 *
	nop
	rrf	SR,1	;15	;14+15+14=3.0+2.8+2.8=8.6 us (8.6806 us)
				
LAST	btfss	GF,1
	goto	SB1B	;check for start bit
	decfsz	GK,1
	goto	GB1B	;get bit
	movlw	9	;stop bit - no need to get
	movwf	GK
	movlw	3
	movwf	SF
	movf	GR,0
;	movlw	0x31
	movwf	SR	;10 inst
	bcf	GF,1
	nop
	goto	TOP	;14


SENDSB	movlw	0xa	;9
	movwf	SK
	clrf	SF		;9 inst  43 inst is most close
	nop
	bsf	PORTA,SP	;13 *
	goto	LAST	;15

GB1	rrf	GR,1	;6
	movf	PORTA,0	;7 *
	movwf	TGR	;8
	btfsc	TGR,GP	;9
	bsf	GR,7	;10
	btfss	TGR,GP	;11
	bcf	GR,7	;12
	goto	NEXT	;14

GB1B	rrf	GR,1	;6
	movf	PORTA,0	;7 *
	movwf	TGR	;8
	btfsc	TGR,GP	;9
	bsf	GR,7	;10
	btfss	TGR,GP	;11
	bcf	GR,7	;12
	goto	TOP	;14

SB1	btfsc	GF,1	;4
	goto	SB2	;
	btfsc	GF,2
	goto	GSB
	btfss	PORTA,GP ;8 *  start bit = 0
	bsf	GF,2	;got sb, get sb next cycle
	nop	;Did not get start bit delay
	nop
	nop	;12
	goto	NEXT	;14

GSB	bcf	GF,2	;9 got sb in other half
	bsf	GF,0	;get bit next time in this half
	nop
	nop
	goto	NEXT	;14

SB2	nop	;7  getting byte in other part
	nop
	nop
	nop
	nop
	nop
	goto	NEXT	;14

GF1	nop	;4
	nop
	nop
	nop
	nop
	nop
	nop	;10
	nop
	nop
	nop	
	goto	LAST	;15

SB1B	btfsc	GF,0	;4
	goto	SB2B	;
	btfsc	GF,2
	goto	GSBB
	btfss	PORTA,GP ;8 *  start bit = 0
	bsf	GF,2	;got sb, get sb next cycle
	nop	;Did not get start bit delay
	nop
	nop	;12
	goto	TOP	;14

GSBB	bcf	GF,2	;9 got sb in other half
	bsf	GF,1	;get bit next time in this half
	nop
	nop
	goto	TOP	;14

SB2B	nop	;7  getting byte in other part
	nop
	nop
	nop
	nop
	nop
	goto	TOP	;14

SEND1	nop	;6	start bit
	nop	
	nop
	decfsz	SK,1
	bcf	SF,1	;clear bit 1 = do not send start bit again
	nop
	nop	
	bcf	PORTA,SP	;13 *
	goto	LAST	;15


	END
