void externalinterrupt(void) interrupt 0    
{
   if( !flag )
   {
      // At this point, flag must be false
      TR0  = 1;    
      flag = !flag; // Toggle the flag;
                    // since it must originally have been false,
                    // it must now be true
   }

   // At this point, flag must be true:
   // either it was originally true, so the above code was skipped;
   // or it was originally false, and the above code set it true!

   // Therefore, this test next is pointless - flag is always true!
   if( flag )
   {
      TR0 = 0;   //disable timer0
      IEN0 = 0x00;    //disable all interrupts

      flag = !flag;   // Again, since flag must have been true
                      // might just as well set it to false directly here!

      timercounts = (TH0*256) + TL0;
      time = timercounts/921583;
      rpm = (unsigned int)(30/time);
   }
}