⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_user.c

📁 nec 78K0 样例对程序初始化电表样
💻 C
字号:
/*
*******************************************************************************
**
**  This device driver was created by Applilet for the 78K0/KB2, 78K0/KC2,
**  78K0/KD2, 78K0/KE2 and 78K0/KF2 8-Bit Single-Chip Microcontrollers.
**
**  Copyright(C) NEC Electronics Corporation 2002 - 2005
**  All rights reserved by NEC Electronics Corporation.
**
**  This program should be used on your own responsibility.
**  NEC Electronics Corporation assumes no responsibility for any losses
**  incurred by customers or third parties arising from the use of this file.
**
**  Filename : timer_user.c
**  Abstract : This file implements a device driver for the timer module
**  APIlib:  NEC78K0KX2.lib V1.01 [09 Aug. 2005]
**
**  Device :	uPD78F0513(44-pin)
**
**  Compiler:  NEC/CC78K0
**
*******************************************************************************
*/

#pragma sfr
#pragma interrupt  INTTM010 MD_INTTM010
/*
*******************************************************************************
**  Include files
*******************************************************************************
*/
#include "macrodriver.h"
#include "timer.h"


/*
*******************************************************************************
**  MacroDefine
*******************************************************************************
*/

/* Timer00, Timer01 pulse width measure */
static ULONG tm00_pul_old_0=0;
static ULONG tm00_pul_old_1=0;
ULONG tm00_pos_width=0;
ULONG tm00_neg_width=0;
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	TM00 INTTM010 interrupt service routine.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
__interrupt void MD_INTTM010( )
{
/* Free-running counter and two capture registers */
	ULONG tm00_pul_cur_0=0;
	ULONG tm00_pul_cur_1=0;
	UCHAR stat = TMC00;
	ClrIORBit(TMC00, 0x1);			/* OVF00 clear */
	tm00_pul_cur_0 = (ULONG)CR000;
	tm00_pul_cur_1 = (ULONG)CR010;

	if(stat & 0x1){			/*overflow generated */
		if(tm00_pul_cur_0 < tm00_pul_cur_1){
			tm00_pos_width = (0x10000 + tm00_pul_cur_0) - tm00_pul_old_1;
			tm00_neg_width = tm00_pul_cur_1 - tm00_pul_cur_0;
		}
		else{
			tm00_pos_width = tm00_pul_cur_0 - tm00_pul_old_1;
			tm00_neg_width = (0x10000 + tm00_pul_cur_1) - tm00_pul_cur_0;
		}
	}
	else{
		tm00_pos_width = tm00_pul_cur_0 - tm00_pul_old_1;
		tm00_neg_width = tm00_pul_cur_1 - tm00_pul_cur_0;
	}

	tm00_pul_old_0 = tm00_pul_cur_0;
	tm00_pul_old_1 = tm00_pul_cur_1;
	/*TODO*/
}

⌨️ 快捷键说明

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