I had this same thing happen. The PIC in question has both a High Freq built-in osc and a built-in 32KHz RC osc . It was coming up running in the 32Khz mode by default, and later, my start-up routine switched the mode to HF. I had a software delay of a few millisec in the start-up routine ahead of where the oscillator was switched over. The C compiler dutifuly created the delay as though the clock was 4Mhz, but it was actually running at 32kHz, so the delay took a very long time. Simply putting the oscillator initialization near the beginning of the Start-up routine cured it...