区分XMEGA中的下降和上升边缘

时间:2015-05-26 10:40:02

标签: c avr

我有3个按钮,每次按下或释放时都会产生中断,我遇到的问题是,我需要分析实际发生​​的事情(重新按下或按下按钮),这是我的代码:

..................

 ISR(PORTA_INT0_vect){
    if(!(PORTA.IN & PIN1_bm)){  // Green LED  pressed
        printf(" Green button pressed\n");

    }

     if(!(PORTA.IN & PIN3_bm)){ // Blue LED pressed 
        printf(" Blue button pressed\n");

    }

    if (!(PORTA.IN & PIN5_bm)){ // Red LED
        printf(" Red button pressed  \n");

    }
}

 ISR(PORTA_INT1_vect){
  printf(" I'm in \n");
    if((PORTA.IN & PIN1_bm)){// Green LED  released
        printf("Green button  released \n");
    }
    else if((PORTA.IN & PIN3_bm)){// Blue  LED  released
        printf("Blue button released \n");
    }
    else if((PORTA.IN & PIN5_bm)){// Red LED  released
        printf("Red button released \n");
    }


 }

void buttonINT(){
    // PORTA 
    PORTA.PIN1CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_FALLING_gc ;
    PORTA.PIN3CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_FALLING_gc ;
    PORTA.PIN5CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_FALLING_gc ;
    PORTA.INT0MASK = PIN1_bm | PIN3_bm | PIN5_bm;
    PORTA.INTCTRL = PORT_INT0LVL0_bm;
    PMIC.CTRL |= PMIC_LOLVLEN_bm;
    sei();
    }
void buttonINT2(){
    // PORTA 
    PORTA.PIN1CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_RISING_gc ;
    PORTA.PIN3CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_RISING_gc ;
    PORTA.PIN5CTRL = PORT_OPC_PULLUP_gc|  PORT_ISC_RISING_gc ;
    PORTA.INT1MASK = PIN1_bm | PIN3_bm | PIN5_bm;
    PORTA.INTCTRL = PORT_INT1LVL1_bm;
    PMIC.CTRL |= PMIC_LOLVLEN_bm;
    sei();
    }

我得到的问题是程序根本没有通过上升沿产生中断?

知道我在这里做错了什么吗?

1 个答案:

答案 0 :(得分:1)

我建议使用定时器生成的中断每隔10毫秒轮询一次密钥。你可以在这里

  • debounce 密钥(即只有在2/3/4次读取时才接受密钥更改)...现在似乎经常被遗忘的事情
  • 检查上升和下降边缘
  • 提出关键状态变更"可以处理的标志&已从main()
  • 清除
  • 奖励:检查"长按键"
  • 奖励:检查" doubleclicks"