list p=12c671 include org 0h ; reset vector reset goto start org 4h ; peripheral interrupt vector intv goto start start ; this is where execution begins movlw ADCON1 ; set I/O pins for digital operation movwf FRS movlw 7 movwf INDF movlw TRISIO ; set Tri-state pins movwf FSR bsf INDF,5 ; GP5 (pin 2) is set for clock input bsf INDF,4 ; GP4 (pin 3) is set for data input bsf INDF,3 ; GP3 (pin 4) is cleared for output bcf GPIO,3 ; Clear output bit clrf 20h ; F20 (transition count) = 0 clrf 21h ; F21 (last data input bit) = 0 zerlp: btfss GPIO,5 ; Skip next instruction if clock is one goto zerlp clrf 22h ; Set F22 to next data input bit btfsc GPIO,4 incf 22h,1 movf 21h,W ; W <- XOR(F21, F22) xorwf 22h,W btfss STATUS,Z ; skip next instruction if W == 0 goto out0 ;; there has been a transistion movlw 22h ;; F21 <- F22 movwf 21h incf 20h,W ;; W <- F20+1 andlw 20h,3 ;; W <- W & 3 movwf 20h ;; F20 <- W btfss STATUS,Z ; skip next instruction if F20 == 0 goto out1 out0: bcf GPIO,3 ; data output <- 0 goto onelp out1: bsf GPIO,3 ; data output <- 1 onelp: btfsc GPIO,5 ; Skip next instruction if clock is zero goto onelp goto zerlp end