Couldn't you use the external clock divided by 4 and no program at all?

or if you need a perfect square wave, come up with a 2MHz signal and drive a Flip-Flop with it?