void APP_TimerCallBack ( uintptr_t context, uint32_t tickCount ) { uint32_t portBits; /* If we're in a debounce state, check port to see if switch is pressed. */ if ( appData.state == APP_STATE_DEBOUNCE_START || appData.state == APP_STATE_DEBOUNCE_STOP ) { appData.timeoutCounter++; portBits = PLIB_PORTS_Read(PORTS_ID_0, APP_CN_PORT_CHANNEL); if (APP_CN_PRESS_EQUALS_1_OR_0 == 0) // if pressed switch puts 0 on pin { if ( (1 << APP_CN_PORT_BIT) & portBits) // if switch is bouncing { appData.debounceCounter = 0; // reset count } else { appData.debounceCounter++; // switch stable } } else // pressed switch puts 1 on pin { if ( !((1 << APP_CN_PORT_BIT) & portBits)) // if switch is bouncing { appData.debounceCounter = 0; // reset count } else { appData.debounceCounter++; // switch stable } } /* If switch is pressed for APP_DEBOUNCE_COUNT counts, it's real. */ if (appData.debounceCounter >= APP_DEBOUNCE_COUNT) { appData.switchHasBeenPressed = true; } } /* If we're in a blinking state, blink the LED. */ if ( appData.state == APP_STATE_LED_BLINKING || appData.state == APP_STATE_DEBOUNCE_STOP ) { BSP_LEDToggle(APP_BSP_LED); } }