	list	p=16f873
	include <p16F873.inc>

	__config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF


	BSF	STATUS,RP0	;BANK 1
	BCF	STATUS,RP1

	MOVLW	B'11111111'	;PORT A INPUT
	MOVWF	TRISA	;WRITE
	MOVLW	B'11111111'	;PORT B INPUT(NOT USE)
	MOVWF	TRISB	;WRITE
	MOVLW	B'00000000'	;PORT C OUTPUT
	MOVWF	TRISC	;WRITE


	MOVLW   B'00001000'		;ADCON1-DATA
	MOVWF	ADCON1  	;WRITE
	BSF	PIE1,	ADIE	;A/D ON
	BCF	STATUS,RP0	;BANK 0
	MOVLW	B'10000001'	;ADCON0-DATA
	MOVWF	ADCON0		;WRITE
	BCF	PIR1,	ADIF	;A/D FLAG CLR
	BSF	INTCON,PEIE
;WAIT NEEDS
;	BSF	ADCON0,	GO	;A/D START

;A/D WAIT 190 STEPS
;ADWAIT LOOP = 23*n+1
	MOVLW	H'08'	;LOOP START
	MOVWF	H'49'
ADWAIT
 	CALL WAIT20
	DECFSZ	H'49',1
	GOTO ADWAIT	;LOOP END
;190-23*(0*16+8)=6
	CALL WAIT6

	MOVLW	H'80'
	MOVWF	H'30'	;FIRST OUTPUT ON A/D RESULT
	MOVWF	H'31'
	MOVWF	H'32'
	MOVWF	H'33'
	MOVWF	H'34'
	MOVWF	H'35'
	MOVWF	H'36'
	MOVWF	H'37'
	MOVWF	H'40'	;FIRST TX-DATA OUTPUT
	MOVWF	H'41'
	MOVWF	H'42'
	MOVWF	H'43'
	MOVWF	H'44'
	MOVWF	H'45'
	MOVWF	H'46'
	MOVWF	H'47'


	MOVLW	H'00'	;GAP BIT
	NOP
	NOP
	MOVWF	H'07'
MAIN
	BSF	ADCON0,GO	;A/D 1 START


;GAP1 BIT 623 STEP (BSF+622 STEP)
;GAP1WAIT LOOP = 23*n+1

	MOVLW	H'1B'	;LOOP START
	MOVWF	H'49'
GAP1WAIT
 	CALL WAIT20
	DECFSZ	H'49',1
	GOTO GAP1WAIT	;LOOP END
;622-23*(1*16+11)+1=0
	NOP	
	NOP

	MOVF	ADRESH,0
	MOVWF	H'30'
	BSF	ADCON0,GO	;A/D2 START


;GAP2 BIT 209 STEP (MOVF,MOVWF,BSF+ 206 STEP)
;GAP2WAIT LOOP = 23*n+1

	MOVLW	H'08'	;LOOP START
	MOVWF	H'49'
GAP2WAIT
 	CALL WAIT20
	DECFSZ	H'49',1
	GOTO GAP2WAIT	;LOOP END
;206-23*(0*16+8)=22
	CALL	WAIT22	



;START BIT
	MOVLW	H'01'
	NOP		;ALL GAP =834=625+207+2
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA1-1
	MOVLW	H'01'
	BTFSC	H'40',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-2
	MOVLW	H'01'
	BTFSC	H'40',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-3
	MOVLW	H'01'
	BTFSC	H'40',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-4 INV
	MOVLW	H'00'
	BTFSC	H'40',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-5
	MOVLW	H'01'
	BTFSC	H'40',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-6 INV
	MOVLW	H'00'
	BTFSC	H'40',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA1-7
	MOVLW	H'01'
	BTFSC	H'40',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT22
	
	MOVF	ADRESH,0
	MOVWF	H'31'
;DATA1-8
	MOVLW	H'01'
	BTFSC	H'40',H'07'
	MOVLW	H'00'
	MOVWF	H'07'		;NOW ADCON GO NEED	
	BSF	ADCON0,GO	;A/D3 START
	NOP
	CALL	WAIT22
	CALL 	WAIT24	

;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA2-1
	MOVLW	H'01'
	BTFSC	H'41',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-2
	MOVLW	H'01'
	BTFSC	H'41',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-3
	MOVLW	H'01'
	BTFSC	H'41',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-4 INV
	MOVLW	H'00'
	BTFSC	H'41',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-5
	MOVLW	H'01'
	BTFSC	H'41',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-6 INV
	MOVLW	H'00'
	BTFSC	H'41',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-7
	MOVLW	H'01'
	BTFSC	H'41',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA2-8
	MOVLW	H'01'
	BTFSC	H'41',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT22
	MOVF	ADRESH,0
	MOVWF	H'32'
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	BSF	ADCON0,GO	;ADCON GO NEED
	MOVWF	H'07'

	CALL 	WAIT24
	CALL	WAIT24
;DATA3-1
	MOVLW	H'01'
	BTFSC	H'42',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-2
	MOVLW	H'01'
	BTFSC	H'42',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-3
	MOVLW	H'01'
	BTFSC	H'42',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-4 INV
	MOVLW	H'00'
	BTFSC	H'42',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-5
	MOVLW	H'01'
	BTFSC	H'42',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-6 INV
	MOVLW	H'00'
	BTFSC	H'42',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-7
	MOVLW	H'01'
	BTFSC	H'42',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA3-8
	MOVLW	H'01'
	BTFSC	H'42',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA4-1
	MOVLW	H'01'
	BTFSC	H'43',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT22
	MOVF	ADRESH,0
	MOVWF	H'33'

;DATA4-2
	MOVLW	H'01'
	BTFSC	H'43',H'01'
	MOVLW	H'00'	;ADCON GO NEED
	MOVWF	H'07'
	BSF	ADCON0,GO	;A/D5 START
	NOP
	CALL	WAIT22
	CALL 	WAIT24
;DATA4-3
	MOVLW	H'01'
	BTFSC	H'43',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA4-4 INV
	MOVLW	H'00'
	BTFSC	H'43',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA4-5
	MOVLW	H'01'
	BTFSC	H'43',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA4-6 INV
	MOVLW	H'00'
	BTFSC	H'43',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA4-7
	MOVLW	H'01'
	BTFSC	H'43',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA4-8
	MOVLW	H'01'
	BTFSC	H'43',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA5-1
	MOVLW	H'01'
	BTFSC	H'44',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA5-2
	MOVLW	H'01'
	BTFSC	H'44',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA5-3
	MOVLW	H'01'
	BTFSC	H'44',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT22
	MOVF	ADRESH,0
	MOVWF	H'34'

;DATA5-4 INV
	MOVLW	H'00'
	BTFSC	H'44',H'03'
	MOVLW	H'01'	;ADCON GO NEED
	MOVWF	H'07'

	BSF	ADCON0,GO	;A/D6 START
	NOP

	CALL	WAIT22
	CALL 	WAIT24
;DATA5-5
	MOVLW	H'01'
	BTFSC	H'44',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA5-6 INV
	MOVLW	H'00'
	BTFSC	H'44',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA5-7
	MOVLW	H'01'
	BTFSC	H'44',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA5-8
	MOVLW	H'01'
	BTFSC	H'44',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA6-1
	MOVLW	H'01'
	BTFSC	H'45',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA6-2
	MOVLW	H'01'
	BTFSC	H'45',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA6-3
	MOVLW	H'01'
	BTFSC	H'45',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA6-4 INV
	MOVLW	H'00'
	BTFSC	H'45',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA6-5
	MOVLW	H'01'
	BTFSC	H'45',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT22

	MOVF	ADRESH,0
	MOVWF	H'35'

;DATA6-6 INV
	MOVLW	H'00'
	BTFSC	H'45',H'05'
	MOVLW	H'01'	;ADCON GO NEED
	MOVWF	H'07'
	BSF	ADCON0,GO	;A/D7 START
	NOP
	CALL	WAIT22
	CALL 	WAIT24
;DATA6-7
	MOVLW	H'01'
	BTFSC	H'45',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA6-8
	MOVLW	H'01'
	BTFSC	H'45',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA7-1
	MOVLW	H'01'
	BTFSC	H'46',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-2
	MOVLW	H'01'
	BTFSC	H'46',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-3
	MOVLW	H'01'
	BTFSC	H'46',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-4 INV
	MOVLW	H'00'
	BTFSC	H'46',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-5
	MOVLW	H'01'
	BTFSC	H'46',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-6 INV
	MOVLW	H'00'
	BTFSC	H'46',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA7-7
	MOVLW	H'01'
	BTFSC	H'46',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT22
	CALL 	WAIT24
	MOVF	ADRESH,0
	MOVWF	H'36'

;DATA7-8
	MOVLW	H'01'
	BTFSC	H'46',H'07'
	MOVLW	H'00'	;ADCON GO NEED
	MOVWF	H'07'
	BSF	ADCON0,GO	;A/D8 START
	NOP
	CALL	WAIT20
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24	
	NOP		;52.08*10=521
;START BIT
	MOVLW	H'01'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT24
;DATA8-1
	MOVLW	H'01'
	BTFSC	H'47',H'00'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-2
	MOVLW	H'01'
	BTFSC	H'47',H'01'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-3
	MOVLW	H'01'
	BTFSC	H'47',H'02'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-4 INV
	MOVLW	H'00'
	BTFSC	H'47',H'03'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-5
	MOVLW	H'01'
	BTFSC	H'47',H'04'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-6 INV
	MOVLW	H'00'
	BTFSC	H'47',H'05'
	MOVLW	H'01'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-7
	MOVLW	H'01'
	BTFSC	H'47',H'06'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24
;DATA8-8
	MOVLW	H'01'
	BTFSC	H'47',H'07'
	MOVLW	H'00'
	MOVWF	H'07'
	CALL	WAIT24
	CALL 	WAIT24	
;STOP BIT
	MOVLW	H'00'
	NOP
	NOP
	MOVWF	H'07'
	CALL 	WAIT24
	CALL	WAIT6

	MOVF	ADRESH,0
	MOVWF	H'37'

	MOVF	H'30',0	;A/D MEM > TD MEM
	MOVWF	H'40'
	MOVF	H'31',0
	MOVWF	H'41'
	MOVF	H'32',0
	MOVWF	H'42'
	MOVF	H'33',0
	MOVWF	H'43'
	MOVF	H'34',0
	MOVWF	H'44'
	MOVF	H'35',0
	MOVWF	H'45'
	MOVF	H'36',0
	MOVWF	H'46'
	MOVF	H'37',0
	MOVWF	H'47'
			;52.08333*80-521*8=1.7
			;   24+6+1+16+4=51
	NOP		;52.08*10=521
	GOTO MAIN


WAIT24	nop
	nop
WAIT22	nop
	nop
WAIT20	nop
	nop
WAIT18	nop
	nop
WAIT16	nop
	nop
WAIT14	nop
	nop
WAIT12	nop
	nop
WAIT10	nop
	nop
WAIT8	nop
	nop
WAIT6	nop
	nop
	return	;goto-2 return-2 and nop


	end

