陆续买了2块ATMEGA 128的开发板,都是最小系统板,所有IO口引出。
同样的一个测试程序,就是定时器计数,每100ms反转LED。同样的8M晶振。
反正一片正常,另外一片明显缓慢。将近1s才反转。
想咨询下,影响定时器的因素大概会是什么?
熔丝位没有配置过,同一个程序,IAR编译,JTAGICE烧写。
- /*
- *********************************************************************************************************
- * 函 数 名: bsp_InitTimer
- * 功能说明: 配置systick中断,并初始化软件定时器变量
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void bsp_InitTimer(void)
- {
- _CLI(); // 关总中断
- TCCR0 = 0x00; //停止定时器0
- TIMSK &= ~(1<<OCIE0); //禁止T/C0比较中断,只修改OCIE0的值,而不影响其他位
-
- TCCR0 = 0x0C; //内部时钟,CTC模式,进行64分频 (0x0000 1100)(8 Mhz/64 = 125 khz)
- TCNT0 = 0x00; //赋计数初值
- OCR0 = 0x7C; //OCR0 = 0x7C(124),(124+1)/125khz= 1ms
- TIMSK |= (1<<OCIE0); //启用T/C0比较中断,将原来OCIE0为0的值,修改为1,而不影响其他位的值
- _SEI(); // 开总中断
-
- }
- /*
- *********************************************************************************************************
- * 函 数 名: SysTick_ISR
- * 功能说明: SysTick中断服务程序,每隔1ms进入1次
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- extern void bsp_RunPer1ms(void); /* 此函数在 bsp.c 中定义 */
- extern void bsp_RunPer2ms(void); /* 此函数在 bsp.c 中定义 */
- extern void bsp_RunPer10ms(void); /* 此函数在 bsp.c 中定义 */
- extern void bsp_RunPer100ms(void); /* 此函数在 bsp.c 中定义 */
- extern void bsp_RunPer300ms(void); /* 此函数在 bsp.c 中定义 */
- extern void bsp_RunPer500ms(void); /* 此函数在 bsp.c 中定义 */
- #pragma vector=TIMER0_COMP_vect
- __interrupt void SysTick_ISR(void)
- {
- static Uint8 s_count = 0;
- static Uint8 t_count = 0;
- static Uint8 r_count = 0;
- static Uint16 u_count = 0;
- static Uint16 w_count = 0;
- bsp_RunPer1ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- if (++t_count >= 2)
- {
- t_count = 0;
- bsp_RunPer2ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- }
- if (++s_count >= 10)
- {
- s_count = 0;
- bsp_RunPer10ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- }
- if (++r_count >= 100)
- {
- r_count = 0;
- bsp_RunPer100ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- }
- if (++u_count >= 300)
- {
- u_count = 0;
- bsp_RunPer300ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- }
- if (++w_count >= 500)
- {
- w_count = 0;
- bsp_RunPer500ms(); /* 此函数在 bsp.c 中实现(可以为空) */
- }
- }
- bsp_RunPer100ms(); //此函数里就只有一个语句,反转LED
|