what part of this have you failed to understand
http://www.picbasic.co.uk/forum/showthread.php?t=24650