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

📄 tio5_noise_main.c

📁 瑞萨CAN通讯单片机程序
💻 C
字号:
/*""FILE COMMENT""*****************************************************
 *	M32R C Programming		Rev. 1.00
 *		 < Sample Program for TIO5 noise processing input mode (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);				/* ICU initialization */
	void		TIO4_7_Int(void);			/* Process TIO4-7 output interrupt */
	void		TIO5_noiseInt(void);			/* Process TIO5 interrupt */

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

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

extern	void		TIO5_noise_init(void);			/* Initialize TIO5 noise processing input mode */

/*""FUNC COMMENT""*******************************************************
 * Function name: int_init()
 *-----------------------------------------------------------------------
 * Description	: ICU initialization
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void int_init(void)
{
	IMJTOCR4 = 0x01;					/* TIO4-7 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	: Port initialization
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void port_init(void)
{
	PIEN = PIEN0;						/* Enable port input */

	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 port */
}

/*""FUNC COMMENT""*******************************************************
 * Function name: main()
 *-----------------------------------------------------------------------
 * Description	: Initialize those related to portWhile using TIO5 in noise processing input mode, this function
 *		: performs interrupt processing when the high-level duration of TIN3 is 1 ms or more (when the
 *		: source clock frequency = 10 MHz).
 * 		: It increments the LED (port 11) in each interrupt generated.
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void main(void)
{
	DisInt();						/* Disable interrupt */

	init_func();

	TIO5_noise_init();					/* Start TIO5 count */

	EnInt();						/* Enable interrupt */

	while(1);
}

/*""FUNC COMMENT""*******************************************************
 * Function name: TIO4_7_Int()
 *-----------------------------------------------------------------------
 * Description	: Enable interruptProcess TIO4-7 output interrupt
 * 		: - If a TIO5 interrupt, clear request status and process the TIO5 interrupt
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void TIO4_7_Int(void)
{
	unsigned char	temp;

/*** Interrupt judgment(TIO5) ***/

	if(( TIOIR1 & TIOIS5) != 0) {
		DisInt();					/* Disable interrupt */
		temp = TIOIR1;
		temp |= ( TIOIS4 | TIOIS6 | TIOIS7);
		temp &= ~TIOIS5;				/* Clear TIO5 interrupt request */
		TIOIR1 = temp;
		EnInt();					/* Enable interrupt */

		TIO5_noiseInt();				/* Process TIO5 interrupt */
	}
}
/*""FUNC COMMENT""*******************************************************
 * Function name: TIO5_noiseInt()
 *-----------------------------------------------------------------------
 * Description	: Process TIO5 interrupt
 *-----------------------------------------------------------------------
 * Argument	: -
 *-----------------------------------------------------------------------
 * Returns	: -
 *-----------------------------------------------------------------------
 * Notes	:
 *""FUNC COMMENT END""***************************************************/
void	TIO5_noiseInt()
{
	P11DATA++;						/* Increment port in interrupt generated */
}

⌨️ 快捷键说明

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