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); }
原文地址:https://www.cnblogs.com/ollie-lin/p/10794434.html
时间: 2024-10-10 05:30:28