Have a look at the following, read all post there, this should give you some hints.
http://www.picbasic.co.uk/forum/showthread.php?t=561

You may also need to debounce your switch once you've discover why it doesn't work.

There's another option, use an internal counter to do the job.