Have a look at the thread a few posts down

http://www.picbasic.co.uk/forum/showthread.php?t=13084

I'm sure you should be able to adapt that for your needs