
M16C/2
Using the M16C/26 Timers in Timer Mod
REU05B0046-0100Z June 2003
Page 8 of 8
/*****************************************************************************
Name: init()
Parameters: none
Returns: nothing
Description: Timer TA0 is setup to interrupt every 1ms.
**************************************************************************** */
void init()
{
ta0 = 2500; // 20MHz xtal divide by 8 at 1ms intervals = 2,500 counts
/* the following procedure for writing an Interrupt Priority Level follows what
is described in the M16C datasheets under 'Interrupts'. */
_asm (" fclr i") ; //turn off interrupts before modifying IPL
ta0ic |= CNTR_IPL; // use read-modify-write instruction to write IPL
ta0mr = TIME_CONFIG;
_asm (" fset i");
ta0s = 1; //start counting
}
In order for this program to run properly, timer A0’s interrupt vector needs to point to the TimerA0Int function. The
interrupt vector table is near the end of the startup file “sect30.inc”. Insert the function label “_TimerA0Int” into
the interrupt vector table at vector 21 as shown below.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; File Name: sect30.inc
;
; Content: Section include file for MSV30262-SKP.
;
; Copyright 2003 Renesas Technology America, Inc.
; All rights reserved
;
;=============================================================================
; $Log:$
;=============================================================================
:
:
.lword dummy_int ; uart1 transmit(for user)(vector 19)
.lword dummy_int ; uart1 receive(for user)(vector 20)
.glb _TimerA0Int
.lword _TimerA0Int ; timer A0(for user)(vector 21)
.lword dummy_int ; timer A1(for user)(vector 22)
.lword dummy_int ; timer A2(for user)(vector 23)
:
:
Kommentare zu diesen Handbüchern