
//=============================================
// T2 is set for a 1ms interrupt in auto-reload

void timer2_int(void) interrupt 5 using 2
{
  TF2 = 0;
 
  ++checkCount;
  --msTick_1 ;        // Initialized by msDelay function

  if ( msTick_1==0 )
   {
    DelayOver = 1;   // to flag that the delay has timed out
   }
} 
//==============================================
//Time delay function. Call with required ms delay

 void msDelay (int DelayVal)
{
  msTick_1 = DelayVal;
  DelayOver = 0;
  TR2 = 1;
  while ( !DelayOver ); // Wait for timed out flag from T2 ISR
  msTick_1 = 0;
  TR2 = 0;
} 
//===============================================
