Texas Instruments MSC1210 User Manual
Page 238
Timers
17-10
end_test = 0;
//Timer 0 TH0:TL0 will always count up from 0x0200 until overflow,
//and will be replenished with 0x0200 indefinitely
count_start = 0x200;
/*Timer 0 and Timer 1 in Mode 1, timer mode, Gate 0 is closed and Gate
1 is opened. System will clock if TR0 set, only when INT0 is asserted*/
TMOD = 0x19;
CKCON = 0;
//Select Divide by 12
//Enable global interrupt, timer0 overflow and external_int1 interrupts
IE = 0x86;
TH0 = count_start / 256;
//set THO for timer0
TL0 = count_start % 256;
//set TLO for timer0
/*Indefinite Idle loop.
It breaks when interrupt_external0 ( ) ISR is called an even number of times.
In that instance,end_test is set to ”1”,
otherwise, it is ”0”*/
while (!end_test);
/*compute time elapsed, including the residual time in the 16−bit counter,
with correction for the 0x0200 counter offset.*/
current_count = TH0 * 256 + TL0;
//current residual timer0 count
time_lapse_residual = (float)(current_count − count_start) /
(0x10000 − count_start);
time_lapse = time_lapse_residual + timer_0_overflow_count;
time_lapse *= (12 / 24000000.) * (0x10000 − count_start);
printf (”\nThe Pulse Width for INT0 was: %f Sec.”, time_lapse);
//enter infinite loop
while (1);
}