久久精品99久久_亚洲一区二区综合_狠狠色伊人亚洲综合成人_亚洲综合爱爱久久网

您好,歡迎進入深圳市穎特新科技有限公司官方網站!

您現在的位置:首頁 新聞資訊 >> 新聞頭條 >> M451定時器的寄存器講解
新聞資訊
NEWS INFORMATION

M451定時器的寄存器講解

關鍵字:M451 發布時間:2019-05-22

M451的定時器的寄存器的這一章節,相信很多人都清楚明白了,但還是有必要說一說的

 

 

/**
 * @brief       Timer0 IRQ
 *
 * @param       None
 *
 * @return      None
 *
 * @details     The Timer0 default IRQ, declared in startup_M451Series.s.
 */
void TMR0_IRQHandler(void)
{
    if(TIMER_GetIntFlag(TIMER0) == 1)
    {
        /* Clear Timer0 time-out interrupt flag */
        TIMER_ClearIntFlag(TIMER0);

        g_au32TMRINTCount[0]++;
    }
}

/**
 * @brief       Timer1 IRQ
 *
 * @param       None
 *
 * @return      None
 *
 * @details     The Timer1 default IRQ, declared in startup_M451Series.s.
 */
void TMR1_IRQHandler(void)
{
    if(TIMER_GetIntFlag(TIMER1) == 1)
    {
        /* Clear Timer1 time-out interrupt flag */
        TIMER_ClearIntFlag(TIMER1);

        g_au32TMRINTCount[1]++;
    }
}

/**
 * @brief       Timer2 IRQ
 *
 * @param       None
 *
 * @return      None
 *
 * @details     The Timer2 default IRQ, declared in startup_M451Series.s.
 */
void TMR2_IRQHandler(void)
{
    if(TIMER_GetIntFlag(TIMER2) == 1)
    {
        /* Clear Timer2 time-out interrupt flag */
        TIMER_ClearIntFlag(TIMER2);

        g_au32TMRINTCount[2]++;
    }
}

/**
 * @brief       Timer3 IRQ
 *
 * @param       None
 *
 * @return      None
 *
 * @details     The Timer3 default IRQ, declared in startup_M451Series.s.
 */
void TMR3_IRQHandler(void)
{
    if(TIMER_GetIntFlag(TIMER3) == 1)
    {
        /* Clear Timer3 time-out interrupt flag */
        TIMER_ClearIntFlag(TIMER3);

        g_au32TMRINTCount[3]++;
    }
}

void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Enable HIRC clock */
    CLK->PWRCTL |= CLK_PWRCTL_HIRCEN_Msk;

    /* Waiting for HIRC clock ready */
    while(!(CLK->STATUS & CLK_STATUS_HIRCSTB_Msk));

    /* Switch HCLK clock source to HIRC */
    CLK->CLKSEL0 = CLK_CLKSEL0_HCLKSEL_HIRC;

    /* Set PLL to Power-down mode and PLLSTB bit in CLK_STATUS register will be cleared by hardware.*/
    CLK->PLLCTL |= CLK_PLLCTL_PD_Msk;

    /* Enable HXT */
    CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk;

    /* Enable PLL and Set PLL frequency */
    CLK->PLLCTL = PLLCON_SETTING;

    /* Waiting for clock ready */
    while(!(CLK->STATUS & CLK_STATUS_PLLSTB_Msk));
    while(!(CLK->STATUS & CLK_STATUS_HXTSTB_Msk));

    /* Switch STCLK source to HCLK/2 and HCLK clock source to PLL */
    CLK->CLKSEL0 = CLK_CLKSEL0_STCLKSEL_HCLK_DIV2 | CLK_CLKSEL0_HCLKSEL_PLL;

    /* Enable peripheral clock */
    CLK->APBCLK0 = CLK_APBCLK0_UART0CKEN_Msk |
                   CLK_APBCLK0_TMR0CKEN_Msk | CLK_APBCLK0_TMR1CKEN_Msk |
                   CLK_APBCLK0_TMR2CKEN_Msk | CLK_APBCLK0_TMR3CKEN_Msk;

    /* Peripheral clock source */
    CLK->CLKSEL1 = CLK_CLKSEL1_UARTSEL_PLL |
                   CLK_CLKSEL1_TMR0SEL_HXT | CLK_CLKSEL1_TMR1SEL_PCLK0 | CLK_CLKSEL1_TMR2SEL_HIRC | CLK_CLKSEL1_TMR3SEL_HXT;

    /* Update System Core Clock */
    /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
    SystemCoreClockUpdate();

    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Set PD multi-function pins for UART0 RXD, TXD */
    SYS->GPD_MFPL = SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD;
}

void UART0_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init UART                                                                                               */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Reset UART module */
    SYS->IPRST1 |=  SYS_IPRST1_UART0RST_Msk;
    SYS->IPRST1 &= ~SYS_IPRST1_UART0RST_Msk;

    /* Configure UART0 and set UART0 Baudrate */
    UART0->BAUD = UART_BAUD_MODE2 | UART_BAUD_MODE2_DIVIDER(PllClock, 115200);
    UART0->LINE = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1;
}

/*---------------------------------------------------------------------------------------------------------*/
/*  MAIN function                                                                                          */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    volatile uint32_t u32InitCount;

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+--------------------------------------------+\n");
    printf("|    Timer Periodic Interrupt Sample Code    |\n");
    printf("+--------------------------------------------+\n\n");

    printf("# Timer0 Settings:\n");
    printf("    - Clock source is HXT       \n");
    printf("    - Time-out frequency is 1 Hz\n");
    printf("    - Periodic mode             \n");
    printf("    - Interrupt enable          \n");
    printf("# Timer1 Settings:\n");
    printf("    - Clock source is HCLK      \n");
    printf("    - Time-out frequency is 2 Hz\n");
    printf("    - Periodic mode             \n");
    printf("    - Interrupt enable          \n");
    printf("# Timer2 Settings:\n");
    printf("    - Clock source is HIRC      \n");
    printf("    - Time-out frequency is 4 Hz\n");
    printf("    - Periodic mode             \n");
    printf("    - Interrupt enable          \n");
    printf("# Timer3 Settings:\n");
    printf("    - Clock source is HXT       \n");
    printf("    - Time-out frequency is 8 Hz\n");
    printf("    - Periodic mode             \n");
    printf("    - Interrupt enable          \n");
    printf("# Check Timer0 ~ Timer3 interrupt counts are reasonable or not.\n\n");

    /* Open Timer0 in periodic mode, enable interrupt and 1 interrupt tick per second */
    TIMER0->CMP = __HXT;
    TIMER0->CTL = TIMER_CTL_INTEN_Msk | TIMER_PERIODIC_MODE;
    TIMER_SET_PRESCALE_VALUE(TIMER0, 0);

    /* Open Timer1 in periodic mode, enable interrupt and 2 interrupt ticks per second */
    TIMER1->CMP = ((SystemCoreClock / 4) / 2);
    TIMER1->CTL = TIMER_CTL_INTEN_Msk | TIMER_PERIODIC_MODE;
    TIMER_SET_PRESCALE_VALUE(TIMER1, 3);

    /* Open Timer2 in periodic mode, enable interrupt and 4 interrupt ticks per second */
    TIMER2->CMP = ((__HIRC / 1) / 4);
    TIMER2->CTL = TIMER_CTL_INTEN_Msk | TIMER_PERIODIC_MODE;
    TIMER_SET_PRESCALE_VALUE(TIMER2, 0);

    /* Open Timer3 in periodic mode, enable interrupt and 8 interrupt ticks per second */
    TIMER3->CMP = ((__HXT / 1) / 8);
    TIMER3->CTL = TIMER_CTL_INTEN_Msk | TIMER_PERIODIC_MODE;
    TIMER_SET_PRESCALE_VALUE(TIMER3, 0);

    /* Enable Timer0 ~ Timer3 NVIC */
    NVIC_EnableIRQ(TMR0_IRQn);
    NVIC_EnableIRQ(TMR1_IRQn);
    NVIC_EnableIRQ(TMR2_IRQn);
    NVIC_EnableIRQ(TMR3_IRQn);

    /* Clear Timer0 ~ Timer3 interrupt counts to 0 */
    g_au32TMRINTCount[0] = g_au32TMRINTCount[1] = g_au32TMRINTCount[2] = g_au32TMRINTCount[3] = 0;
    u32InitCount = g_au32TMRINTCount[0];

    /* Start Timer0 ~ Timer3 counting */
    TIMER_Start(TIMER0);
    TIMER_Start(TIMER1);
    TIMER_Start(TIMER2);
    TIMER_Start(TIMER3);

    /* Check Timer0 ~ Timer3 interrupt counts */
    printf("# Timer interrupt counts :\n");
    while(u32InitCount < 20)
    {
        if(g_au32TMRINTCount[0] != u32InitCount)
        {
            printf("    TMR0:%3d    TMR1:%3d    TMR2:%3d    TMR3:%3d\n",
                   g_au32TMRINTCount[0], g_au32TMRINTCount[1], g_au32TMRINTCount[2], g_au32TMRINTCount[3]);
            u32InitCount = g_au32TMRINTCount[0];

            if((g_au32TMRINTCount[1] > (g_au32TMRINTCount[0] * 2 + 1)) || (g_au32TMRINTCount[1] < (g_au32TMRINTCount[0] * 2 - 1)) ||
                    (g_au32TMRINTCount[2] > (g_au32TMRINTCount[0] * 4 + 1)) || (g_au32TMRINTCount[2] < (g_au32TMRINTCount[0] * 4 - 1)) ||
                    (g_au32TMRINTCount[3] > (g_au32TMRINTCount[0] * 8 + 1)) || (g_au32TMRINTCount[3] < (g_au32TMRINTCount[0] * 8 - 1)))
            {
                printf("*** FAIL ***\n");
                while(1);
            }
        }
    }

    printf("*** PASS ***\n");

    while(1);
}

/*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/

 

typedef struct
{




/**
 * @var TIMER_T::CTL
 * Offset: 0x00  Timer Control and Status Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[7:0]   |PSC       |Prescale Counter
 * |        |          |Timer input clock or event source is divided by (PSC+1) before it is fed to the timer up counter.
 * |        |          |If this field is 0 (PSC = 0), then there is no scaling.
 * |[17]    |WKTKEN    |Wake-Up Touch-Key Scan Enable Bit
 * |        |          |If this bit is set to 1, timer time-out interrupt in Power-down mode can be triggered Touch-Key start scan.
 * |        |          |0 = Timer time-out interrupt signal trigger Touch-Key start scan Disabled.
 * |        |          |1 = Timer time-out interrupt signal trigger Touch-Key start scan Enabled.
 * |        |          |Note: This bit is only available in TIMER0_CTL.
 * |[18]    |TRGSSEL   |Trigger Source Select Bit
 * |        |          |This bit is used to select trigger source is form Timer time-out interrupt signal or capture interrupt signal.
 * |        |          |0 = Timer time-out interrupt signal is used to trigger PWM, EADC and DAC.
 * |        |          |1 = Capture interrupt signal is used to trigger PWM, EADC and DAC.
 * |[19]    |TRGPWM    |Trigger PWM Enable Bit
 * |        |          |If this bit is set to 1, timer time-out interrupt or capture interrupt can be triggered PWM.
 * |        |          |0 = Timer interrupt trigger PWM Disabled.
 * |        |          |1 = Timer interrupt trigger PWM Enabled.
 * |        |          |Note: If TRGSSEL (TIMERx_CTL[18]) = 0, time-out interrupt signal will trigger PWM.
 * |        |          |If TRGSSEL (TIMERx_CTL[18]) = 1, capture interrupt signal will trigger PWM.
 * |[20]    |TRGDAC    |Trigger DAC Enable Bit
 * |        |          |If this bit is set to 1, timer time-out interrupt or capture interrupt can be triggered DAC.
 * |        |          |0 = Timer interrupt trigger DAC Disabled.
 * |        |          |1 = Timer interrupt trigger DAC Enabled.
 * |        |          |Note: If TRGSSEL (TIMERx_CTL[18]) = 0, time-out interrupt signal will trigger DAC.
 * |        |          |If TRGSSEL (TIMERx_CTL[18]) = 1, capture interrupt signal will trigger DAC.
 * |[21]    |TRGEADC   |Trigger EADC Enable Bit
 * |        |          |If this bit is set to 1, timer time-out interrupt or capture interrupt can be triggered EADC.
 * |        |          |0 = Timer interrupt trigger EADC Disabled.
 * |        |          |1 = Timer interrupt trigger EADC Enabled.
 * |        |          |Note: If TRGSSEL (TIMERx_CTL[18]) = 0, time-out interrupt signal will trigger EADC.
 * |        |          |If TRGSSEL (TIMERx_CTL[18]) = 1, capture interrupt signal will trigger EADC.
 * |[22]    |TGLPINSEL |Toggle-Output Pin Select
 * |        |          |0 = Toggle mode output to Tx_OUT (Timer Event Counter Pin).
 * |        |          |1 = Toggle mode output to Tx_EXT(Timer External Capture Pin).
 * |[23]    |WKEN      |Wake-Up Function Enable Bit
 * |        |          |If this bit is set to 1, while timer interrupt flag TIF (TIMERx_INTSTS[0]) is 1 and INTEN (TIMERx_CTL[29]) is enabled, the timer interrupt signal will generate a wake-up trigger event to CPU.
 * |        |          |0 = Wake-up function Disabled if timer interrupt signal generated.
 * |        |          |1 = Wake-up function Enabled if timer interrupt signal generated.
 * |[24]    |EXTCNTEN  |Event Counter Mode Enable Bit
 * |        |          |This bit is for external counting pin function enabled.
 * |        |          |0 = Event counter mode Disabled.
 * |        |          |1 = Event counter mode Enabled.
 * |        |          |Note: When timer is used as an event counter, this bit should be set to 1 and select HCLK as timer clock source.
 * |[25]    |ACTSTS    |Timer Active Status Bit (Read Only)
 * |        |          |This bit indicates the 24-bit up counter status.
 * |        |          |0 = 24-bit up counter is not active.
 * |        |          |1 = 24-bit up counter is active.
 * |[26]    |RSTCNT    |Timer Counter Reset Bit
 * |        |          |Setting this bit will reset the 24-bit up counter value CNT (TIMERx_CNT[23:0]) and also force CNTEN (TIMERx_CTL[30]) to 0 if ACTSTS (TIMERx_CTL[25]) is 1.
 * |        |          |0 = No effect.
 * |        |          |1 = Reset internal 8-bit prescale counter, 24-bit up counter value and CNTEN bit.
 * |[28:27] |OPMODE    |Timer Counting Mode Select
 * |        |          |00 = The Timer controller is operated in One-shot mode.
 * |        |          |01 = The Timer controller is operated in Periodic mode.
 * |        |          |10 = The Timer controller is operated in Toggle-output mode.
 * |        |          |11 = The Timer controller is operated in Continuous Counting mode.
 * |[29]    |INTEN     |Timer Interrupt Enable Bit
 * |        |          |0 = Timer Interrupt Disabled.
 * |        |          |1 = Timer Interrupt Enabled.
 * |        |          |Note: If this bit is enabled, when the timer interrupt flag TIF is set to 1, the timer interrupt signal is generated and inform to CPU.
 * |[30]    |CNTEN     |Timer Counting Enable Bit
 * |        |          |0 = Stops/Suspends counting.
 * |        |          |1 = Starts counting.
 * |        |          |Note1: In stop status, and then set CNTEN to 1 will enable the 24-bit up counter to keep counting from the last stop counting value.
 * |        |          |Note2: This bit is auto-cleared by hardware in one-shot mode (TIMER_CTL[28:27] = 00) when the timer interrupt flag TIF (TIMERx_INTSTS[0]) is generated.
 * |[31]    |ICEDEBUG  |ICE Debug Mode Acknowledge Disable
 * |        |          |0 = ICE debug mode acknowledgement effects TIMER counting.
 * |        |          |TIMER counter will be held while CPU is held by ICE.
 * |        |          |1 = ICE debug mode acknowledgement Disabled.
 * |        |          |TIMER counter will keep going no matter CPU is held by ICE or not.
 * @var TIMER_T::CMP
 * Offset: 0x04  Timer Compare Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[23:0]  |CMPDAT    |Timer Compared Value
 * |        |          |CMPDAT is a 24-bit compared value register.
 * |        |          |When the internal 24-bit up counter value is equal to CMPDAT value, the TIF (TIMERx_INTSTS[0] Timer Interrupt Flag) will set to 1.
 * |        |          |Time-out period = (Period of timer clock input) * (8-bit PSC + 1) * (24-bit CMPDAT).
 * |        |          |Note1: Never write 0x0 or 0x1 in CMPDAT field, or the core will run into unknown state.
 * |        |          |Note2: When timer is operating at continuous counting mode, the 24-bit up counter will keep counting continuously even if user writes a new value into CMPDAT field.
 * |        |          |But if timer is operating at other modes, the 24-bit up counter will restart counting from 0 and using newest CMPDAT value to be the timer compared value while user writes a new value into CMPDAT field.
 * @var TIMER_T::INTSTS
 * Offset: 0x08  Timer Interrupt Status Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[0]     |TIF       |Timer Interrupt Flag
 * |        |          |This bit indicates the interrupt flag status of Timer while 24-bit timer up counter CNT (TIMERx_CNT[23:0]) value reaches to CMPDAT (TIMERx_CMP[23:0]) value.
 * |        |          |0 = No effect.
 * |        |          |1 = CNT value matches the CMPDAT value.
 * |        |          |Note: This bit is cleared by writing 1 to it.
 * |[1]     |TWKF      |Timer Wake-Up Flag
 * |        |          |This bit indicates the interrupt wake-up flag status of timer.
 * |        |          |0 = Timer does not cause CPU wake-up.
 * |        |          |1 = CPU wake-up from Idle or Power-down mode if timer time-out interrupt signal generated.
 * |        |          |Note: This bit is cleared by writing 1 to it.
 * @var TIMER_T::CNT
 * Offset: 0x0C  Timer Data Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[23:0]  |CNT       |Timer Data Register
 * |        |          |This field can be reflected the internal 24-bit timer counter value or external event input counter value from Tx_CNT (x=0~3) pin.
 * |        |          |If EXTCNTEN (TIMERx_CTL[24] ) is 0, user can read CNT value for getting current 24- bit counter value .
 * |        |          |If EXTCNTEN (TIMERx_CTL[24] ) is 1, user can read CNT value for getting current 24- bit event input counter value.
 * @var TIMER_T::CAP
 * Offset: 0x10  Timer Capture Data Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[23:0]  |CAPDAT    |Timer Capture Data Register
 * |        |          |When CAPEN (TIMERx_EXTCTL[3]) bit is set, CAPFUNCS (TIMERx_EXTCTL[4]) bit is 0, and a transition on Tx_EXT pin matched the CAPEDGE (TIMERx_EXTCTL[2:1]) setting, CAPIF (TIMERx_EINTSTS[0]) will set to 1 and the current timer counter value CNT (TIMERx_CNT[23:0]) will be auto-loaded into this CAPDAT field.
 * @var TIMER_T::EXTCTL
 * Offset: 0x14  Timer External Control Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[0]     |CNTPHASE  |Timer External Count Phase
 * |        |          |This bit indicates the detection phase of external counting pin Tx_CNT (x= 0~3).
 * |        |          |0 = A Falling edge of external counting pin will be counted.
 * |        |          |1 = A Rising edge of external counting pin will be counted.
 * |[2:1]   |CAPEDGE   |Timer External Capture Pin Edge Detect
 * |        |          |00 = A Falling edge on Tx_EXT (x= 0~3) pin will be detected.
 * |        |          |01 = A Rising edge on Tx_EXT (x= 0~3) pin will be detected.
 * |        |          |10 = Either Rising or Falling edge on Tx_EXT (x= 0~3) pin will be detected.
 * |        |          |11 = Reserved.
 * |[3]     |CAPEN     |Timer External Capture Pin Enable
 * |        |          |This bit enables the Tx_EXT pin.
 * |        |          |0 =Tx_EXT (x= 0~3) pin Disabled.
 * |        |          |1 =Tx_EXT (x= 0~3) pin Enabled.
 * |[4]     |CAPFUNCS  |Capture Function Selection
 * |        |          |0 = External Capture Mode Enabled.
 * |        |          |1 = External Reset Mode Enabled.
 * |        |          |Note1: When CAPFUNCS is 0, transition on Tx_EXT (x= 0~3) pin is using to save the 24-bit timer counter value.
 * |        |          |Note2: When CAPFUNCS is 1, transition on Tx_EXT (x= 0~3) pin is using to reset the 24-bit timer counter value.
 * |[5]     |CAPIEN    |Timer External Capture Interrupt Enable
 * |        |          |0 = Tx_EXT (x= 0~3) pin detection Interrupt Disabled.
 * |        |          |1 = Tx_EXT (x= 0~3) pin detection Interrupt Enabled.
 * |        |          |Note: CAPIEN is used to enable timer external interrupt.
 * |        |          |If CAPIEN enabled, timer will rise an interrupt when CAPIF (TIMERx_EINTSTS[0]) is 1.
 * |        |          |For example, while CAPIEN = 1, CAPEN = 1, and CAPEDGE = 00, a 1 to 0 transition on the Tx_EXT pin will cause the CAPIF to be set then the interrupt signal is generated and sent to NVIC to inform CPU.
 * |[6]     |CAPDBEN   |Timer External Capture Pin De-Bounce Enable
 * |        |          |0 = Tx_EXT (x= 0~3) pin de-bounce Disabled.
 * |        |          |1 = Tx_EXT (x= 0~3) pin de-bounce Enabled.
 * |        |          |Note: If this bit is enabled, the edge detection of Tx_EXT pin is detected with de-bounce circuit.
 * |[7]     |CNTDBEN   |Timer Counter Pin De-Bounce Enable
 * |        |          |0 = Tx_CNT (x= 0~3) pin de-bounce Disabled.
 * |        |          |1 = Tx_CNT (x= 0~3) pin de-bounce Enabled.
 * |        |          |Note: If this bit is enabled, the edge detection of Tx_CNT pin is detected with de-bounce circuit.
 * @var TIMER_T::EINTSTS
 * Offset: 0x18  Timer External Interrupt Status Register
 * ---------------------------------------------------------------------------------------------------
 * |Bits    |Field     |Descriptions
 * | :----: | :----:   | :---- |
 * |[0]     |CAPIF     |Timer External Capture Interrupt Flag
 * |        |          |This bit indicates the timer external capture interrupt flag status.
 * |        |          |0 = Tx_EXT (x= 0~3) pin interrupt did not occur.
 * |        |          |1 = Tx_EXT (x= 0~3) pin interrupt occurred.
 * |        |          |Note1: This bit is cleared by writing 1 to it.
 * |        |          |Note2: When CAPEN (TIMERx_EXTCTL[3]) bit is set, CAPFUNCS (TIMERx_EXTCTL[4]) bit is 0, and a transition on Tx_EXT (x= 0~3) pin matched the CAPEDGE (TIMERx_EXTCTL[2:1]) setting, this bit will set to 1 by hardware.
 * |        |          |Note3: There is a new incoming capture event detected before CPU clearing the CAPIF status.
 * |        |          |If the above condition occurred, the Timer will keep register TIMERx_CAP unchanged and drop the new capture value.
 */

    __IO uint32_t CTL;           /* Offset: 0x00  Timer Control and Status Register                                  */
    __IO uint32_t CMP;           /* Offset: 0x04  Timer Compare Register                                             */
    __IO uint32_t INTSTS;        /* Offset: 0x08  Timer Interrupt Status Register                                    */
    __I  uint32_t CNT;           /* Offset: 0x0C  Timer Data Register                                                */
    __I  uint32_t CAP;           /* Offset: 0x10  Timer Capture Data Register                                        */
    __IO uint32_t EXTCTL;        /* Offset: 0x14  Timer External Control Register                                    */
    __IO uint32_t EINTSTS;       /* Offset: 0x18  Timer External Interrupt Status Register                           */

} TIMER_T;



/**
    @addtogroup TMR_CONST TMR Bit Field Definition
    Constant Definitions for TMR Controller
@{ */

#define TIMER_CTL_PSC_Pos                  (0)                                             /*!< TIMER_T::CTL: PSC Position                  */
#define TIMER_CTL_PSC_Msk                  (0xfful << TIMER_CTL_PSC_Pos)                   /*!< TIMER_T::CTL: PSC Mask                      */

#define TIMER_CTL_WKTKEN_Pos               (17)                                            /*!< TIMER_T::CTL: WKTKEN Position               */
#define TIMER_CTL_WKTKEN_Msk               (0x1ul << TIMER_CTL_WKTKEN_Pos)                 /*!< TIMER_T::CTL: WKTKEN Mask                   */

#define TIMER_CTL_TRGSSEL_Pos              (18)                                            /*!< TIMER_T::CTL: TRGSSEL Position              */
#define TIMER_CTL_TRGSSEL_Msk              (0x1ul << TIMER_CTL_TRGSSEL_Pos)                /*!< TIMER_T::CTL: TRGSSEL Mask                  */

#define TIMER_CTL_TRGPWM_Pos               (19)                                            /*!< TIMER_T::CTL: TRGPWM Position               */
#define TIMER_CTL_TRGPWM_Msk               (0x1ul << TIMER_CTL_TRGPWM_Pos)                 /*!< TIMER_T::CTL: TRGPWM Mask                   */

#define TIMER_CTL_TRGDAC_Pos               (20)                                            /*!< TIMER_T::CTL: TRGDAC Position               */
#define TIMER_CTL_TRGDAC_Msk               (0x1ul << TIMER_CTL_TRGDAC_Pos)                 /*!< TIMER_T::CTL: TRGDAC Mask                   */

#define TIMER_CTL_TRGEADC_Pos              (21)                                            /*!< TIMER_T::CTL: TRGEADC Position              */
#define TIMER_CTL_TRGEADC_Msk              (0x1ul << TIMER_CTL_TRGEADC_Pos)                /*!< TIMER_T::CTL: TRGEADC Mask                  */

#define TIMER_CTL_TGLPINSEL_Pos            (22)                                            /*!< TIMER_T::CTL: TGLPINSEL Position            */
#define TIMER_CTL_TGLPINSEL_Msk            (0x1ul << TIMER_CTL_TGLPINSEL_Pos)              /*!< TIMER_T::CTL: TGLPINSEL Mask                */

#define TIMER_CTL_WKEN_Pos                 (23)                                            /*!< TIMER_T::CTL: WKEN Position                 */
#define TIMER_CTL_WKEN_Msk                 (0x1ul << TIMER_CTL_WKEN_Pos)                   /*!< TIMER_T::CTL: WKEN Mask                     */

#define TIMER_CTL_EXTCNTEN_Pos             (24)                                            /*!< TIMER_T::CTL: EXTCNTEN Position             */
#define TIMER_CTL_EXTCNTEN_Msk             (0x1ul << TIMER_CTL_EXTCNTEN_Pos)               /*!< TIMER_T::CTL: EXTCNTEN Mask                 */

#define TIMER_CTL_ACTSTS_Pos               (25)                                            /*!< TIMER_T::CTL: ACTSTS Position               */
#define TIMER_CTL_ACTSTS_Msk               (0x1ul << TIMER_CTL_ACTSTS_Pos)                 /*!< TIMER_T::CTL: ACTSTS Mask                   */

#define TIMER_CTL_RSTCNT_Pos               (26)                                            /*!< TIMER_T::CTL: RSTCNT Position               */
#define TIMER_CTL_RSTCNT_Msk               (0x1ul << TIMER_CTL_RSTCNT_Pos)                 /*!< TIMER_T::CTL: RSTCNT Mask                   */

#define TIMER_CTL_OPMODE_Pos               (27)                                            /*!< TIMER_T::CTL: OPMODE Position               */
#define TIMER_CTL_OPMODE_Msk               (0x3ul << TIMER_CTL_OPMODE_Pos)                 /*!< TIMER_T::CTL: OPMODE Mask                   */

#define TIMER_CTL_INTEN_Pos                (29)                                            /*!< TIMER_T::CTL: INTEN Position                */
#define TIMER_CTL_INTEN_Msk                (0x1ul << TIMER_CTL_INTEN_Pos)                  /*!< TIMER_T::CTL: INTEN Mask                    */

#define TIMER_CTL_CNTEN_Pos                (30)                                            /*!< TIMER_T::CTL: CNTEN Position                */
#define TIMER_CTL_CNTEN_Msk                (0x1ul << TIMER_CTL_CNTEN_Pos)                  /*!< TIMER_T::CTL: CNTEN Mask                    */

#define TIMER_CTL_ICEDEBUG_Pos             (31)                                            /*!< TIMER_T::CTL: ICEDEBUG Position             */
#define TIMER_CTL_ICEDEBUG_Msk             (0x1ul << TIMER_CTL_ICEDEBUG_Pos)               /*!< TIMER_T::CTL: ICEDEBUG Mask                 */

#define TIMER_CMP_CMPDAT_Pos               (0)                                             /*!< TIMER_T::CMP: CMPDAT Position               */
#define TIMER_CMP_CMPDAT_Msk               (0xfffffful << TIMER_CMP_CMPDAT_Pos)            /*!< TIMER_T::CMP: CMPDAT Mask                   */

#define TIMER_INTSTS_TIF_Pos               (0)                                             /*!< TIMER_T::INTSTS: TIF Position               */
#define TIMER_INTSTS_TIF_Msk               (0x1ul << TIMER_INTSTS_TIF_Pos)                 /*!< TIMER_T::INTSTS: TIF Mask                   */

#define TIMER_INTSTS_TWKF_Pos              (1)                                             /*!< TIMER_T::INTSTS: TWKF Position              */
#define TIMER_INTSTS_TWKF_Msk              (0x1ul << TIMER_INTSTS_TWKF_Pos)                /*!< TIMER_T::INTSTS: TWKF Mask                  */

#define TIMER_CNT_CNT_Pos                  (0)                                             /*!< TIMER_T::CNT: CNT Position                  */
#define TIMER_CNT_CNT_Msk                  (0xfffffful << TIMER_CNT_CNT_Pos)               /*!< TIMER_T::CNT: CNT Mask                      */

#define TIMER_CAP_CAPDAT_Pos               (0)                                             /*!< TIMER_T::CAP: CAPDAT Position               */
#define TIMER_CAP_CAPDAT_Msk               (0xfffffful << TIMER_CAP_CAPDAT_Pos)            /*!< TIMER_T::CAP: CAPDAT Mask                   */

#define TIMER_EXTCTL_CNTPHASE_Pos          (0)                                             /*!< TIMER_T::EXTCTL: CNTPHASE Position          */
#define TIMER_EXTCTL_CNTPHASE_Msk          (0x1ul << TIMER_EXTCTL_CNTPHASE_Pos)            /*!< TIMER_T::EXTCTL: CNTPHASE Mask              */

#define TIMER_EXTCTL_CAPEDGE_Pos           (1)                                             /*!< TIMER_T::EXTCTL: CAPEDGE Position           */
#define TIMER_EXTCTL_CAPEDGE_Msk           (0x3ul << TIMER_EXTCTL_CAPEDGE_Pos)             /*!< TIMER_T::EXTCTL: CAPEDGE Mask               */

#define TIMER_EXTCTL_CAPEN_Pos             (3)                                             /*!< TIMER_T::EXTCTL: CAPEN Position             */
#define TIMER_EXTCTL_CAPEN_Msk             (0x1ul << TIMER_EXTCTL_CAPEN_Pos)               /*!< TIMER_T::EXTCTL: CAPEN Mask                 */

#define TIMER_EXTCTL_CAPFUNCS_Pos          (4)                                             /*!< TIMER_T::EXTCTL: CAPFUNCS Position          */
#define TIMER_EXTCTL_CAPFUNCS_Msk          (0x1ul << TIMER_EXTCTL_CAPFUNCS_Pos)            /*!< TIMER_T::EXTCTL: CAPFUNCS Mask              */

#define TIMER_EXTCTL_CAPIEN_Pos            (5)                                             /*!< TIMER_T::EXTCTL: CAPIEN Position            */
#define TIMER_EXTCTL_CAPIEN_Msk            (0x1ul << TIMER_EXTCTL_CAPIEN_Pos)              /*!< TIMER_T::EXTCTL: CAPIEN Mask                */

#define TIMER_EXTCTL_CAPDBEN_Pos           (6)                                             /*!< TIMER_T::EXTCTL: CAPDBEN Position           */
#define TIMER_EXTCTL_CAPDBEN_Msk           (0x1ul << TIMER_EXTCTL_CAPDBEN_Pos)             /*!< TIMER_T::EXTCTL: CAPDBEN Mask               */

#define TIMER_EXTCTL_CNTDBEN_Pos           (7)                                             /*!< TIMER_T::EXTCTL: CNTDBEN Position           */
#define TIMER_EXTCTL_CNTDBEN_Msk           (0x1ul << TIMER_EXTCTL_CNTDBEN_Pos)             /*!< TIMER_T::EXTCTL: CNTDBEN Mask               */

#define TIMER_EINTSTS_CAPIF_Pos            (0)                                             /*!< TIMER_T::EINTSTS: CAPIF Position            */
#define TIMER_EINTSTS_CAPIF_Msk            (0x1ul << TIMER_EINTSTS_CAPIF_Pos)              /*!< TIMER_T::EINTSTS: CAPIF Mask                */

/**@}*/ /* TIMER_CONST */
/**@}*/ /* end of TIMER register group */
#define TIMER0               ((TIMER_T *) TMR01_BASE)
#define TIMER1               ((TIMER_T *) (TMR01_BASE + 0x20))
#define TIMER2               ((TIMER_T *) TMR23_BASE)
#define TIMER3               ((TIMER_T *) (TMR23_BASE+ 0x20))
/** @addtogroup TIMER_EXPORTED_CONSTANTS TIMER Exported Constants
  @{
*/
/*---------------------------------------------------------------------------------------------------------*/
/*  TIMER Operation Mode, External Counter and Capture Mode Constant Definitions                           */
/*---------------------------------------------------------------------------------------------------------*/
#define TIMER_ONESHOT_MODE                      (0UL << TIMER_CTL_OPMODE_Pos)      /*!< Timer working in one-shot mode */
#define TIMER_PERIODIC_MODE                     (1UL << TIMER_CTL_OPMODE_Pos)      /*!< Timer working in periodic mode */
#define TIMER_TOGGLE_MODE                       (2UL << TIMER_CTL_OPMODE_Pos)      /*!< Timer working in toggle-output mode */
#define TIMER_CONTINUOUS_MODE                   (3UL << TIMER_CTL_OPMODE_Pos)      /*!< Timer working in continuous counting mode */
#define TIMER_TOUT_PIN_FROM_TX                  (0UL << TIMER_CTL_TGLPINSEL_Pos)   /*!< Timer toggle-output pin is from Tx pin */
#define TIMER_TOUT_PIN_FROM_TX_EXT              (1UL << TIMER_CTL_TGLPINSEL_Pos)   /*!< Timer toggle-output pin is from Tx_EXT pin */
#define TIMER_CAPTURE_FREE_COUNTING_MODE        (0UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to get timer counter value */
#define TIMER_CAPTURE_COUNTER_RESET_MODE        (1UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to reset timer counter */
#define TIMER_CAPTURE_FALLING_EDGE              (0UL << TIMER_EXTCTL_CAPEDGE_Pos)  /*!< Falling edge detection to trigger timer capture */
#define TIMER_CAPTURE_RISING_EDGE               (1UL << TIMER_EXTCTL_CAPEDGE_Pos)  /*!< Rising edge detection to trigger timer capture */
#define TIMER_CAPTURE_FALLING_AND_RISING_EDGE   (2UL << TIMER_EXTCTL_CAPEDGE_Pos)  /*!< Both falling and rising edge detection to trigger timer capture */
#define TIMER_COUNTER_FALLING_EDGE              (0UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on falling edge detection */
#define TIMER_COUNTER_RISING_EDGE               (1UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on rising edge detection */

/*@}*/ /* end of group TIMER_EXPORTED_CONSTANTS */

 

    
TIMER1->CMP = ((SystemCoreClock / 4) / 2);
    TIMER1->CTL = TIMER_CTL_INTEN_Msk | TIMER_PERIODIC_MODE;
    TIMER_SET_PRESCALE_VALUE(TIMER1, 3);

 

One–shot模式 
如果定時器工作在單周期 (one-shot) 模式(TIMERx_CTL[28:27]為00,且CNTEN (TIMERx_CTL[30])置1),則定時器的計數器開始計數。一旦CNT (TIMERx_CNT[23:0])計數器的值達到CMPDAT (TIMERx_CMP[23:0])的值時,TIF (TIMERx_INTSTS[0])標志將變為1,CNT的值和 CNTEN位將由定時器控制器自動清零,然后定時器計數操作停止。與此同時,如果INTEN (TIMERx_CTL[29])位使能,則定時器中斷信號產生并送到 NVIC通知CPU。(參見數據手冊上的數據)

#define TIMER_CTL_OPMODE_Pos               (27)                                            /*!< TIMER_T::CTL: OPMODE Position               */
#define TIMER_CTL_OPMODE_Msk               (0x3ul << TIMER_CTL_OPMODE_Pos)                 /*!< TIMER_T::CTL: OPMODE Mask  

如果定時器工作在周期 (periodic) 模式(TIMERx_CTL[28:27]為01)且CNTEN (TIMERx_CTL[30])置1,則定時器的計數器開始向上計數。一旦CNT (TIMERx_CNT[23:0])計數器的值達到CMPDAT (TIMERx_CMP[23:0])的值時,TIF (TIMERx_INTSTS[0])標志將變為1,CNT的值將由定時器控制器自動清零,然后定時器重新計數。與此同時,如果INTEN (TIMERx_CTL[29])使能,則定時器中斷信號產生并送到 NVIC 通知 CPU 。在該模式,定時器控制器周期性地操作計數和 與CMPDAT的值比較,直到CNTEN位由軟件清0。

 

 

聯系方式0755-82591179

郵箱:ivy@yingtexin.net

地址:深圳市南山區桃源街道平山社區平山一路2號南山云谷創業園二期11棟410-411

久久精品99久久_亚洲一区二区综合_狠狠色伊人亚洲综合成人_亚洲综合爱爱久久网
亚洲精品一二三四五区| 成人一区二区av| 777久久久精品一区二区三区| 男女裸体影院高潮| 男同互操gay射视频在线看| 亚洲第一色av| 国产成人免费高清视频| 粉嫩av一区二区三区天美传媒 | 黄色激情在线视频| 成人免费看片视频在线观看| 婷婷视频在线播放| 搡的我好爽在线观看免费视频| 色婷婷777777仙踪林| 五月天男人天堂| 欧美日韩黄色一级片| 男人天堂手机在线视频| heyzo国产| 国产精品一区二区小说| 欧美成年人视频在线观看| 亚洲欧美日韩一二三区| 国产一二三区在线播放| 成人中文字幕在线播放| 日本在线观看免费视频| 免费成人深夜夜行网站视频| 欧美精品久久久久久久久久久| 免费 成 人 黄 色| 97超碰成人在线| 国产盗摄视频在线观看| 国产精品秘入口18禁麻豆免会员| 久久精品午夜福利| 人人妻人人澡人人爽精品欧美一区| 亚洲乱码日产精品bd在线观看| 久久婷婷国产精品| 精品国产无码在线| 成人羞羞国产免费网站| 国产免费一区二区三区四在线播放| 无码熟妇人妻av在线电影| www.激情小说.com| koreanbj精品视频一区| 国产精品12p| 国产激情在线观看视频| 国产成人强伦免费视频网站| ww国产内射精品后入国产| 特黄视频免费观看| 国产日韩成人内射视频| 青青草免费在线视频观看| 成年人小视频网站| 日韩国产一级片| 青青草免费在线视频观看| 国产成人精品无码播放| www.com毛片| 久久久久99精品成人片| 91性高潮久久久久久久| 欧美大尺度做爰床戏| 99精品视频在线看| 美女日批免费视频| 日韩专区第三页| 中文字幕超清在线免费观看| 色噜噜狠狠一区二区| 无码内射中文字幕岛国片| 国产69精品久久久久999小说| 999热精品视频| 五月天婷婷在线观看视频| 在线观看高清免费视频| 亚洲性生活网站| 天天爽天天爽夜夜爽| 日本三区在线观看| 日av中文字幕| 日韩精品一区中文字幕| 黄色高清无遮挡| 9久久婷婷国产综合精品性色| 久久久久久香蕉| 欧美成人精品欧美一级乱| 热久久精品免费视频| 久久这里只精品| 色黄视频免费看| 免费特级黄色片| 男人操女人逼免费视频| 妞干网在线免费视频| 青青青在线视频免费观看| 性chinese极品按摩| 99亚洲精品视频| 妺妺窝人体色777777| 亚洲中文字幕无码中文字| 精品www久久久久奶水| 九九精品久久久| 人妻无码一区二区三区四区| 欧洲精品一区二区三区久久| 久久精品视频91| 日本不卡一区二区三区四区| 亚洲熟妇av日韩熟妇在线| 污污动漫在线观看| 欧美又粗又长又爽做受| 在线黄色免费观看| av日韩一区二区三区| 国内国产精品天干天干| 日韩精品综合在线| 中文字幕国产免费| 日韩精品一区在线视频| 亚洲老女人av| 可以看毛片的网址| 午夜精品久久久久久久99热影院| 福利视频免费在线观看| 天天干天天色天天干| xxxx18hd亚洲hd捆绑| 亚洲高清在线不卡| 男女午夜激情视频| 国产欧美精品aaaaaa片| 中文字幕精品一区二区三区在线| 日韩xxxx视频| 中文字幕在线乱| 波多野结衣xxxx| 日av中文字幕| 欧美综合在线播放| 国产91在线亚洲| 国产又黄又爽免费视频| 午夜精品中文字幕| 韩国一区二区av| 日韩avxxx| av动漫在线看| 日本一道本久久| 日韩欧美一区三区| 免费一级特黄毛片| 久久久久久www| 国产精品成人久久电影| 国产精品三级一区二区| 国产高清精品软男同| 中文字幕成人免费视频| 色91精品久久久久久久久| 亚洲五月天综合| 在线观看免费成人av| 黄色国产小视频| 热久久精品免费视频| 中文字幕国产传媒| 亚洲综合在线网站| 向日葵污视频在线观看| 中文字幕 91| www.日本久久| 久久男人资源站| 欧美二区在线视频| 黄色三级视频片| 亚洲精品综合在线观看| 欧美爱爱视频网站| 69精品丰满人妻无码视频a片| 大胆欧美熟妇xx| 国产精品宾馆在线精品酒店| 任你操这里只有精品| 中文字幕成人免费视频| 在线观看免费黄色片| 久久99久久99精品| 国产淫片免费看| 天天干天天干天天干天天干天天干| 久久黄色片网站| 欧美日韩激情四射| 成人精品视频一区二区| 午夜福利123| 鲁一鲁一鲁一鲁一澡| 日日摸天天爽天天爽视频| 一本之道在线视频| 99精品在线免费视频| 最新中文字幕免费视频| 青青草影院在线观看| 男女av免费观看| 日韩精品第1页| 国产理论在线播放| 成人在线播放网址| 日韩av片专区| 成人综合视频在线| 男同互操gay射视频在线看| 91黄色小网站| 久久久久福利视频| 欧美一级视频在线| 激情婷婷综合网| 日韩一级性生活片| 国产精品波多野结衣| 国产无套粉嫩白浆内谢的出处| 一本色道久久88亚洲精品综合 | 欧美交换配乱吟粗大25p| 国产黄色特级片| 免费一级特黄毛片| 男女h黄动漫啪啪无遮挡软件| 欧美精品aaaa| av黄色在线网站| 国产欧美日韩网站| 中文字幕乱码免费| 国产一区二区在线观看免费视频| 国模无码视频一区二区三区| 91欧美一区二区三区| 国产小视频精品| 国产一级特黄a大片免费| 欧美 日韩精品| 亚洲精品中文字幕无码蜜桃| 1024av视频| 欧美 日韩精品| 精品人妻一区二区三区四区在线 | 中文字幕天天干| av网站在线不卡| 五月天婷婷亚洲| 久久婷五月综合| 岛国毛片在线播放|