int main(void) { uchar i; /* calibration value from last time */ uchar calibrationValue = eeprom_read_byte(EEPROM_OSCCAL); if(calibrationValue != 0xff) { OSCCAL = calibrationValue; } wdt_enable(WDTO_1S); /* 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. */ odDebugInit(); DBG1(0x00, 0, 0); /* debug output: main starts */ sbi(DDRB, WHITE_LED); sbi(DDRB, YELLOW_LED); cbi(DDRB, 4); cbi(PORTB, 4); sbi(MCUCR, PUD); timerInit(); //Create a timer that will trigger a flag at a ~60hz rate adcInit(); //Setup the ADC conversions usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; while(--i) { /* fake USB disconnect for > 250 ms */ wdt_reset(); _delay_ms(1); } usbDeviceConnect(); //set_sleep_mode(SLEEP_MODE_PWR_SAVE); //sleep_mode(); //sleep_enable(); sei(); DBG1(0x01, 0, 0); /* debug output: main loop starts */ for(;;) { /* main event loop */ DBG1(0x02, 0, 0); /* debug output: main loop iterates */ //sleep_cpu(); sbi(PORTB, YELLOW_LED); wdt_reset(); usbPoll(); cbi(PORTB, YELLOW_LED); if(usbInterruptIsReady()) { /* called after every poll of the interrupt endpoint */ reportBuffer.adcvalue = getAdcValue(); DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */ usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer)); } timerPoll(); adcPoll(); _delay_ms(5); } return 0; }
int main(void) { //uchar i; unsigned int i; uchar calibrationValue; calibrationValue = eeprom_read_byte(0); /* calibration value from last time */ if(calibrationValue != 0xff){ OSCCAL = calibrationValue; } //odDebugInit(); //Production Test Routine - Turn on both LEDs and an LED on the SparkFun Pogo Test Bed. DDRB |= 1 << WHITE_LED | 1 << YELLOW_LED | 1<<4; /* output for LED */ sbi(PORTB, WHITE_LED); for(i=0;i<20;i++){ /* 300 ms disconnect */ _delay_ms(15); } cbi(PORTB, WHITE_LED); sbi(PORTB, YELLOW_LED); for(i=0;i<20;i++){ /* 300 ms disconnect */ _delay_ms(15); } cbi(PORTB, YELLOW_LED); sbi(PORTB, 4); for(i=0;i<20;i++){ /* 300 ms disconnect */ _delay_ms(15); } cbi(PORTB, 4); DDRB &= ~(1<<4); //Initialize the USB Connection with the host computer. usbDeviceDisconnect(); for(i=0;i<20;i++){ /* 300 ms disconnect */ _delay_ms(15); } usbDeviceConnect(); wdt_enable(WDTO_1S); timerInit(); //Create a timer that will trigger a flag at a ~60hz rate adcInit(); //Setup the ADC conversions usbInit(); //Initialize USB comm. sei(); for(;;){ /* main event loop */ wdt_reset(); usbPoll(); //Check to see if it's time to send a USB packet if(usbInterruptIsReady() && nextDigit != NULL){ /* we can send another key */ buildReport(); //Get the next 'key press' to send to the host. usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); if(*++nextDigit == 0xff) /* this was terminator character */ nextDigit = NULL; } timerPoll(); //Check timer to see if it's time to start another ADC conversion. adcPoll(); //If an ADC conversion was started, get the value and switch to the other ADC channel for the next conversion. } return 0; }