I'm kinda confused as to why this stuff is being implemented as busy-waiting loops when the chip (A PIC18F4550, right?) has 4 separate timer/counter sections? It would seem much more reasonable to use a timer interrupt to schedule the transitions accordingly, plus you'd end up with some pretty insane resolution.
- i.e. set TMR1 to -1000, and you'd get an interrupt in 1000 timer ticks.
- i.e. set TMR1 to -1000, and you'd get an interrupt in 1000 timer ticks.