#include "c:\miniide\hcs12.inc" tov_vec_no equ 23 org $1000 edge1 rmb 2 overflow rmb 2 pulse_width rmb 2 org $1500 movw #tov_isr,UserTimerOvf ; set up timer overflow interrupt vector ldd #0 std overflow movb #$90,TSCR1 ; enable TCNT and fast timer flag clear movb #$04,TSCR2 ; set prescaler to TCNT to 16 bclr TIOS,$01 ; enable input capture 0 movb #$01,DLYCT ; select delay count to 256 E cycles movb #$01,ICOVW ; prohibit overwrite to TC0 register movb #$0,ICSYS ; disable queue mode movb #$01,TCTL4 ; capture the rising edge on PT0 pin movb #C0F,TFLG1 ; clear C0F flag brclr TFLG1,$FE,* ; wait for the arrival of the first rising edge movb #TOF,TFLG2 ; clear the TOF flag bset TSCR2,TOI ; enable TCNT overflow interrupt cli ; " movw TC0,edge1 ; clear C0F flag and save the captured first edge movb #$02,TCTL4 ; " brclr TFLG1,C0F,* ; wait for the arrival of the falling edge ldd TC0 subd edge1 std pulse_width bcc next ; second edge is smaller, so decrement overflow count by 1 ldx overflow dex stx overflow next swi tov_isr movb #TOF,TFLG2 ; clear TOF flag ldx overflow ; incrment TCNT overflow count inx ; " stx overflow ; " rti end