
bit flag = 0;
unsigned int timercounts = 0;
unsigned int rpm = 0;
float time = 0.0;

void main(void){
      TMOD = 0x09;       //sets timer0 in 16-bit mode
      //timer0 will run only when INT0(3.2) is high
      THO = 0;
      TL0 = 0;
      TRO = 0;          //disable the timer
      IPL0 = 0x01;
      IPH0 = 0x01;      //highest priority to external interrupt0
      IEN0 = 0x81;      //enable external interrupt
      while(1);
}
void external interrupt(void) interrupt 0{
      if(!flag){ 
          TR0 = 1;           //enable timer0
          flag = 1;
      }    
      else if(flag){
          TR0 = 0;           //disable timer0
          IEN0 =0x00;        //disable all interrupts
          flag =0;
          timercounts = (TH0*256) + TL0;
          time = timercounts/921583;
          rpm = 30/time;
       }
}     
