Beispiel #1
0
int main(void)
{
    enableInterrupts();
    initLEDs();
    initSW2();
    initTimer2();
    updateLEDState();
    
    
    while(1)
    {
        switch (currentState)
        {
            case wait:
                if(buttonState==risingEdge)//button is pressed
                {
                    
                    currentState=debouncePress;
                    buttonState=Idle;
                }
//                if(IFS1bits.CNDIF==1)
//                //if(PORTDbits.RD6==0) //!!! use change notifications, not polling
//                {
//                    currentState=debouncePress;
//                }
                break;
            case debouncePress:
                delayUs(50);
                currentState=waitForRelease;
                break;
            case waitForRelease:
                //!!! use change notifications, not polling
                if(buttonState==fallingEdge)//button released
                {
                    currentState=debounceRelease;
                    buttonState=Idle;
                }
//                if(IFS1bits.CNDIF==1)
//                //if(PORTDbits.RD6==1)//released
//                {
//                    currentState=debounceRelease;
//                }
                break;
            case debounceRelease:
                delayUs(50);
                updateLEDState();
                currentState=wait;
                break;
        }
        
    }
    
    return 0;
}
Beispiel #2
0
int main(void) {
	wdt_enable(WDTO_1S);
  initPodControls();

	/* Even if you don't use the watchdog, turn it off here. On newer devices,
	 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
	 */
	/* RESET status: all port bits are inputs without pull-up.
	 * That's the way we need D+ and D-. Therefore we don't need any
	 * additional hardware initialization.
	 */
	usbInit();
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
	uchar i = 0;
	while(--i){             /* fake USB disconnect for > 250 ms */
			wdt_reset();
			_delay_ms(1);
	}

	usbDeviceConnect();
	sei();
	for(;;){                /* main event loop */
			wdt_reset();
			usbPoll();
			if(usbInterruptIsReady()){
				/* called after every poll of the interrupt endpoint */
				usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
			} else {
				updateSensorData();
        updateLEDState();
      }
	}
}