Without seeing or knowing anything about the code it's not easy to say but here are two general things to try:

* Obviously, pretty much anything that you're doing more than once thru out the code AND is more than two or three instructions should be made into a subroutine and called with a GOSUB. Ie, it's not worth putting something like PortB.0 = 1 as the single instruction in a subroutine but as soon as there's a couple of instructions it gets worth it. Easy enough to try and see the effect.

* Use multiple IF's instead of SELECT CASE.

Post a specific section of code, wait and see what comes back.

/Henrik.