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

📄 tio4_mes_main.c

📁 瑞萨CAN通讯单片机程序
💻 C
字号:
/*""FILE COMMENT""*****************************************************
 *	M32R C Programming		Rev. 1.00
 *		 < Sample Program for TIO4 measure clear input (main routine) >
 *
 *	Copyright (c) 2003 Renesas Technology Corporation
 *			   And Renesas Solutions Corporation
 *			   All Rights Reserved
 *********************************************************************/

/************************************************************************/
/*		Include file						*/
/************************************************************************/

#include		"..\inc\sfr32170_pragma.h"

/************************************************************************/
/*		Function prototype declaration				*/
/************************************************************************/

	void		main(void);				/* Main function */
	void		init_func(void);			/* Initial setup function */
	void		port_init(void);			/* Initialize port */
	void		timer_init(void);			/* Timer initialization */
	void		int_init(void);				/* Initialize ICU */
	void		TIN0_2_Int(void);			/* Process TIN0-2 input interrupt */

/************************************************************************/
/*		Definition of external reference			*/
/************************************************************************/

extern	void		DisInt( void );				/* Interrupt disable function */
extern	void		EnInt( void );				/* Interrupt enable function */

extern	void		TIO4_MesClr_init( void );		/* Initialize TIO4 measurement clear input mode */
extern	void		TIN0_Int(void);				/* Process TIN0 (TIO4 measurement input) interrupt */

/************************************************************************/
/*		Global variable						*/
/************************************************************************/

	unsigned long	MesTime;				/* Measurement count value */

/*""FUNC COMMENT""*******************************************************
 * Function name: int_init()
 *-----------------------------------------------------------------------
 * Description	: Initialize ICU
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void int_init(void)
{
	IMJTICR1 = 0x01;					/* TINO-2 ILEVEL = 1 */
}

/*""FUNC COMMENT""*******************************************************
 * Function name: timer_init()
 *-----------------------------------------------------------------------
 * Description	: Timer initialization
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void timer_init(void)
{
	PRS0 = ( 100 - 1);					/* Set prescaler(10us@10MHz) */
}

/*""FUNC COMMENT""*******************************************************
 * Function name: port_init()
 *-----------------------------------------------------------------------
 * Description	: Initialize port
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	: -
 *""FUNC COMMENT END""***************************************************/
void port_init(void)
{
	PIEN = PIEN0;						/* Enable port input */

	P10DATA = 0x00;						/* Output data (must be set prior to mode) */
	P10DIR = 0xff;						/* P100-P107 : Output mode */
	P10MOD = 0x00;						/* P100-P107 : Input/output port */

	P11DATA = 0x00;						/* Output data (must be set prior to mode) */
	P11DIR = 0xff;						/* P110-P117 : Output mode */
	P11MOD = 0x00;						/* P110-P117 : Input/output port */
}

/*""FUNC COMMENT""*******************************************************
 * Function name: init_func()
 *-----------------------------------------------------------------------
 * Description	: Call various initialization functions
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	: -
 *""FUNC COMMENT END""***************************************************/
void init_func(void)
{
	port_init();						/* Initialize those related to port */
	timer_init();						/* Initialize those related to timer */
	int_init();						/* Initialize those related to int */
}

/*""FUNC COMMENT""*******************************************************
 * Function name: main()
 *-----------------------------------------------------------------------
 * Description	: Initialize those related to intWhile using TIO4 in measurement clear input mode,
 *		: this function measures the duration of a rising edge on the input signal entered
 *		: from the TIN0 pin. The 16 low-order bits of the measurement result are output from ports 10 and 11.
 * 		: The measurement resolution is 10 us (when the source clock frequency = 10 MHz).
 * 		:
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void main(void)
{
        volatile unsigned short  *P10P11DATA;

	P10P11DATA = (unsigned short *)&P10DATA;
	MesTime = 0;

	DisInt();						/* Disable interrupt */

	init_func();

	TIO4_MesClr_init();					/* T104 count start */

	EnInt();						/* Enable interrupt */

	while(1) {
		*P10P11DATA = (unsigned short)MesTime;
	}
}

/*""FUNC COMMENT""*******************************************************
 * Function name: TIN0_2_Int()
 *-----------------------------------------------------------------------
 * Description	: Enable interruptProcess TIN0-2 input interrupt
 * 		: If a TIN0 interrupt, clear request status and process the TIN0 interrupt.
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	: -
 *""FUNC COMMENT END""***************************************************/
void TIN0_2_Int(void)
{
	unsigned char	temp;

/*** Interrupt judgment (TIN0) ***/

	if(( TINIR0 & TINIS0) != 0) {
		DisInt();					/* Disable interrupt */
		temp = TINIR0;
		temp |= ( TINIS2 | TINIS1);
		temp &= ~TINIS0;				/* Clear TIN0 interrupt request */
		TINIR0 = temp;
		EnInt();					/* Enable interrupt */

		TIN0_Int();					/* Process TIN0 interrupt */
	}
}

⌨️ 快捷键说明

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