
M16C/2
Using the M16C/26 Timers in Timer Mod
REU05B0046-0100Z June 2003
Page 7 of 8
*=============================================================================
* $Log:$
*===========================================================================*/
#include "sfr26.h"
#define TIME_CONFIG 0x40 /* 01000000 value to load into timer mode register
||||||||_ TMOD0, TMOD1: TIMER MODE SELECTED
||||||____ MR0: NO PULSE OUTPUT
|||||_____ MR1, MR2: GATE FUNCTION NOT SELECTED
|||_______ MR3: SET TO 0 IN TIMER MODE
||________ TCK0, TCK1: F8 SELECTED */
#define CNTR_IPL 0x03 // TA0 priority interrupt level
#define LED p7_2 // LED4 is connected to p7_2 on the MSV30262 board
int time_cnt;
int count; //Global count value, incremented every second
//prototypes
void init(void);
#pragma INTERRUPT /B TimerA0Int
void TimerA0Int(void);
/*****************************************************************************
Name: TimerA0Int()
Parameters: none
Returns: nothing
Description: Timer A0 Interrupt Service Routine. Interrupts every 1ms,
toggles LED every second, and increments global'count'
**************************************************************************** */
void TimerA0Int(void)
{
if ((time_cnt++) > (1000)) // = 1 second
{ LED ^= 1; // toggle LED
count++; // example 1 second "clock"
time_cnt = 0;
}
}
/*****************************************************************************
Name: main()
Parameters: none
Returns: nothing
Description: initializes variables and LED port. Then does nothing but
wait for TA0 interrupts.
**************************************************************************** */
void main (void)
{
time_cnt = 0;
count = 0;
pd7_2 = 1;
init();
while (1); //LED flashing is interrupt driven
}
Comentarios a estos manuales