ifare 发表于 2012-1-12 15:48:17

请教: 向外部中断INT0发送下降沿触发脉冲过快, 导致INT0后来失去反应

在中断服务程序里已经关掉中断, 并清除了中断标志位


=================================INT0_M16.c==========================================================


#include "public.h"
#include "Delay_7.37M.h"

#include "Usart_M16.h"
#include "Timer0_M16.h"
#include "INT0_M16.h"
#include "App.h"


#define INT0_DDRDDRD
#define INT0_PORT PORTD
#define INT0_PINPIND
#define INT0_IO   2

unsigned char flg_Int0_In;

void Int0_Init(void)
{
   GICR|= (1<<6);      //enable int0

   //设置中断引脚为输入(示例为M16的PD2)
   INT0_DDR&=~(1<<INT0_IO);
   INT0_PORT|=(1<<INT0_IO);               

   MCUCR|= (1<<1);   //mod set --下降沿方式
   MCUCR&= ~(1<<0);   

}

#pragma interrupt_handler ISR_Int0:iv_INT0
void ISR_Int0(void)
{
   flg_Int0_In=1;

   GICR&= ~(1<<6);   //disable int0-- 关闭中断
   
}

void Int0_DoWithInt(void)
{                       


   UART_Puts("int0.. ");
                  
   GIFR|= (1<<6);      //通过写入"1"到GIFR.6来清零中断int0的标志位
   GICR|= (1<<6);      //enable int1
}

ifare 发表于 2012-1-12 15:49:37

==============================main.c=======================================
#include "public.h"
#include "Delay_7.37M.h"

#include "Usart_M16.h"
#include "Timer0_M16.h"
#include "INT1_M16.h"
#include "App.h"

#include "INT0_M16.h"


void main(void)
{
   unsigned char i;
   
   
   CLI();

   Int0_Init();
   Int1_Init();
   UART_Init();
   Timer0_Init();
   
   SEI();
   
   UART_Puts("start ");

   
   while (1)
   {   
      
      //响应串口中断
      if (flg_Received )
      {
         //DoWithUart(); flg_Received=0;
         
      }
      
      //响应定时器中断
      if (flg_Timer0==1 )
      {
         DoWithTimer0(); flg_Timer0=0;
         
      }
      
      //响应外部中断      
      if (flg_Int0_In==1)
      {                                             
         Int0_DoWithInt(); flg_Int0_In=0;       
      }   
      
      
      
   }   
   
}

ifare 发表于 2012-1-12 16:13:43

中断又发现问题了

ifare 发表于 2012-1-12 18:11:39

继续问, 是用红外手柄向int0发送数据, 每个下降沿都触发中断来進行测试

没几下int0就停止反应, 而timer0还可继续向串口不断发送数据

yl3721 发表于 2012-1-12 21:29:36

设为低电平中断试试

ifare 发表于 2012-1-12 22:12:44

谢谢, 明天试试

ifare 发表于 2012-1-13 14:21:14

是电源的问题
页: [1]
查看完整版本: 请教: 向外部中断INT0发送下降沿触发脉冲过快, 导致INT0后来失去反应