Main
[COLOR="Blue"] clrf CountLo
clrf CountHi[/COLOR]
WaitSignal0
btfsc PORTA,0 ;wait for signal 1 to be low
goto WaitSignal0
WaitSignal1
btfss PORTA,0 ;wait for signal 1 to go high
goto WaitSignal1
TimeSignal0
btfss PORTA,1 ;is signal 2 low
goto WaitEdge ;yes, go wait for rising edge
incf Count[COLOR="blue"]Lo[/COLOR],f ;no so count
btfsc STATUS,Z ;is there a carry
incf Count[COLOR="blue"]Hi[/COLOR],f ;yes, inc high byte
nop ;waste 1 cycle
goto $+1 ;waste 2 cycles
goto TimeSignal0 ;loop arnd - total time = 10 cycles
WaitEdge
btfsc PORTA,1 ;is signal 2 high
goto GotTime ;yes, so were done
incf Count[COLOR="blue"]Lo[/COLOR],f ;as above
btfsc STATUS,Z
incf Count[COLOR="blue"]Hi[/COLOR],f
nop
goto $+1
goto WaitEdge
GotTime
movf CountHi,W
movwf PORTC
movf CountLo,W
movwf PORTD
goto Main