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

📄 tin_dma.c

📁 瑞萨CAN通讯单片机程序
💻 C
字号:
/*  FILE COMMENT   **************************************************** *	M32R C Programming		Rev. 1.00 *		< Sample Program for TIN-DMAC > * *	Copyright (c) 2003 Renesas Technology Corporation *			   And Renesas Solutions Corporation *			   All Rights Reserved **********************************************************************//************************************************************************//*		Include file						*//************************************************************************/#include		"..\inc\sfr32170_pragma.h"/************************************************************************//*		Definition of external reference			*//************************************************************************/extern	void		DisInt( void );				/* Interrupt disable function */extern	void		EnInt( void );				/* Interrupt enable function *//************************************************************************//*		Function prototype declaration				*//************************************************************************/	void		init_func(void);			/* Initial setup function */	void		port_init(void);			/* Initialize port */	void		dma_init(void);				/* Initialize DMA  *//************************************************************************//*		Define macro						*//************************************************************************//* DMAC setting data */						/* 0123 4567	*/#define	DMA2_INIT	(unsigned char)0x2c	/* 0010 1100B	DMA2 channel control register		*/						/* |||| |||+---	Destination address fixed		*/						/* |||| ||+----	Source address fixed			*/						/* |||| |+-----	Transfer size of 8-bit			*/						/* |||| +------	Transfer enabled			*/						/* ||++--------	10: start upon TIN18 input signal	*/						/* |+----------	No transfer request			*/						/* +-----------	Normal mode				*//* TIN setting data */						/* 0123 4567 89AB CDEF	*/#define	TIN18_MASK	(unsigned short)0x3000	/* 0011 0000 0000 0000B	TIN input processing control register 3	*/#define	TIN18_R_Edge	(unsigned short)0x1000	/* 0001 0000 0000 0000B	*/						/*   ++---------------- TIN 18 rising edge			*//************************************************************************//*		Variable definition					*//************************************************************************/unsigned char DMA_DUMMY;/*""FUNC COMMENT""******************************************************* * Function name : init_func() *----------------------------------------------------------------------- * Description	: - Initialize ICU *----------------------------------------------------------------------- * Argument	: - *----------------------------------------------------------------------- * Returns	: - *----------------------------------------------------------------------- * Notes	: *""FUNC COMMENT END""***************************************************/void init_func(void){	port_init();					/* Initialize those related to port壔 */	dma_init();					/* Initialize DMA  */}/*""FUNC COMMENT""******************************************************* * Function name : port_init() *----------------------------------------------------------------------- * Description	: - Initialize port *----------------------------------------------------------------------- * Argument	: - *----------------------------------------------------------------------- * Returns	: - *----------------------------------------------------------------------- * Notes	: *""FUNC COMMENT END""***************************************************/void port_init(void){	PIEN = PIEN0;						/* Enable port input *//*** LED 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 *//*** Switch input port ***/	P13DIR = 0x00;						/* PP130-P137 : Input mode */	P13MOD |= 0x0020;					/* P132:TIN18 */	TINCR3 = ( TINCR3 & ~TIN18_MASK) | TIN18_R_Edge;	/* Set rise on TIN18 to be the active edge */}/*""FUNC COMMENT""******************************************************* * Function name : dma_init() *----------------------------------------------------------------------- * Description 	: - Initialize DMAC *		:   DMA2: transferred upon TIN18 input signal *----------------------------------------------------------------------- * Argument	: - *----------------------------------------------------------------------- * Returns	: - *----------------------------------------------------------------------- * Notes	: Transfer is dummy *		: Restart is required if the number of transfers is 256 or more *""FUNC COMMENT END""***************************************************/void dma_init(void){/*** DMA2 initial setting ***/	DM04ITMK |= DMITMK2;				/* Inhibit DMA2 interrupt */	DM04ITST = ~DMITST2;				/* Clear DMA2 interrupt request */	DM2SA = (unsigned short)&DMA_DUMMY;		/* Source address -> dummy */	DM2DA = (unsigned short)&DMA_DUMMY;		/* Destination address -> dummy */	DM2TCT = 0xff;					/* Number of DMA2 transfer (256 times) */	DM2CNT = DMA2_INIT;				/* Start and enable transfer upon TIN18 input signal */}/*""FUNC COMMENT""******************************************************* * Function name : main() *----------------------------------------------------------------------- * Description	: - Start DMA2 upon rising edge of TIN18 and count the *		:   number of transfers, then output number of edge  *		:   inputs (number of transfers) to LED (PORT11) *----------------------------------------------------------------------- * Argument	: - *----------------------------------------------------------------------- * Returns	: - *----------------------------------------------------------------------- * Notes	: Transfer counter is counting down from 255 *""FUNC COMMENT END""***************************************************/void main(void){/*** Initialize microcomputer ***/	DisInt();						/* Disable interrupt */	init_func();	EnInt();						/* Enable interrupt */	while(1) {		P11DATA = (255 - DM2TCT);			/* Display the value for DM2TCT on LED */	}}

⌨️ 快捷键说明

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