Quote Originally Posted by xnihilo View Post
There are various things to write in PBP code but what would be the best order? I put the things empirically but is there an optimal way do do it?
At least you got a plan and stick to it..
About the only change I would make is to put the interrupt handler somewhere near the beginning and skip over it. This will keep the interrupt routines as low in code space as possible. They run just a tad bit quicker because there is just a few less BANKSELecting going on, at least on 16F type PICs. Same thing with any commonly used subroutines, right after the interrupt handler, but before the main loop, for the same reasons.