Read_Pulse clrf LoX
btfss IR_PORT, IR_In ;wait until high
goto $-1
clrf tmp1
movlw 0xC0 ;delay to decide new keypress
movwf tmp2 ;for keys that need to toggle
Still_High btfss IR_PORT, IR_In ;and wait until goes low
goto Next
incfsz tmp1,f
goto Still_High
incfsz tmp2,f
goto Still_High
bsf Flags2, New ;set New flag if no button pressed
goto Still_High
Next nop
nop
nop
nop
nop ;waste time to scale pulse
nop ;width to 8 bits
nop
nop
nop
nop
nop
nop
incf LoX, f
btfss IR_PORT, IR_In
goto Next ;loop until input high again