Here is a program I posted some time ago. It can be used as an example to do what you are trying to do.

http://www.picbasic.co.uk/forum/show...highlight=port