(LPC1769) Timer Interrupt Application

void TIMER0_IRQHandler (void)
{
    if(LPC_TIM0->IR & 0x01)
    {
        LPC_GPIO1->FIOPIN ^= (1 << 14);
        LPC_TIM0->IR = 0x01;
    }
}

/*
 *  CPU : LPC1769
 *  Operate Frequency : 120MHz
 *  Timer Interrupt Example :
 *        TCR : Counter Enable/Disable
 *        PR : PreScale register
 *        MR0 : when TC(timer counter) match MR0. the cup action are to generator an interrupt, reset the TC
 *        or stop the timer.
 *        IR : if an interrupt is generated that the corresponding bit in the IR will be high.
 *        writing a 1 to corresponding IR bit will reset the interrupt.
 *        writing a 0 has no effect.
 *        MCR : it will be control timer function that interrupt enable/disable. reset TC if MR0 matchit.
 *
 * */
int main(void)
{
    CFWInit();
    LPC_GPIO1->FIODIR |= (1<<14);
    LPC_GPIO1->FIOPIN &= ~(1<<14);
    LPC_SC->PCONP |= 1 << 1;                /* power control --> power saving function */
    LPC_SC->PCLKSEL0 |= (0x01 << 2);        /* Enable Timer0 peripheral clock */
    LPC_TIM0->TCR = 0x02;                     /* reset timer */
    LPC_TIM0->PR = 0x00;                     /* set prescaler to zero */
    LPC_TIM0->MR0 = 119;                     /* set the count value */
    LPC_TIM0->IR = 0xff;                     /* reset all interrupts */
    LPC_TIM0->MCR = 0x03;                     /* stop timer on match */
    NVIC_EnableIRQ(TIMER0_IRQn);
    LPC_TIM0->TCR = 0x01;                     /* start the timer */
    while(1);
}

 

posted on 2019-04-30 10:06  OO程式猿  阅读(264)  评论(0编辑  收藏  举报

导航