acprd_timer.c

来自「source code for a sample alarm control p」· C语言 代码 · 共 49 行

C
49
字号
//=============================================================================
// File: ACPRD_TIMER.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
//=============================================================================

//-- Includes -----------------------------------------------------------------

#include "datatypes.h"
#include "hcs12dp256.h"
#include "s12_ect.h"
#include "acprd_timer.h"

//-- Static Vars --------------------------------------------------------------

void (*timer_handler)(void);

//-- Code ---------------------------------------------------------------------

void initTimer(void (*ufunc)(void)) {

	// timer enable, freeze while BDM
	TSCR1  = BM_TEN | BM_TSFRZ;
	// MDCU Interrupt enable, modulus mode, counter enable, MDC prescaler=4 
	MCCTL = BM_MCZI | BM_MODMC | BM_MCEN | BM_MCPR0;
	MCCNT = TIMER_MDC_COUNT;
	// if not NULL, this user function will be called cyclically
	timer_handler = ufunc;
	}

//-----------------------------------------------------------------------------

// ISR for Modulus Down Counter Underflow
//
#ifdef METROWERKS_C
interrupt
#endif
#ifdef IMAGECRAFT_C
#pragma interrupt_handler isrMDCU
#endif
void isrMDCU(void) {

	MCFLG = BM_MCZF;					// clear Intr flag
	if(timer_handler)
		(*timer_handler)();				// call user handler
	}

//=============================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?