C	EQU	00
Z	EQU	02
w       equ     00
f       equ     01
TO	EQU	04
RP0	EQU	05
PORTA	EQU	05
PORTB   EQU     06
INTCON	EQU	0B
STATUS	EQU	03
TMR0	EQU	01
INFRA	EQU	03
ADATKI	EQU	02
ADATBE	EQU	00
OPTI	EQU	01

        ORG     h'0000'
        goto    L0005
        ORG     h'0004'
        goto    L0005
L0005:  movwf   PORTA
        clrf    INTCON
        movlw   h'09'

	BSF	STATUS,RP0
        MOVWF   PORTB

        movlw   h'c2'
        MOVWF	OPTI
	BCF	STATUS,RP0

        bsf     PORTB,ADATKI

        btfss   STATUS,TO
        goto    L00E2

        clrwdt
;        movlw   h'58'		;power up message
;        call    L00B6		;send	it
;        call    L009F		;waiting for message from pc
;        movf    h'12',w
;        bcf     STATUS,Z
;        bcf     STATUS,C
;        xorlw   h'49'		;is it same as I

;        btfss   STATUS,Z
;        goto    L0005

;        call    L009F
;        movf    h'12',w
;        bcf     STATUS,Z
;        bcf     STATUS,C
;        xorlw   h'52'		;is itb same as  R

;        btfss   STATUS,Z
;        goto    L0005

;        movlw   h'4f'		;send	O
;        call    L00B6
;        movlw   h'4b'		;send	K
;        call    L00B6
L0023:  call    L0091		;end of init, start program
L0024:  clrwdt
        btfsc   PORTB,INFRA
        goto    L0024
        clrf    TMR0
L0028:  btfss   PORTB,INFRA
        goto    L002D
        movf    TMR0,w
        movwf   h'15'
        goto    L006F
L002D:  clrwdt
        btfss   TMR0,7
        goto    L0028
        btfss   TMR0,6
        goto    L0028
        clrwdt
L0033:  btfss   PORTB,INFRA
        goto    L0033
        clrf    TMR0
        clrwdt
L0037:  btfsc   PORTB,INFRA
        goto    L003D
        movf    TMR0,w
        clrf    TMR0
        movwf   h'15'
        goto    L011C
L003D:  btfss   TMR0,7
        goto    L0037
        clrwdt
L0040:  btfsc   PORTB,INFRA
        goto    L0040
        clrf    TMR0
L0043:  btfss   PORTB,INFRA
        goto    L0043
        movf    TMR0,w
        clrf    TMR0
        movwf   h'15'
        bcf     STATUS,C
        rrf     h'15',w
        addwf   h'15',f
L004B:  clrwdt
        clrf    h'1B'
        clrf    h'1A'
        clrf    h'19'
        clrf    h'18'
        clrf    h'17'
        clrf    h'16'
        movlw   h'30'
        movwf   h'14'
        goto    L0059
L0055:  btfss   PORTB,INFRA
        goto    L0055
        clrf    TMR0
        clrwdt
L0059:  bcf     STATUS,C
        movf    TMR0,w
        subwf   h'15',w
        btfss   STATUS,Z
        goto    L0059
        bcf     STATUS,C
        btfss   PORTB,INFRA
        goto    L0065
        clrf    TMR0
L0062:  btfsc   PORTB,INFRA
        goto    L0062
        bsf     STATUS,C
L0065:  clrwdt
        rlf     h'16',f
        rlf     h'17',f
        rlf     h'18',f
        rlf     h'19',f
        rlf     h'1A',f
        rlf     h'1B',f
        decfsz  h'14',f
        goto    L0055
        goto    L00D4
L006F:  clrwdt
        btfsc   h'15',7
        goto    L00F1
        btfsc   h'15',6
        goto    L00F1
        clrf    TMR0
        clrwdt
L0076:  btfsc   PORTB,INFRA
        goto    L0076
        clrf    TMR0
        clrwdt
L007A:  btfss   PORTB,INFRA
        goto    L007A
        movf    TMR0,w
        clrf    TMR0
        movwf   h'15'
        rrf     h'15',f
        clrwdt
L0081:  btfsc   PORTB,INFRA
        goto    L0081
        movf    TMR0,w
        clrf    TMR0
        addwf   h'15',f
        clrwdt
L0087:  btfss   PORTB,INFRA
        goto    L0087
        goto    L004B
L008A:  btfsc   PORTB,INFRA
        goto    L008A
        movf    TMR0,w
        clrf    TMR0
        movwf   h'15'
        rrf     h'15',f
        goto    L004B
L0091:  BSF	STATUS,RP0
	movlw   h'c7'
        MOVWF	OPTI
	BCF	STATUS,RP0

        clrwdt
        btfss   PORTB,INFRA
        goto    L0091
        clrf    TMR0
L0097:  clrwdt
        btfss   PORTB,INFRA
        goto    L0091
        btfss   TMR0,7
        goto    L0097
        movlw   h'c2'
	BSF	STATUS,RP0
        MOVWF	OPTI
	BCF	STATUS,RP0

        retlw   h'00'
L009F:  movlw   h'08'
        movwf   h'0F'
        clrf    h'12'
L00A2:  clrwdt
        btfss   PORTB,ADATBE
        goto    L00A2
        movlw   h'2e'
        movwf   h'13'
L00A7:  decfsz  h'13',f
        goto    L00A7
L00A9:  bcf     STATUS,C
        rrf     h'12',f
        btfss   PORTB,ADATBE
        bsf     h'12',7
        movlw   h'1f'
        movwf   h'13'
L00AF:  decfsz  h'13',f
        goto    L00AF
        nop
        decfsz  h'0F',f
        goto    L00A9
        movf    h'12',w
        return
L00B6:  clrwdt
        movwf   h'11'
        movlw   h'08'
        movwf   h'0F'
        bcf     PORTB,ADATKI
L00BB:  movlw   h'1f'
        movwf   h'13'
L00BD:  decfsz  h'13',f
        goto    L00BD
        bcf     STATUS,C
        rrf     h'11',f
        btfsc   STATUS,C
        bsf     PORTB,ADATKI
        btfss   STATUS,C
        bcf     PORTB,ADATKI
        nop
        decfsz  h'0F',f
        goto    L00BB
        movlw   h'1f'
        movwf   h'13'
L00CA:  decfsz  h'13',f
        goto    L00CA
        bsf     PORTB,ADATKI
        movwf   h'13'
L00CE:  decfsz  h'13',f
        goto    L00CE
        movwf   h'13'
L00D1:  decfsz  h'13',f
        goto    L00D1
        return
L00D4:  clrwdt
        movf    h'1B',w
        call    L00B6
        movf    h'1A',w
        call    L00B6
        movf    h'19',w
        call    L00B6
        movf    h'18',w
        call    L00B6
        movf    h'17',w
        call    L00B6
        movf    h'16',w
        call    L00B6
        goto    L0023
L00E2:  clrwdt
        bcf     STATUS,C
        movlw   h'26'
        subwf   h'14',w
        btfsc   STATUS,C
        goto    L0023
L00E8:  rlf     h'16',f
        rlf     h'17',f
        rlf     h'18',f
        rlf     h'19',f
        rlf     h'1A',f
        rlf     h'1B',f
        decfsz  h'14',f
        goto    L00E8
        goto    L00D4
L00F1:  clrwdt
        bcf     STATUS,C
        rrf     h'15',w
        addwf   h'15',f
        movlw   h'50'
        movwf   h'1C'
        clrf    h'1B'
        clrf    h'1A'
        clrf    h'19'
        clrf    h'18'
        clrf    h'17'
        clrf    h'16'
        movlw   h'31'
        movwf   h'14'
L00FF:  btfsc   PORTB,INFRA
        goto    L00FF
        clrwdt
        clrf    TMR0
L0103:  bcf     STATUS,C
        movf    TMR0,w
        subwf   h'15',w
        btfss   STATUS,Z
        goto    L0103
        btfss   PORTB,INFRA
        goto    L010E
L010A:  btfsc   PORTB,INFRA
        goto    L010A
        bcf     STATUS,C
        goto    L0111
L010E:  btfss   PORTB,INFRA
        goto    L010E
        bsf     STATUS,C
L0111:  clrf    TMR0
        clrwdt
        rlf     h'16',f
        rlf     h'17',f
        rlf     h'18',f
        rlf     h'19',f
        rlf     h'1A',f
        rlf     h'1B',f
        decfsz  h'14',f
        goto    L0103
        goto    L00D4
L011C:  clrwdt
        bcf     STATUS,C
        rrf     h'15',f
        addwf   h'15',w
        rrf     h'15',f
        addwf   h'15',f
        movlw   h'53'
        movwf   h'1C'
        clrf    h'1B'
        clrf    h'1A'
        clrf    h'19'
        clrf    h'18'
        clrf    h'17'
        clrf    h'16'
        movlw   h'30'
        movwf   h'14'
        goto    L0131
L012D:  btfsc   PORTB,INFRA
        goto    L012D
        clrf    TMR0
        clrwdt
L0131:  bcf     STATUS,C
        movf    TMR0,w
        subwf   h'15',w
        btfss   STATUS,Z
        goto    L0131
        bcf     STATUS,C
        btfsc   PORTB,INFRA
        goto    L013D
        clrf    TMR0
L013A:  btfss   PORTB,INFRA
        goto    L013A
        bsf     STATUS,C
L013D:  clrwdt
        rlf     h'16',f
        rlf     h'17',f
        rlf     h'18',f
        rlf     h'19',f
        rlf     h'1A',f
        rlf     h'1B',f
        decfsz  h'14',f
        goto    L012D
        goto    L00D4
        ORG     h'2007'
        end
