This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

interrrupt on both key press and key release

Hello

I want to know how its possible to generate interrupt on key press and generate interrupt  on release which is on port P0.0 and P0.1 

I have done in this way but it generate only one time interrupt

P2INP |= 0x20; // pull P0 low
P0IFG = ~(0x03); // clear status flag for P0_0/1
P0IF = 0; // clear CPU interrupt status flag for P0
P0IEN |= 0x03; // enable interrupts on P0_0/1

PICTL &= ~(0x01); // P0 interrupt on rising edge

IEN1 |= 0x20; // enable P0 interrupts

Please reply ASAP

Regards

Amit

  • Hello Amit,

    Only one interrupt is generated for a port pin. There is no way to distinguish between an interrupt that is generated when the pin is configured to trigger on positive, negative or both edges. This means that you would have to reconfigure the interrupt for each edge you are trying to capture.

    Unless you implement some form of key Debouncing, your setup will not work correctly. The way SimpleKeys does it is to implement an interrupt then use software Debouncing and then I believe it switches to polling the input.

    Follow the method used in SimpleKeys for detecting the first edge then use polling to detect when it was released.

    Thanks,