Hi, I want to measure the width of the pulse applied in INT0. My code base on the sample of KEIL: http://www.keil.com/download/docs/8051_timer0_pulse.zip.asp The result printed out in Serial1 window is very strange. For example, when I input 100usec pulse into INT0, but it just print out 3us. (Notes, I run in debug and simulation mode). #include "fx2.h" #include "fx2regs.h" #include <stdio.h> /*------------------------------------------- Timer 0 Overflow Interrupt ------------*/ unsigned int T0_ISR_count = 0; void T0_ISR (void) interrupt 1 { T0_ISR_count++; TF0 = 0; // Reset the interrupt request } /*------------------------------------------- MAIN C function ------------*/ void main (void) { /*-------------------------------------- Set serial port for 9600 baud at 11.0592 MHz. Note that we use Timer 1 for the baud rate generator. --------------------------------------*/ SCON0 = 0x50; TMOD |= 0x20; //Enable bit TMOD5 Timer1: Mode2: 8bit counter with auto-reload TH1 = 0xFA; TR1 = 1; //Enable counting on Timer 1 TI = 1; PCON |= 0x80; //Serial Port 0 mode 3 printf ("\nPulse Width Example Program\n\n"); /*-------------------------------------- Enable interrupts for timer 0. --------------------------------------*/ ET0 = 1; /* ET0 - Enable Timer 0 interrupt. ET0 = 0 disables Timer 0 interrupt (TF0). ET0=1 enables interrupts generated by the TF0 flag.*/ EA = 1; /*-------------------------------------- Set Timer0 for 16-bit interval timer mode. --------------------------------------*/ TMOD = (TMOD & 0xF0) | 0x09; while (1) { /*-------------------------------------- Clear the timer overflow counter and the timer low and high registers. Then, start the timer. --------------------------------------*/ T0_ISR_count = 0; //Clear overflow counter TH0 = 0; TL0 = 0; TR0 = 1; //Enable Timer0 to receive clock in IT0= 0;// Detect LowLevel at INT0 printf ("\nStart a pulse.\n"); /*-------------------------------------- Wait for the pulse to start. Then, wait for the pulse to end. --------------------------------------*/ while (!IE0); // Wait when INT0 low while (IE0); //and continue to wait when INTO high /*-------------------------------------- Compute the width of the pulse -- one clock cycle is 1us for a standard 8051 and display it. --------------------------------------*/ printf ("The width pulse is: %ld uSec\n", (unsigned long)((TH0 << 8) | TL0 | ((unsigned long)T0_ISR_count << 16))); } }