#include "c:\MiniIDE\hcs12.inc" CR equ $0D LF equ $0A org $1000 oc_cnt rmb 2 frequency rmb 2 org $1500 movb #$90,TSCR1 ; enable TCNT and fast timer flags clear movb #$00,TSCR2 ; set prescale factor to 1 movb #$02,TIOS ; enable OC1 and IC0 ldd #400 std oc_cnt ; prepare to perform 400 OC1 operation, each ; creates 2.5 ms delay and total 1 second ldd #0 std frequency ; initialize frequency count to 0 movb #$01,TCTL4 ; prepare to capture the rising edges of PT0 movb #C0F,TFLG1 ; clear the C0F flag bset TIE,IC0 ; enable IC0 interrupt cli ; " ldd TCNT ; start an OC1 operation with 2.5 ms delay continue addd #60000 ; " std TC1 ; " w_lp brclr TFLG1,OC1,w_lp ; wait for 2.5 ms ldd TC1 ldx oc_cnt dex stx oc_cnt bne continue ldd frequency pshd ldd #msg ldx printf jsr 0,x ; jsr [printf,PCR] leas 2,sp swi msg db CR,LF,"The frequency is %d",CR,LF,0 TC0_isr ldd TC0 ; clear C0F flag ldx frequency ; increment frequency count by 1 inx ; " stx frequency ; " rti org $3E6E ; set up interrupt vector number fdb TC0_isr ; for TC0 end