int main(void) { led_init(); sht1x_init(); //sser_init(); 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 */ usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ unsigned char i = 0; while(--i){ /* fake USB disconnect for > 250 ms */ wdt_reset(); _delay_ms(1); } usbDeviceConnect(); sei(); DBG1(0x01, 0, 0); /* debug output: main loop starts */ for(;;){ wdt_reset(); usbPoll(); } return 0; /* never reached */ }
int main() { fabscan_setup(); uchar i; // wdt_enable(WDTO_1S); // enable 1s watchdog timer usbInit(); usbDeviceDisconnect(); // enforce re-enumeration for(i = 0; i<250; i++) { // wait 500 ms // wdt_reset(); // keep the watchdog happy _delay_ms(2); } usbDeviceConnect(); sei(); // Enable interrupts after re-enumeration while(1) { // wdt_reset(); // keep the watchdog happy usbPoll(); if(fab_work_flag) // if there is new data for fabscan → let it work { fab_work_flag=0; fabscan_work(1,incomingByte); } } return 0; }
int main() { initLCD(); LCD_goto(1,0); lcd_puts("AVRLCD 4bit mode"); uchar i; DDRB = 1; // PB0 as output wdt_enable(WDTO_1S); // enable 1s watchdog timer usbInit(); usbDeviceDisconnect(); // enforce re-enumeration for(i = 0; i<250; i++) { // wait 500 ms wdt_reset(); // keep the watchdog happy _delay_ms(2); } usbDeviceConnect(); sei(); // Enable interrupts after re-enumeration while(1) { wdt_reset(); // keep the watchdog happy usbPoll(); } return 0; }
int main(void) { wdt_enable(WDTO_1S); odDebugInit(); hardwareInit(); usbInit(); intr3Status = 0; sendEmptyFrame = 0; sei(); for(;;){ /* main event loop */ wdt_reset(); usbPoll(); uartPoll(); #if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* We need to report rx and tx carrier after open attempt */ if(intr3Status != 0 && usbInterruptIsReady3()){ static uchar serialStateNotification[10] = {0xa1, 0x20, 0, 0, 0, 0, 2, 0, 3, 0}; if(intr3Status == 2){ usbSetInterrupt3(serialStateNotification, 8); }else{ usbSetInterrupt3(serialStateNotification+8, 2); } intr3Status--; } #endif } return 0; }
// main int main(void) { wdt_enable(WDTO_1S); hardwareInit(); usbInit(); sei(); unsigned int adcValue,replymask,replyshift,replybyte; while(1) { uchar i = 0; wdt_reset(); usbPoll(); PORTD ^= (1 << 6); //jump to bootloader if jumper is HIGH if(bit_is_clear(PIND, 5)) { startBootloader(); } for(i = 0; i < ADC_CHANNELS; i++) { //adcValue = adc_read(ADC_PRESCALER_32, ADC_VREF_AVCC, i); adcValue = i; usb_reply[i] = adcValue >> 2; replybyte = 16 + (i / 4); replyshift = ((i % 4) * 2); replymask = (3 << replyshift); usb_reply[replybyte] = (usb_reply[replybyte] & ~replymask) | (replymask & (adcValue << replyshift)); _delay_us(ADCDELAY); } usb_reply[20] = PINC; } return 0; }
void main(void) { uint16 speed = param_speed; uint8 port = param_port, pin=param_pin; uint8 ServoPos = 120; uint8 dir=1; systemInit(); usbInit(); InitServos(); EA=1; // Global interrupt enabled SetPin(0, port, pin); SetPin(1, 0, 1); SetPin(2, 0, 3); while (1) { delayMs(speed); usbComService(); if (dir==1) { ++ServoPos; } else { --ServoPos; } if (ServoPos > 253 || ServoPos < 2) { dir ^=1; } SetPos(0,ServoPos); SetPos(1,128); SetPos(2,64); } }
void __attribute__((noreturn)) main( void ) { cli(); initLeds(); wdt_enable( WDTO_1S ); // USB initialization. usbInit(); usbDeviceDisconnect(); // enforce re-enumeration, do this while interrupts are disabled! unsigned char b = 150; while ( b-- ) { _delay_ms( 1 ); wdt_reset(); } cpuIoInit(); usbDeviceConnect(); sei(); for ( ;; ) { // main event loop usbPoll(); wdt_reset(); cpuIoPoll(); //_delay_ms( 10 ); } }
/************************************************************************* NAME InitEarlyUserFeatures DESCRIPTION This function initialises the configureation that is required early on in the start-up sequence. RETURNS */ void InitEarlyUserFeatures ( void ) { ChargerConfigure(CHARGER_SUPPRESS_LED0, TRUE); /* Initialise the Button Manager */ buttonManagerInit() ; /* Once system Managers are initialised, load up the configuration */ configManagerInit(TRUE); /* Init wired before USB or wired audio gets routed before init */ wiredAudioInit(); /* USB init can be done once power lib initialised */ usbInit(); /* initialise the display */ displayInit(); /* initialise DUT */ dutInit(); /*configure the audio Pre amp if enabled */ initPreAmp( AUDIO_CHANNEL_A) ; initPreAmp( AUDIO_CHANNEL_B) ; /* Enter the limbo state as we may be ON due to a charger being plugged in */ stateManagerEnterLimboState(); }
int main( void ) { //=========================================== uchar calibrationValue; calibrationValue = eeprom_read_byte(0); /* calibration value from last time */ if(calibrationValue != 0xff){ OSCCAL = calibrationValue; } //=========================================== usbInit(); wdt_enable(WDTO_1S); /* Даже если Вы не используете сторожевой таймер (watchdog), выключите его здесь. На более новых * микроконтроллерах состояние watchdog (вкл\выкл, период) СОХРАНЯЕТСЯ ЧЕРЕЗ СБРОС! */ //=========================================== usbDeviceDisconnect(); _delay_ms(300); /* 300 ms disconnect */ usbDeviceConnect(); //=========================================== //LED_PORT_DDR |= _BV(LED_BIT); /* делаем ножку, куда подключен LED, выходом */ sbi(LED_PORT_DDR,LED_BIT); /* делаем ножку, куда подключен LED, выходом */ //=========================================== sei(); /* Разрешаем прерывания*/ for(;;){ /* main event loop */ wdt_reset(); usbPoll(); } //=========================================== }
void vusb_init(void) { // inits the timer used for idle rate // a rate of 12M/(1024 * 256) = 45.78 Hz (period = 21845us) TCCR0B = _BV(CS02) | _BV(CS00); #define TMR1US 21845L // a rate of 12M/(64 * 256) = 732,42 Hz (1365us) // TCCR0B = _BV(CS01) | _BV(CS00); //#define TMR1US 1365L #define OVF2MS(tmr) ((uint16_t)(( (tmr) * TMR1US) / 1000)) #define OVF2US(tmr) ((uint16_t)( (tmr) * TMR1US)) usbInit(); usbDeviceDisconnect(); // enforce re-enumeration, do this while interrupts are disabled! _delay_ms(260); // fake USB disconnect for > 250 ms usbDeviceConnect(); vusb_idle_rate = 0; vusb_curr_protocol = 1; // report protocol // clear the reports usb_consumer_report = 0; reset_keyboard_report(); }
void main() { uint32 last_ms; systemInit(); //configure the P1_2 and P1_3 IO pins makeAllOutputs(LOW); //initialise Anlogue Input 0 P0INP = 0x1; //initialise the USB port usbInit(); usbComRequestLineStateChangeNotification(LineStateChangeCallback); last_ms = getMs(); while (1) { boardService(); usbComService(); if((getMs()-last_ms) >=5000){ LED_YELLOW_TOGGLE(); printf("batteryPercent: %i\r\n", batteryPercent(adcRead(0 | ADC_REFERENCE_INTERNAL))); last_ms=getMs(); } } }
int main() { uchar i=0; wdt_enable(WDTO_1S); usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ for (i=0; i<250; i++) { /* fake USB disconnect for > 500 ms */ wdt_reset(); _delay_ms(2); } usbDeviceConnect(); //LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */ sei(); //DBG1(0x01, 0, 0); /* debug output: main loop starts */ while (1) { wdt_reset(); usbPoll(); } }
int main(void) { #if STARTUP_DELAY /* Power ON delay (300ms) */ for (wait=0; wait<150; wait++) { delay_10us(200); // 2ms } #endif #if F_CPU == 12800000 /* RC OSC mode, (D-) */ TCCR0B = 3; /* 1/64 prescaler */ OSCCAL=118; #endif #if 1 /* PD5は USB D-, PD2はmodeジャンパ用 pullup */ /* なお、PD2はクロック出力を無効にした時に入力ポートになります */ PORTD |= ((1<<PD6)|(1<<PD5)|(1<<PD2)|(1<<PD1)|(1<<PD0)); /* all outputs except (USB data, PD2, PD1, PD0) */ DDRD = ~(USBMASK | (1<<PD6)| (1<<PD2)|(1<<PD1)|(1<<PD0)); #else DDRD = ~USBMASK; /* all outputs except USB data */ #endif PORTB = 0xff; /* All pullup */ DDRB = 0; /* PB7-0=in */ usbInit(); sei(); for(;;){ /* main event loop */ usbPoll(); } return 0; }
void main (void) { usbError ret; /* Configure the USB Sense pin - C0 */ TRISC = TRISC & 1; PORTC = 0; OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX, 51); printf("USB Project Debug Output\r\n"); (void)usbInit(); usbSetPowerState(USB_POWER_SELF); usbSetCallback(USB_CB_CONFIG, SetConfigCallback); ret = usbBdSetup(1, USB_ED_OUT, DATA_ENDPOINT_SIZE); if (USB_SUCCESS != ret) { printf("Data BD Setup failed! ret=%d\r\n", ret); return; } ret = usbBdSetup(1, USB_ED_IN, DATA_ENDPOINT_SIZE); if (USB_SUCCESS != ret) { printf("Data BD Setup failed! ret=%d\r\n", ret); return; } while (1) { CheckForUSBAttachDetach(); (void)usbWork(); } }
void main() { uint32 f; /* frequency in hz */ f = 200; systemInit(); usbInit(); /* PWM duty cycle */ T1CC1L = 0x40; T1CC1H = 0x00; /* setup Timer 1, alt location 2 and prescaler 128*/ t1Init(IO_LOC_ALT_2, PRESCALER_128); /* setup Channel 1, compare mode, clear on compare up and peripheral*/ t1ChannelInit(CHANNEL1, COMPARE_MODE, CLR_ON_COMP_UP, PERIPHERAL); /* start Timer 1 by setting it's mode to modulo */ t1Mode(MODE_MODULO); /* set Timer 1 frequency */ setT1Frequency(f); while(1) { boardService(); updateLeds(); usbComService(); } }
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(); } } }
int main( void ) { usbInit(); sei(); init_joy(); for ( ;; ) { usbPoll(); // Don't bother reading joy if previous changes haven't gone out yet. // Forces delay after changes which serves to debounce controller as well. if ( usbInterruptIsReady() ) { read_joy(); // Don't send update unless joystick changed if ( memcmp( report_out, report, sizeof report ) ) { memcpy( report_out, report, sizeof report ); usbSetInterrupt( report_out, sizeof report_out ); toggle_led(); } } } return 0; }
int main(void) { extern uchar usbNewDeviceAddr; uint8_t i; //Reconnect USB usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; while(--i) _delay_ms(2); usbDeviceConnect(); usbInit(); sei(); leds[LED_RED].frequency = LED_ON; LED_init(); for (i=0; i<3; i++) TIMER_delay(250); leds[LED_RED].frequency = LED_OFF; leds[LED_GREEN].frequency = 1; while(1) { if (TIMER_timeout == 0) { if(usbNewDeviceAddr) leds[LED_BLUE].frequency = LED_ON; PORTD ^= (1<<PD7); TIMER_start(1); usbPoll(); LED_poll(); } } }
int main() { message[0] = 'M'; uchar i; DDRB = 1; // PB0 as output wdt_enable(WDTO_1S); // enable 1s watchdog timer usbInit(); usbDeviceDisconnect(); // enforce re-enumeration for(i = 0; i<250; i++) // wait 500 ms { wdt_reset(); // keep the watchdog happy _delay_ms(2); PORTB ^= 1; } usbDeviceConnect(); sei(); // Enable interrupts after re-enumeration while(1) { wdt_reset(); // keep the watchdog happy usbPoll(); } return 0; }
int main(void) { uchar i, j; /* no pullups on USB and ISP pins */ //PORTD = 0; //PORTB = 0; /* all outputs except PD2 = INT0 */ /// LB - different pins on STK500 board //DDRD = ~(1 << 2); // make JTAG pins inputs with pullups SET_JTAG_PULLUPS(); /* output SE0 for USB reset */ /// LB - different pins on STK500 board //DDRB = ~0; j = 0; /* USB Reset by device only required on Watchdog Reset */ while (--j) { i = 0; /* delay >10ms for USB reset */ while (--i) ; } /* all USB and ISP pins inputs */ //DDRB = 0; /// LB - LED pins are different from usbasp to sp duo - conflict: SP duo uses these for JTAG /* all inputs except PC0, PC1 */ //DDRC = 0x03; //PORTC = 0xfe; SET_LED_OUTPUT(); LED_OFF(); /* init timer */ clockInit(); #ifdef UART_DEBUG // init debug uart setupUART(); TransmitString("\r\n\n***\r\nstarting up\r\n"); #endif // USB Re-Enumeration usbDeviceDisconnect(); while(--i){ // fake USB disconnect for > 250 ms wdt_reset(); // if watchdog is active, reset it _delay_ms(1); // library call -- has limited range } usbDeviceConnect(); /* main event loop */ usbInit(); sei(); for (;;) { usbPoll(); } return 0; }
int __attribute__((noreturn)) main(void) { uchar i; wdt_enable(WDTO_1S); /* If you don't use the watchdog, replace the call above with a wdt_disable(). * 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 */ 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(); LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */ sei(); DBG1(0x01, 0, 0); /* debug output: main loop starts */ for(;;) { /* main event loop */ DBG1(0x02, 0, 0); /* debug output: main loop iterates */ wdt_reset(); usbPoll(); } }
int main(void) { wdt_enable(WDTO_1S); // watchdog status is preserved on reset hardwareInit(); usbInit(); usbDeviceDisconnect(); // fake USB disconnect for > 250 ms for( uint8_t i=255; i>0; i-- ) { wdt_reset(); _delay_ms(1); } usbDeviceConnect(); sei(); for(;;) { // main event loop wdt_reset(); usbPoll(); } return 0; }
int main(void) { extern uchar usbNewDeviceAddr; uint8_t i; PORTC |= (1<<PC2); //Reconnect USB usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; while(--i) _delay_ms(2); usbDeviceConnect(); usbInit(); sei(); leds[LED_RED].frequency = LED_ON; LED_init(); for (i=0;i<3;i++) TIMER_delay(250); leds[LED_RED].frequency = LED_OFF; LED_poll(); // wdt_enable(WDTO_60MS); i2c_init(); for(;;) { if(usbNewDeviceAddr) { leds[LED_BLUE].frequency = LED_ON; } wdt_reset(); LED_poll(); usbPoll(); } return 0; }
static void hardwareInit(void) { uchar i; uchar calibrationValue; calibrationValue = eeprom_read_byte(0); /* calibration value from last time */ if (calibrationValue != 0xff) { OSCCAL = calibrationValue; } 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(); wdt_enable(WDTO_1S); /* activate pull-ups for the buttons */ BUTTON_PORT |= _BV(BUTTON1_BIT) | _BV(BUTTON2_BIT); /* initialize LED output */ LED_DDR |= _BV(LED_BIT); LED_ON; /* select clock: 16.5M/1k -> overflow rate = 16.5M/256k = 62.94 Hz (~11ms) */ TCCR1 = 0x0b; }
int main(int argc, char *argv[]) { initPLL(); initGPIO(); vicInit(); uart0Init(CLOCKS_PCLK, UART0_BAUD_RATE); boot_mode_t bootMode = selectBootMode(); bootMode == APP_CON ? led_on(ADMIN_LED) : led_off(ADMIN_LED); LOG_INFO("Initializing USB Stack"); usbUserDriver = bootMode == APP_NET ? usbNetDriver : usbConDriver; usbInit(); if(bootMode == APP_NET) { LOG_INFO("Initializing Ethernet stack"); enc28j60_init(&IODIR, &IOPIN, MACAddress); // Print MAC address enc28j60_get_mac_address((uint8_t*)MACAddress); LOG_INFO("MAC address: %X-%X-%X-%X-%X-%X\n", MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]); } LOG_INFO("Starting USB Stack"); interruptsEnable(); usbConnect(); LOG_INFO("Entering main loop"); bootMode == APP_NET ? appnet_loop() : appcon_loop(); return 0; }
/** Configures the USB and radio communication then calls the processBytesFromUsb and * processBytesFromRadio functions. **/ void main() { // required by wixel api: // http://pololu.github.io/wixel-sdk/group__libraries.html systemInit(); usbInit(); radioLinkInit(); // wait for a wireless pairing // between two wixels // blink yellow LED while connection is being established while(!radioLinkConnected()) { yellowLedOn ^= 1; updateLeds(); delayMs(DELAY_MS); } // turn off LED yellowLedOn = 0; // process bytes while(1) { boardService(); updateLeds(); usbComService(); processBytesFromUsb(); processBytesFromRadio(); } }
int __attribute__((noreturn)) main(void) { uchar i; 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(); 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(); sei(); DDRB |= _BV(PB0); for(;;){ /* main event loop */ wdt_reset(); usbPoll(); if (eeprom_read_byte(10) == 1) { PORTB |= _BV(PB0); } else { PORTB &= ~_BV(PB0); } } }
void usb_init(void) { #ifdef USB_NET_SUPPORT usb_net_init(); #endif #define USB_DDR_CONFIG(pin) DDR_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN)) #define USB_PORT_CONFIG(pin) PORT_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN)) USB_DDR_CONFIG(USB_DMINUS); USB_PORT_CONFIG(USB_DMINUS); #undef USB_DDR_CONFIG #undef USB_PORT_CONFIG uint8_t i; /* Reenummerate the device */ usbDeviceDisconnect(); for(i = 0; i < 20; i++){ /* 300 ms disconnect */ _delay_ms(15); wdt_kick(); } usbDeviceConnect(); /* USB Initialize */ usbInit(); }
int main(void) { uchar i; wdt_enable(WDTO_1S); wdt_disable(); usbInit(); usbDeviceDisconnect(); i = 0; while(--i){ wdt_reset(); _delay_ms(1); } _delay_ms(250); usbDeviceConnect(); sei(); for(;;){ //wdt_reset(); usbPoll(); } return 0; }
void configure (void) { /* usb stuff. make the host re-enumerate our device */ cli (); usbDeviceDisconnect (); /* configure timer 2 for calling usbPoll() */ TIMSK2 = _BV (TOIE2); /* overflow interrupt enabled */ TCCR2B = _BV (CS02) | _BV (CS01) | _BV (CS00); /* set prescaler to 1024, timer starts */ /* end of usb stuff */ /* display configuration */ d_status = &display[0]; display[LCD_DISP_LENGTH] = '\0'; d_content = &display[LCD_DISP_LENGTH + 1]; display[LCD_DISP_LENGTH * 2 + 1] = '\0'; lcd_init (LCD_DISP_ON); /* end display configuration */ /* temperature sensors */ t_sensors_count = search_sensors (); if (t_sensors_count) { have_ts = 1; d_status_update ("Found %d DS18B20", t_sensors_count); d_update (); } /* end if temperature sensors setup */ /* twi/accelerometer configuration */ i2c_init (); /* don't hurry! */ _delay_ms (1000); if (!lis_initialize (0, 1, 0, 1)) { have_ac = 1; d_content_update ("Found LIS302DL"); d_update (); } /* end of accelerometer configuration */ _delay_ms (1500); /* configure timer 0 for button state detection */ TIMSK0 = _BV (TOIE0); /* enable overflow interrupt */ TCCR0B = _BV (CS02) | _BV (CS00); /* set prescaler to 1024, timer starts */ PORTD |= _BV (PD3) | _BV (PD4); /* pullup for buttons */ /* end if button detection setup */ /* ADC configuration goes here */ ADMUX = _BV (REFS0); ADCSRA = _BV (ADEN) | _BV (ADPS2) | _BV (ADPS1) | _BV (ADPS0); PORTC |= _BV (PC0) | _BV (PC1); /* end of ADC configuration */ /* clear the display */ d_content_update (" "); d_status_update (" "); d_update (); usbDeviceConnect (); usbInit (); sei (); }