#include "c:\miniide\hcs12.inc" org $1000 edge1 rmb 2 overflow rmb 2 pulse_width rmb 2 org $1500 movw #tov_isr,UserTimerOvf ; set up TCNT overflow interrupt vector lds #$1500 ; set up stack pointer movw #0,overflow movb #$90,TSCR1 ; enable TCNT and fast timer flag clear movb #$05,TSCR2 ; disable TCNT interrupt, set prescaler to 32 bclr TIOS,IOS0 ; select IC0 movb #$01,TCTL4 ; capture rising edge movb #$01,TFLG1 ; clear C0F flag wait1 brclr TFLG1,C0F,wait1 ; wait for the first rising edge movw TC0,edge1 ; save the first edge & clear the C0F flag movb #$80,TFLG2 ; clear TOF flag bset TSCR2,$80 ; enable TCNT overflow interrupt cli ; " movb #$02,TCTL4 ; capture the falling edge on PT0 pin wait2 brclr TFLG1,C0F,wait2 ; wait for the arrival of the falling edge ldd TC0 subd edge1 std pulse_width bcc next ; is the second edge smaller? ldx overflow ; second edge is smaller, so decrement dex ; overflow count by 1 stx overflow ; " next swi tov_isr movb #$80,TFLG2 ; clear TOF flag ldx overflow inx stx overflow rti end