static void sw1_isr (void) { /* TODO: Add some debouncing! */ /* Call callback function. */ SW1_CALLBACK_FUNCTION(); }
/*********************************************************************************************************************** * Function name: R_SWITCHES_Update * Description : Polls switches and calls callback functions as needed. If you are using IRQ mode then this function * is not needed and can be removed if desired. It is left in so that code will not fail when switching * between polling or IRQ mode. * Arguments : none * Return value : none ***********************************************************************************************************************/ void R_SWITCHES_Update (void) { #if SWITCHES_DETECTION_MODE == 1 /* This code is only needed for polling mode. */ /* Check switch 1. */ if (SW1 == SW_ACTIVE) { if (g_switches[0].active != true) { if (++g_switches[0].debounce_cnt >= g_sw_debounce_cnts) { /* Set this to true so we only call the callback function once per press. */ g_switches[0].active = true; /* Call callback function. */ SW1_CALLBACK_FUNCTION(); } } } else { if (0 == g_switches[0].debounce_cnt) { g_switches[0].active = false; } else { g_switches[0].debounce_cnt--; } } /* Check switch 2. */ if (SW2 == SW_ACTIVE) { if (g_switches[1].active != true) { if (++g_switches[1].debounce_cnt >= g_sw_debounce_cnts) { /* Set this to true so we only call the callback function once per press. */ g_switches[1].active = true; /* Call callback function. */ SW2_CALLBACK_FUNCTION(); } } } else { if (0 == g_switches[1].debounce_cnt) { g_switches[1].active = false; } else { g_switches[1].debounce_cnt--; } } /* Check switch 3. */ if (SW3 == SW_ACTIVE) { if (g_switches[2].active != true) { if (++g_switches[2].debounce_cnt >= g_sw_debounce_cnts) { /* Set this to true so we only call the callback function once per press. */ g_switches[2].active = true; /* Call callback function. */ SW3_CALLBACK_FUNCTION(); } } } else { if (0 == g_switches[2].debounce_cnt) { g_switches[2].active = false; } else { g_switches[2].debounce_cnt--; } } #endif /* SWITCHES_DETECTION_MODE */ }