int main(void) { initIO(); //Setup LED and Button pins timer0_overflow(); //Setup the button debounce timer initTimer1_modes(); //Setup the delay timer state = sweep; //Set default state initState(state); //Setup initial state while(1) { //If interrupt set the timer flag act on that if (timer) { switch (state) { case sweep: if (direction) tracker <<= 1; else tracker >>= 1; if ((tracker == 0x01) | (tracker == 0x80)) direction ^= 1; ledPort = tracker; break; case xor: toggle_led(); break; case flash: toggle_led(); break; case sleep: //Arriving here means we just woke up from sleep state = sweep; //Reset state machine initState(state); break; } timer = 0; } if( get_key_press( 1<<KEY0 )) { timer1_stop(); //Halt the delay timer timer = 0; //Clear delay timer flag //Increment the state machine if (++state > sleep) state = sweep; initState(state); } } }
/* PD(3) ONSWITCH_DB (PB_STAT), any change */ irqreturn_t ltc3675_button_change_irq_handler(void) { bool pin_state; pin_state = io_test_pin(ONSWITCH_DB); /* the pushbutton is active low, therefore backwards logic */ if (pin_state && !button.onswitch_last_state) { button.onswitch_release_event = true; timer1_stop(); } else if (!pin_state && button.onswitch_last_state) { button.onswitch_press_event = true; timer1_start(); } button.onswitch_last_state = pin_state; return IRQ_HANDLED; }
void interrupt ISR(){ static int blinkCounter =0; //Timer 0 Overflow - Filter for LVL One if(TMR0IF && TMR0IE){ switch(blinkState) { case FILTER_BLINK_FAST: if((blinkCounter % 5) == 0) { LEDPORT ^= ALMLED; } break; case ALARM_BLINK_SLOW: if((blinkCounter % 15) == 0) { LEDPORT ^= ALMLED; } break; case ALARM_SOLID_ON: LEDPORT |= ALMLED; break; case LIGHTS_OFF: default: LEDPORT &= ~(ALMLED); } blinkCounter ++; blinkCounter %= 1000; TMR0IF = 0; } //Timer 1 Overflow if(TMR1IE && TMR1IF){ switch(theAlarm.ALARM_STATE){ case ALARM_ON: theAlarm.current_value += 1; break; case ALARM_DOUBLE_TIME: theAlarm.current_value += 3; break; case ALARM_FINAL_STATE: default: timer1_stop(); } TMR1IF = 0; } //Timer 2 Overflow - Filter Counter for both Sensors if(TMR2IF && TMR2IE){ if(levelSensors[0].LEVEL_STATE == TRANSITION_TO_EMPTY || levelSensors[0].LEVEL_STATE == TRANSITION_TO_FULL){ //Transition States levelSensors[0].counter++; } if(levelSensors[1].LEVEL_STATE == TRANSITION_TO_EMPTY || levelSensors[1].LEVEL_STATE == TRANSITION_TO_FULL){ //Transition States levelSensors[1].counter++; } TMR2IF = 0; } //ADC Interrupt Flag if(ADIF && ADIE){ theAlarm.trigger_value = ADRESH; ADIF = 0; } }