void init_interrupt(void)
{
EX0 = 1; /* 1=Enable External interrupt 0 */
ET0 = 1; /* 1=Enable Timer 0 interrupt */
EX1 = 0; /* 1=Enable External interrupt 1 */
ET1 = 0; /* 1=Enable Timer 1 interrupt */
ES = 0; /* 1=Enable Serial port interrupt */
ET2 = 0; /* 1=Enable Timer 2 interrupt */
IT0 = 1; /* 1 =INT0 Trigger on fall slope */
EA = 1; /* 0=Disable all interrupts */
}
void edge_detect(void) interrupt 0
{
disable_interrupt0();
disable_keypad();
ctrl_1 = !ctrl_1;
i2c_receive_packet();
ctrl_1 = !ctrl_1;
enable_keypad();
enable_interrupt0();
}
void disable_interrupt0(void)
{
EX0 = 0; /* 1=Enable External interrupt 0 */
}
void enable_interrupt0(void)
{
EX0 = 1; /* 1=Enable External interrupt 0 */
}
当I2C数据来时,触发外部中断0,进入中断程序,在中断程序内部先禁止中断0,避免后面的数据下降沿触发中断。接收完数据后,开中断0后返回。
现在我发现接收完一个完整的数据包退出中断后,立即又触发了一次中断,进入了中断服务程序。请问各位大虾这可能是什么原因。
以下是引用Lichunfu在2003-7-14 9:42:06的发言: 我想是这样的...!虽然你已经禁止了INT0的中断,但是INT0引脚上的下降沿同样会使INT0的中断请求标志IE0置位,只是程序不转到INT0中断入口地址处罢了,而IE0是不能由软件清除的,如果此时重新开放INT0的中断后的下一周期立即回触发另一次中断。我在做一个项目时就发现有这个问题,我当时是用定时器1,对于INT0我想也应该是这个问题。 |