Something to start
On this forum
http://www.picbasic.co.uk/forum/showthread.php?t=1044

Melabs Website... choose counter.zip
http://www.melabs.com/resources/samples.htm#submitted

Both are the same, the second include the schematic

Sorry, based on a old and dirty F84 but should gives you some pointer.