初学ARM,使用定时器遇到问题了,请大家帮忙看一下,
Timer0初始化函数如下:
void Timer0Init(FuncPtr timer0IrqHandler) { U32 dummy; if(timer0IrqHandler == NULL) { return; } //开TIMER0时钟 AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 0x1<<AT91C_ID_TC0);
//禁止记数时钟 AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
//禁止中断 AT91F_TC_InterruptDisable(AT91C_BASE_TC0, 0xFFFF);
dummy = AT91C_BASE_TC0->TC_SR; dummy = dummy;
//设置TC模式 AT91C_BASE_TC0->TC_CMR = TC_CLKS_MCK1024;// |0x2<<13; // enable counter clock // AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
// 打开定时器0中断 AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, //base AT91C_ID_TC0, //ID TIMER0_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, timer0IrqHandler);
//设置记数值, 0.1ms一次中断 AT91C_BASE_TC0->TC_RC = TIMER_100US_MCK1024_RC; AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; // IRQ使能CPC
//允许TC0中断 AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_TC0);
}
中断处理函数 void Timer0IrqHandler(void) { unsigned int clear_SR;
//读取,同时清除状态积存器 clear_SR = AT91C_BASE_TC0->TC_SR; //避免编译警告 clear_SR = clear_SR; }
中断处理函数总是进入不了,请大家帮忙看一下,谢谢了。 编译器:Keil 3.4
|