Code for counter

This is not making much sense. Why are you setting your input pin as an output and writing to it before reading from it?!?