Your routine has some bugs:

The If/Then-Part is only used at the very first counts of the PIC.
If PortB.5 is low, it goes to POO, lows PortB.5 (switching from input to output) and circles in the FREQ-Part.
If PortB.5 is high, it circles inside the START-part (does nothing to the outside) and and waits for PortB.5 to go down.


What do you really want to get ?