interrupt rising/falling edge test

Dependencies:   mbed

Committer:
iamhuzhe
Date:
Thu Jul 22 01:35:19 2010 +0000
Revision:
0:bdf893fb0228

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iamhuzhe 0:bdf893fb0228 1 #include "mbed.h"
iamhuzhe 0:bdf893fb0228 2
iamhuzhe 0:bdf893fb0228 3 BusOut leds( LED4, LED3, LED2, LED1 );
iamhuzhe 0:bdf893fb0228 4 char count;
iamhuzhe 0:bdf893fb0228 5
iamhuzhe 0:bdf893fb0228 6 InterruptIn button( p16 ); // interrupt instance for the button
iamhuzhe 0:bdf893fb0228 7 Timer t; // To manage debounce by menchanical switch
iamhuzhe 0:bdf893fb0228 8
iamhuzhe 0:bdf893fb0228 9 #define DEBOUNCING_INTERVAL 20 // Debouncing interval (in mili-seconds)
iamhuzhe 0:bdf893fb0228 10
iamhuzhe 0:bdf893fb0228 11 void isr_buton( void ) {
iamhuzhe 0:bdf893fb0228 12 if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
iamhuzhe 0:bdf893fb0228 13 leds = (count++) & 0xF;
iamhuzhe 0:bdf893fb0228 14 }
iamhuzhe 0:bdf893fb0228 15 t.reset(); // timer reset
iamhuzhe 0:bdf893fb0228 16 }
iamhuzhe 0:bdf893fb0228 17
iamhuzhe 0:bdf893fb0228 18 void isr_button2(void) {
iamhuzhe 0:bdf893fb0228 19 if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
iamhuzhe 0:bdf893fb0228 20 leds = (count--) & 0xF;
iamhuzhe 0:bdf893fb0228 21 }
iamhuzhe 0:bdf893fb0228 22 t.reset(); // timer reset
iamhuzhe 0:bdf893fb0228 23 }
iamhuzhe 0:bdf893fb0228 24
iamhuzhe 0:bdf893fb0228 25 int main() {
iamhuzhe 0:bdf893fb0228 26 count = 0;
iamhuzhe 0:bdf893fb0228 27 t.start(); // timer start
iamhuzhe 0:bdf893fb0228 28 button.rise( &isr_buton );
iamhuzhe 0:bdf893fb0228 29 button.fall(&isr_button2);
iamhuzhe 0:bdf893fb0228 30 while ( 1 ) {
iamhuzhe 0:bdf893fb0228 31 }
iamhuzhe 0:bdf893fb0228 32 }