;JJ1GRK PIC ONDIGI-RX G.711 
;this is pic_DAC 96k RA2=IN PUT(NORM MODE NOT INV)
; RA4=PTT 0=TX(NEED REMOVE ";")    02'02
;it's G.711&chouho-douki
;output RB0-7 7=MSB 0=LSB
;
	list	p=16f84a
	include <p16F84a.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'00000000'	;PORT B OUTPUT
	MOVWF	TRISB	;WRITE

        BCF	STATUS,RP0	;BANK 0


;setup
        clrw
main



	MOVLW H'80'
        MOVWF H'06'
        MOVWF H'31'
        MOVWF H'32'
        MOVWF H'33'
        MOVWF H'34'
        MOVWF H'35'
        MOVWF H'36'
        MOVWF H'37'
        MOVWF H'38'

;

wait1			;GAP-TOP

;IT'S TX-RX SW 
;	btfss H'05',h'04'
;	goto main


;WAIT 10BITS
        MOVLW H'28'
        MOVWF H'17'
;WAIT "1"
one_wait
	btfss H'05',H'02'
	goto wait1
	MOVLW H'18'
	SUBWF H'17',0
	BTFSS H'03',H'02'
	goto nwait

        MOVF H'38',0
	MOVWF H'06'

nwait	decf H'17',1  
	MOVLW H'00'
	SUBWF H'17',0
	BTFSS H'03',h'02'


        goto one_wait

;WAIT"0"

waitx1   btfsc H'05',2   ;WAIT 0
	goto waitx1        
        btfsc H'05',2   ;WAIT 0
	goto waitx1        
        btfsc H'05',2   ;WAIT 0
	goto waitx1        
        btfsc H'05',2   ;WAIT 0
	goto waitx1        
        MOVF H'31',0
	MOVWF H'06'

	call wait20
	call wait24
	call wait20
        MOVF H'39',0
	MOVWF H'38'
	MOVLW B'01010101'
	MOVWF H'19'

;1-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	bsf H'19',H'07'   ;7BIT＝１	
	call wait24
	call wait26

;1-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;1-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;1-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0	
	call wait24
	call wait26

;1-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;1-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;1-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;1-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'21'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0
waitx2
        btfsc H'05',H'02'   ;WAIT 0
	goto waitx2        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx2        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx2        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx2        
;
	call wait22
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;2-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait10
        nop

        MOVF H'32',0
	MOVWF H'06'

        nop
	call wait12

;2-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;2-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;2-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0	
	call wait24
	call wait26

;2-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;2-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;2-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;2-8
	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'22'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx3   btfsc H'05',H'02'   ;WAIT 0
	goto waitx3        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx3        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx3        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx3        
;
	call wait22
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;3-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait26

;3-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;3-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait14

        MOVF H'33',0
	MOVWF H'06'
        call wait10
;3-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;3-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;3-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;3-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;3-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'23'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx4   btfsc H'05',H'02'   ;WAIT 0
	goto waitx4        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx4        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx4        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx4        
;
	call wait22
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;4-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait26

;4-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;4-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;4-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;4-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait12
	nop

        MOVF H'34',0
	MOVWF H'06'

	nop
	call wait10

;4-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;4-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;4-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'24'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx5   btfsc H'05',H'02'   ;WAIT 0
	goto waitx5        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx5        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx5        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx5        
;
	call wait24
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;5-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait26

;5-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;5-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;5-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;5-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;5-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;5-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait10
	nop

        MOVF H'35',0
	MOVWF H'06'

	nop
        call wait12

;5-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',h'00'
	movwf h'25'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx6   btfsc H'05',H'02'   ;WAIT 0
	goto waitx6        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx6        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx6        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx6        
;
	call wait22
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;6-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait26

;6-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;6-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;6-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;6-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;6-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;6-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;6-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'26'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx7   btfsc H'05',H'02'   ;WAIT 0
	goto waitx7        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx7        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx7        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx7        
;
	call wait22
	call wait22
	call wait12

        MOVF H'36',0
	MOVWF H'06'

	call wait10

	MOVLW B'01010101'
	MOVWF H'19'
	
;7-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait26

;7-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;7-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;7-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;7-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;7-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;7-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;7-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'27'

;NEXT DATA

	call wait24
	call wait24

;WAIT 0

waitx8   btfsc H'05',H'02'   ;WAIT 0
	goto waitx8        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx8        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx8        
       btfsc H'05',H'02'   ;WAIT 0
	goto waitx8        
;
	call wait22
	call wait22
	call wait24

	MOVLW B'01010101'
	MOVWF H'19'
	
;8-1

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'07'   ;7BIT＝１	
	call wait24
	call wait12

	movf h'37',0
	movwf h'06'

	call wait12

;8-2

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'06'   ;6BIT＝0	
	call wait24
	call wait26

;8-3

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'05'   ;5BIT＝１	
	call wait24
	call wait26

;8-4

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'04'   ;4BIT＝0
	call wait24
	call wait26

;8-5

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'03'   ;3BIT＝１	
	call wait24
	call wait26

;8-6

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',H'02'   ;2BIT＝0
	call wait24
	call wait26

;8-7

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BSF H'19',h'01'   ;1BIT＝１	
	call wait24
	call wait26

;8-8

	btfsc H'05',H'02' ;IF INPUT=0 THEN SKIP
	BCF H'19',h'00'   ;0BIT＝0	

	movf h'19',0
	movwf h'28'


	btfsc h'21',h'07'
	goto posi21
	comf h'21',1
	bcf h'21',h'07'
	goto nega21
posi21
	nop
	nop
	nop
nega21
	btfsc h'22',h'07'
	goto posi22
	comf h'22',1
	bcf h'22',h'07'
	goto nega22
posi22
	nop
	nop
	nop
nega22
	btfsc h'23',h'07'
	goto posi23
	comf h'23',1
	bcf h'23',h'07'
	goto nega23
posi23
	nop
	nop
	nop
nega23
	btfsc h'24',h'07'
	goto posi24
	comf h'24',1
	bcf h'24',h'07'
	goto nega24
posi24
	nop
	nop
	nop
nega24
	btfsc h'25',h'07'
	goto posi25
	comf h'25',1
	bcf h'25',h'07'
	goto nega25
posi25
	nop
	nop
	nop
nega25
	btfsc h'26',h'07'
	goto posi26
	comf h'26',1
	bcf h'26',h'07'
	goto nega26
posi26
	nop
	nop
	nop
nega26
	btfsc h'27',h'07'
	goto posi27
	comf h'27',1
	bcf h'27',h'07'
	goto nega27
posi27
	nop
	nop
	nop
nega27
	btfsc h'28',h'07'
	goto posi28
	comf h'28',1
	bcf h'28',h'07'
	goto nega28
posi28
	nop
	nop
	nop
nega28

	movf h'21',0
	movwf h'31'
	movf h'22',0
	movwf h'32'
	movf h'23',0
	movwf h'33'
	movf h'24',0
	movwf h'34'
	movf h'25',0
	movwf h'35'
	movf h'26',0
	movwf h'36'
	movf h'27',0
	movwf h'37'
	movf h'28',0
	movwf h'39'

shori	call wait6	;

	goto wait1	;LOOP


;


wait26  nop
	nop
wait24	nop
	nop
wait22	nop
        nop
wait20  nop
	nop
wait18	nop
	nop
wait16	nop
	nop
wait14   nop
wait13	nop
wait12  nop
	nop
wait10	nop
wait9	nop
wait8	nop
	nop
wait6	nop
	nop
	return
 	END
