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

📄 wave_casc.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
字号:
//*-----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*-----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*-----------------------------------------------------------------------------
//* File Name           : wave_casc.c
//* Object              : AT91 - Timer Counter - Timers Cascade
//*
//* Exported resources  : main
//*
//* 1.0 30/09/98 JCZ    : Creation
//* 2.0 24/07/00  PF    : Clean up
//*-----------------------------------------------------------------------------
/*
Configure the channel 0 of the Timer Counter (TC) of the AT91
to aim Single waveform generation :
- clock = MCKI / 1024
- Register C = 0x4000
  toggle TIOA0 when reached
  generate trigger to restart the timer

Configure the channel 1 of the Timer Counter (TC) of the AT91
to aim single waveform generation by using TIOA0 as clock :
- clock = XC1
- Register C = 0x0001
  toggle TIOA0 and TIOB0 when reached
  generate trigger to restart the timer

Every time the user button is pressed, the clock is inverted :
--------------------------------------------------------------------------------
          _   _   _   _   _   _   _   _   _   _   _   _   _
  TIOA0 _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_|     red LED / output
          _______         _______       _______         ___
  TIOA1 _|       |_______|       |_____|       |_______|     amber LED / output
                                   _
  TIOB1 __________________________| |______________________  input
--------------------------------------------------------------------------------
*/

#include    "periph/stdc/std_c.h"
#include    "targets/eb40/eb40.h"
#include    "parts/r40807/reg_r40807.h"


//*-----------------------------------------------------------------------------
//* Function Name       : timer1_irq_handler
//* Object              : Timer 1 interrupt Handler
//*-----------------------------------------------------------------------------
__irq void timer1_irq_handler ( void )
{
    // Invert TIOA1 every time TIOB1 is pressed
    TC1_CMR = TC_CLKI ;

	// Acknowledge at timer level
    AIC_EOICR = TC1_SR ;
}


//*-----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : AT91 - Timer Counter - Timers Cascade
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : None
//*-----------------------------------------------------------------------------
int main ( void )
//* Begin
{
    long dummy;

    /* Enable and clear PIO pin corresponding to TIOA0, TIOB0 and TIOA1 */
	PIO_PER  = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB1) ;
	PIO_OER  = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB1) ;
	PIO_CODR = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB1) ;

    PIO_PDR  = (1<<PIOTIOA0) | (1<<PIOTIOA1) | (1<<PIOTIOB1) ;		/* Define TIOA0 and TIOB0 as peripheral */

    TCB0_BMR = TC_TIOA0XC1 ;										/* Define XC1 as TIOA0 for channel 0 */


    AIC_SMR5 = ( AIC_SRCTYPE_INT_EDGE_TRIGGERED | (1 << 0) ) ;		/* Set the trigg and priority for TC0 interrupt */
	AIC_SVR5 = ((u_int)timer1_irq_handler ) ;						/* Set the TC0 IRQ handler address */
    AIC_IECR = (1<<TC1_ID) ;										/* Enable the TC0 interrupt */

    /* Initialize the mode of the channel 1 */
    TC1_CMR =
        TC_ASWTRG_SET_OUTPUT   |         		/* ASWTRG  : software trigger set TIOA */
        TC_ACPC_TOGGLE_OUTPUT  |         		/* ACPC    : Register C compare toggle TIOA */
        TC_WAVE				   |         		/* WAVE    : Waveform mode */
        TC_CPCTRG              |         		/* CPCTRG  : Register C compare trigger enable */
        TC_ENETRG 			   |         		/* ENETRG  : External event trigger enable */
        TC_EEVT_TIOB		   |         		/* EEVT    : TIOB as external event */
        TC_EEVTEDG_RISING_EDGE |         		/* EEVTEDG : Trigger on rising edge */
        TC_CLKS_XC1 ;          			 		/* TCCLKS  : XC1 */


    /* Validate interrupts */
	dummy = TC1_SR ;
    TC1_IER = TC_ETRGS ;

    TC1_RC = 0x0001 ;							/* Initialize the RC Register value */

    /* Start the timer 1 */
    TC1_CCR = TC_CLKEN ;
    TC1_CCR = TC_SWTRG ;

    /* Initialize the mode of the timer 0 */
    TC0_CMR =
        TC_ASWTRG_SET_OUTPUT   |    			/* ASWTRG  : software trigger set TIOA */
        TC_ACPC_TOGGLE_OUTPUT  |    			/* ACPC    : Register C compare toggle TIOA */
        TC_WAVE		           |    			/* WAVE    : Waveform mode */
        TC_CPCTRG              |    			/* CPCTRG  : Register C compare trigger enable */
        TC_CLKS_MCK1024 ;   	    			/* TCCLKS  : MCKI / 1024 */

    TC0_RC = 0x4000;				   			/* Initialize the RC value */


    TC0_CCR = TC_CLKEN ;						/* Enable the Clock Timer */
    TC0_CCR = TC_SWTRG ;						/* Start the timer 1 */

   /* for (;;)
    {
    }*/

//* End
    return(0);
}

⌨️ 快捷键说明

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