标题:
Strongchen,Help。还是使用多通道PIT问题?
[打印本页]
作者:
chudf
时间:
2007-7-31 10:32
标题:
Strongchen,Help。还是使用多通道PIT问题?
这是我写的例程,还是发现这3个通道不能同时使用。估计是它们之间相互干涉了,我用的是9S12XDP512,4M晶振。
#include
/* common defines and macros */
#include
/* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"
void SetupPITimer (void)
{
/* time-out period = (PITMTLD0 + 1) * (PITLD0 + 1) / Fbus */
PITMUX &= ~(0x01|0x02|0x04); /* T0,T1 and T2 count with MT0 time base (0.25 us)*/
PITCE |= (0x01|0x02|0x04); /* enable PIT channel 0,1,2 */
PITCFLMT |= 0x80; /* PITE=1 (enable PIT) */
}
void EnablePIT0 (void)
{
PITTF |= 0x01; /* clear PIT channel 0 flag */
PITMTLD0 = 99; /* MT0 load value (divides bus clock) */
PITLD0 = 19999; /* T0 load value (5 ms) */
PITCFLMT |= 0x01; /* PFLMT0=1 (reload MT0) */
PITFLT |= 0x01; /* force reload of PIT channel 0 */
PITINTE |= 0x01; /* enable PIT channel 0 interrupt */
}
void EnablePIT1 (void)
{
PITTF |= 0x02; /* clear PIT channel 1 flag */
PITMTLD0 = 99; /* MT0 load value (divides bus clock) */
PITLD1 = 19999; /* T1 load value (5 ms) */
PITCFLMT |= 0x02; /* PFLMT0=1 (reload MT0) */
PITFLT |= 0x02; /* force reload of PIT channel 1 */
PITINTE |= 0x02; /* enable PIT channel 1 interrupt */
}
void EnablePIT2 (void)
{
PITTF |= 0x04; /* clear PIT channel 1 flag */
PITMTLD0 = 99; /* MT1 load value (divides bus clock) */
PITLD2 = 19999; /* T1 load value (5 ms) */
PITCFLMT |= 0x04; /* PFLMT0=1 (reload MT0) */
PITFLT |= 0x04; /* force reload of PIT channel 1 */
PITINTE |= 0x04; /* enable PIT channel 1 interrupt */
}
void IoInit (void)
{
DDRB |= 0x07; /* for test */
PORTB =0x07;
}
void main(void)
{
IoInit();
SetupPITimer();
EnablePIT0();
EnablePIT1();
EnablePIT2();
asm CLI;
for(;;)
{
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
/* interrupt handler for PIT 0 */
interrupt void ISR_PIT0 ()
{
//PITINTE &= not_bit0; /* disable this interrupt for channel 0 */
PITTF |= 0x01; /* clear the interrupt flag */
PORTB_PB0 = ~PORTB_PB0;
}
interrupt void ISR_PIT1 ()
{
//PITINTE &= not_bit0; /* disable this interrupt for channel 0 */
PITTF |= 0x02; /* clear the interrupt flag */
PORTB_PB1 = ~PORTB_PB1;
}
interrupt void ISR_PIT2 ()
{
//PITINTE &= not_bit0; /* disable this interrupt for channel 0 */
PITTF |= 0x04; /* clear the interrupt flag */
PORTB_PB2 = ~PORTB_PB2;
}
#pragma CODE_SEG DEFAULT
作者:
strongchen
时间:
2007-8-1 08:41
怎么不能同时使用,具体现象是什么?
作者:
chudf
时间:
2007-8-1 15:31
我分别在三个中断里面安排了三个LED,不断对它们取反,可是发现LED1不能闪(对应ISR_PIT1),我怀疑是因为PIT0与PIT1共有了一个微定时器MT0.不知道是不是这样了?
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0