I found that the pause() function can be tripped up with large values. May I suggest that it be re-coded as follows.
void pause(int time) // pause function definition
{ // If st_pauseTicks not initialized, set it up to 1 ms.
// if(!st_pauseTicks) set_pause_dt(CLKFREQ/1000);
long t0 = CNT;
while (time--) {
waitcnt(t0 += st_pauseTicks);
}
}