include "p16c5x.inc"
include "P16C5X.INC"

TEMP_VAR    UDATA
c_data      RES     1
count       RES     1

startup   code
start   movlw 0xff      ;moving literal constant 0xff to W
        tris PORTA      ;setting PORTA in input mode
        tris PORTB      ;setting PORTB in input mode
        tris PORTC      ;setting PORTC in input mode
        
        movf PORTC,1    ;reading through PORTC
        movf PORTC,0    ;moving the read value to W
        movwf c_data    ;moving the value to c_data
        movlw 0x00      ;moving literal constant 0x00 to W
        tris PORTC      ;setting PORTC in output mode
        
        
bchk    btfsc PORTA,3   ;checking whether RA3 pin is clear or not
        goto bchk       ;if not

d_read  bcf PORTA,3     ;if yes, blocks further read
        movf PORTB,1    ;reading through PORTB
        movf PORTB,0    ;moving the read value to W
        xorwf c_data,0  ;x-oring the data with the value stored in c_data
        btfsc STATUS,2  ;checking whether zero flag is clear or not
        incf count,1    ;if not
        movf count,0    ;if yes, the value stored in count is moved to W
        movwf PORTC     ;outting the value through PORTC
        bsf PORTA,3     ;setting the RA3 pin HIGH
        goto bchk       ;again goes to bchk
        goto start      ;repeat
        end


