void timer0Init (unsigned int fz0)
{
LPC_TIM0->TCR = 0x02;
LPC_TIM0->IR = 1;
LPC_TIM0->CTCR = 0;
LPC_TIM0->TC = 0;
LPC_TIM0->PR = 0;
LPC_TIM0->MR0 = SystemFrequency /(4*fz0);
LPC_TIM0->MCR = 0x03;
LPC_TIM0->TCR = 0x01;
}
void timer1Init (unsigned int fz1)
{
LPC_TIM1->TCR = 0x02;
LPC_TIM1->IR = 1;
LPC_TIM1->CTCR = 0;
LPC_TIM1->TC = 0;
LPC_TIM1->PR = 0;
LPC_TIM1->MR0 = SystemFrequency /(4*fz1);
LPC_TIM1->MCR = 0x03;
LPC_TIM1->TCR = 0x01;
}
void timer2Init (unsigned int fz1)
{
LPC_TIM2->TCR = 0x02;
LPC_TIM2->IR = 1;
LPC_TIM2->CTCR = 0;
LPC_TIM2->TC = 0;
LPC_TIM2->PR = 0;
LPC_TIM2->MR0 = SystemFrequency /(4*fz1);
LPC_TIM2->MCR = 0x03;
LPC_TIM2->TCR = 0x01;
timer2_counter = 0;
}
前个定时器初始化没问题,为什么TIM2定时器初始化有问题,程序直接跳转到了HardFault_Handler
此帖出自
小平头技术问答
Timer 2 power/clock enable 设置了没
LPC_SC->PCONP = 0x042887DE;不晓得什么意思
Power Control for Peripherals Register (PCONP)
这32bit里有1bit跟timer2有关,须置1打开
// <o11.1> PCTIM0: Timer/Counter 0 power/clock enable
// <o11.2> PCTIM1: Timer/Counter 1 power/clock enable
// <o11.3> PCUART0: UART 0 power/clock enable
// <o11.4> PCUART1: UART 1 power/clock enable
// <o11.6> PCPWM1: PWM 1 power/clock enable
// <o11.7> PCI2C0: I2C interface 0 power/clock enable
// <o11.8> PCSPI: SPI interface power/clock enable
// <o11.9> PCRTC: RTC power/clock enable
// <o11.10> PCSSP1: SSP interface 1 power/clock enable
// <o11.12> PCAD: A/D converter power/clock enable
// <o11.13> PCCAN1: CAN controller 1 power/clock enable
// <o11.14> PCCAN2: CAN controller 2 power/clock enable
// <o11.15> PCGPIO: GPIOs power/clock enable
// <o11.16> PCRIT: Repetitive interrupt timer power/clock enable
// <o11.17> PCMC: Motor control PWM power/clock enable
// <o11.18> PCQEI: Quadrature encoder interface power/clock enable
// <o11.19> PCI2C1: I2C interface 1 power/clock enable
// <o11.21> PCSSP0: SSP interface 0 power/clock enable
// <o11.22> PCTIM2: Timer 2 power/clock enable
// <o11.23> PCTIM3: Timer 3 power/clock enable
// <o11.24> PCUART2: UART 2 power/clock enable
// <o11.25> PCUART3: UART 3 power/clock enable
// <o11.26> PCI2C2: I2C interface 2 power/clock enable
// <o11.27> PCI2S: I2S interface power/clock enable
// <o11.29> PCGPDMA: GP DMA function power/clock enable
// <o11.30> PCENET: Ethernet block power/clock enable
// <o11.31> PCUSB: USB interface power/clock enable
// </h>
一周热门 更多>