	LIST    P = 16F84A
;	115200 full duplex (send delayed up to 8us) 
;		115200 = 
;		20 MHz = .2 us/instruction
;
;  pic1.asm is the current robot PIC1 program
;
	INCLUDE         <P16F84A.INC>
	__CONFIG _PWRTE_OFF & _HS_OSC & _WDT_OFF   ;  configuration switches
;
GP	equ	1	;Get Pin *
GR	equ	0xc	;byte to get
GF	equ	0xd	;get flag
GK	equ	0xe	;get count
TGR	equ	0xf	;temp Get Register
DELA	equ	0x10	;delay count
;
	ORG	0
;
	bsf	STATUS,RP0	;select reg bank 1
	movlw	2	;*
	movwf	TRISA		;set port A pin GP as in
	clrf	TRISB		;set PORTB to output
	bcf	STATUS,RP0	;select reg bank 0
	clrf	PORTB
;	clrf	PORTA

;delay while pic0 initializes
;	movlw	0xfb	;8
;	movwf	DELA	;9
;Dlay0	decfsz	DELA,1	;DELA*3+1 DELA>0  
;	goto	Dlay0	;1=2,2=5,3=8,4=11,5=14,6=17,7=20,8=23,9=26,10=29,11=32
			;9+(11=32)=41


;now start 115200 communciation with serial port
	clrf	GR
	clrf	GF
TOP	btfss	GF,0	;1
	goto	I1GA1	;2 check for start bit
	decfsz	GK,1	;3
	goto	I2GA1	;4 get bit
	nop	;5 stop bit no need to get
	movf	GR,0	;6
;	movlw	0xfe	;6 for testing
	movwf	PORTB	;7 * send 8-bit address to PORTB
	nop	;8
	nop	;9
	nop	;10
	nop	;11
;	nop	;12  
	clrf	GF	;12
	goto	TOP	;14   was 15 why?	


NEXT	nop	;1
	nop	;2
	nop	;3
	nop	;4
	nop	;5
	nop	;6
	nop	;7
	nop	;8
	nop	;9
	nop	;10
	nop	;11
	nop	;12
	nop	;13
	nop	;14
	nop	;15	
;14+15+14=3.0+2.8+2.8=8.6 us (8.6806 us)

LAST	btfss	GF,1	;1
	goto	I1GB1	;2 check for start bit
	decfsz	GK,1	;3
	goto	I2GB1	;4 get bit
	nop	;5 stop bit - no need to get
	movf	GR,0	;6
;	movlw	0xfe	;6 for testing
	movwf	PORTB	;7 * send 8-bit address to PORTB
	nop	;8
	nop	;9
	nop	;10
	nop	;11
;	nop	;12
	clrf	GF	;12
	goto	TOP	;14  was 15 why?

;15 (14+14=28 early 5.6 us)

;---end main loop
				
I1GA1	btfsc	GF,1	;4  check for start bit
	goto	I3GA1	;5
	nop	;6
;	btfsc	PORTA,GP ;7 *  start bit = 0 (reversed)
	btfss	PORTA,GP ;7 *  start bit = 0
	bsf	GF,1	;8 got sb, get byte in next part (not this part)
	movlw	0xa	;9 
	movwf	GK	;10
	nop	;11
	nop	;12
;	nop	;13
	goto	NEXT	;14  was 15

I2GA1	rrf	GR,1	;6 get bit
	movf	PORTA,0	;7 *
	movwf	TGR	;8
	btfsc	TGR,GP	;9
	bsf	GR,7	;10
	btfss	TGR,GP	;11
	bcf	GR,7	;12
;	nop	;13
	goto	NEXT	;14 was 15


;getting byte in other part
I3GA1	nop	;7
	nop	;8
	nop	;9
	nop	;10
	nop	;11
	nop	;12
;	nop	;13
	goto	NEXT	;14 was 15

;-was send part

I1GB1	btfsc	GF,0	;4
	goto	I3GB1	;5
	nop	;6
;	btfsc	PORTA,GP ;7 *  start bit = 0 (reversed)
	btfss	PORTA,GP ;7 *  start bit = 0 
	bsf	GF,0	;8 got sb, get byte in next part
	movlw	0xa	;9 
	movwf	GK	;10
	nop	;11
	nop	;12
	goto	TOP	;14

I2GB1	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

;getting byte in other part
I3GB1	nop	;7
	nop	;8
	nop	;9
	nop	;10
	nop	;11
	nop	;12
	goto	TOP	;14


;43	;14+15+14=3.0+2.8+2.8=8.6 us (8.6806 us)



Delay	decfsz	DELA,1	;DELA*3+1 DELA>0  
	goto	Delay	;1=4,2=7,3=10,4=13,5=16,6=19
	return	;7=22,8=25,9=28,10=31,11=34,12=37,13=40

	END
