Beispiel #1
0
int
main(void)
{
  wdt_disable();
  clock_prescale_set(clock_div_1);

  LED_ON_DDR  |= _BV( LED_ON_PIN );
  LED_ON_PORT |= _BV( LED_ON_PIN );

  led_init();
  LED_ON();

  spi_init();

//  eeprom_factory_reset("xx");
  eeprom_init();

// Setup OneWire and make a full search at the beginning (takes some time)
#ifdef HAS_ONEWIRE
  i2c_init();
	onewire_Init();
	onewire_FullSearch();
#endif

  // Setup the timers. Are needed for watchdog-reset
#if defined (HAS_IRRX) || defined (HAS_IRTX)
  ir_init();
  // IR uses highspeed TIMER0 for sampling 
  OCR0A  = 1;                              // Timer0: 0.008s = 8MHz/256/2   == 15625Hz
#else
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
#endif
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8


  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel |= DISPLAY_RFROUTER;
#endif

  checkFrequency(); 
  LED_OFF();

  sei();

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_RWE
    rf_rwe_task();
#endif
#if defined(HAS_IRRX) || defined(HAS_IRTX)
    ir_task();
#endif
#ifdef HAS_MBUS
    rf_mbus_task();
#endif
  }

}
Beispiel #2
0
void main(void)
{		
	init();
	PSC_Init(0x00, MAX_PWM); 
	uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUDRATE, F_CPU));
	
	while(1)
	{
		/* Communicate with Big Brother :-) */
		communication();
		
		/* Sampling */
		if (Flag_IT_timer0)
		{	
			if ( !(timer % 100) )
			{
				/* This led shows that program is running */
				GPIO_TOGGLE(WD_LED);
			}
			
			if ( !(timer % 10) )
			{
				GPIO_TOGGLE(LED);
				
				/* Read meashured speed from Timer2 */
				Omega_meas = TCNT1 * 10;
				TCNT1      = 0;
					
				/* PID controller */
				pid_output = update_pid(reference_val.omega - Omega_meas, Omega_meas);
				Command    = ((int32_t)pid_output * 131) >> 10;
					
				/* Update immediate vals */
				instant_val.time       = timer;
				instant_val.omega      = Omega_meas;
				instant_val.error      = reference_val.omega - Omega_meas;
				instant_val.pid_output = pid_output;
				instant_val.command	   = Command;
			}
			
			/* direction management : extract sign and absolute value */
			if (Command > (int16_t)(0))
			{
				direction = 0;
				OmegaTe   = Command;
			} else {
				direction = 1;
				OmegaTe   = (~Command) + 1;
			}
			
			if (OmegaTe > K_scal)
			{
			// ------------------------ V/f law --------------------------
				amplitude = controlVF(OmegaTe);
				
			// ------------------ natural PWN algorithm ------------------
				PWM0 = duty_cycle(theta1,amplitude);
				PWM1 = duty_cycle(theta2,amplitude);
				PWM2 = duty_cycle(theta3,amplitude);
			} else {
				PWM0 = 0;
				PWM1 = 0;
				PWM2 = 0;
			}
			
			// -------- load the PSCs with the new duty cycles -----------
			PSC0_Load(PWM0, PWM0 + DeadTime);
			if (!direction)
			{
				PSC1_Load(PWM1, PWM1 + DeadTime);
				PSC2_Load(PWM2, PWM2 + DeadTime);
			} else {
				PSC2_Load(PWM1, PWM1 + DeadTime);
				PSC1_Load(PWM2, PWM2 + DeadTime);
			}
			
			// 3 integrators for the evolution of the angles
			theta1 = (K_scal * theta1 + OmegaTe) / K_scal;
			theta2 = theta1 + 160;
			theta3 = theta1 + 320;
			
			if (theta1>=MAX_THETAx4) theta1 -= MAX_THETAx4;
			if (theta2>=MAX_THETAx4) theta2 -= MAX_THETAx4;
			if (theta3>=MAX_THETAx4) theta3 -= MAX_THETAx4;
			
			Flag_IT_timer0 = 0;
		}
	}
Beispiel #3
0
int
main(void)
{
  wdt_disable();

#ifdef CSMV4

  LED_ON_DDR  |= _BV( LED_ON_PIN );
  LED_ON_PORT |= _BV( LED_ON_PIN );

#endif

  led_init();
  LED_ON();

  spi_init();

//  eeprom_factory_reset("xx");
  eeprom_init();

//  led_mode = 2;

  // if we had been restarted by watchdog check the REQ BootLoader byte in the
  // EEPROM ...
//  if(bit_is_set(MCUSR,WDRF) && eeprom_read_byte(EE_REQBL)) {
//    eeprom_write_byte( EE_REQBL, 0 ); // clear flag
//    start_bootloader();
//  }

  // Setup the timers. Are needed for watchdog-reset
#ifdef HAS_IRRX
  ir_init();
  // IR uses highspeed TIMER0 for sampling
  OCR0A  = 1;                              // Timer0: 0.008s = 8MHz/256/2   == 15625Hz
#else
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
#endif
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  clock_prescale_set(clock_div_1);

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

#ifdef HAS_DOGM
  dogm_init();
#endif

  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel |= DISPLAY_RFROUTER;
#endif

#ifdef HAS_DOGM
  display_channel |= DISPLAY_DOGM;
#endif

  LED_OFF();

  sei();

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_IRRX
    ir_task();
#endif
  }

}
Beispiel #4
0
int
main(void)
{
  wdt_disable();

  led_init();
  LED_ON();

  MARK433_PORT |= _BV( MARK433_BIT );
  MARK915_PORT |= _BV( MARK915_BIT );

  spi_init();

//  eeprom_factory_reset("xx");
  eeprom_init();

//  led_mode = 2;

  // if we had been restarted by watchdog check the REQ BootLoader byte in the
  // EEPROM ...
//  if(bit_is_set(MCUSR,WDRF) && eeprom_read_byte(EE_REQBL)) {
//    eeprom_write_byte( EE_REQBL, 0 ); // clear flag
//    start_bootloader();
//  }

  // Setup the timers. Are needed for watchdog-reset
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  clock_prescale_set(clock_div_1);

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

#ifdef HAS_STACKING
  stacking_initialize();

  // make sure i2c is inactive
  DDRC  &= 0xfc;
  PORTC &= 0xfc;

#endif

  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel |= DISPLAY_RFROUTER;
#endif

  LED_OFF();
  checkFrequency(); 

  sei();

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_STACKING
  stacking_task();
#endif
#ifdef HAS_MBUS
    rf_mbus_task();
#endif

  }

}
Beispiel #5
0
int
main(void)
{
//  wdt_disable();

    clock_prescale_set(clock_div_1);

    MARK433_PORT |= _BV( MARK433_BIT ); // Pull 433MHz marker
    MARK915_PORT |= _BV( MARK915_BIT ); // Pull 915MHz marker

    led_init();

    spi_init();

    // Setup the timers. Are needed for watchdog-reset
    OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
    TCCR0B = _BV(CS02);
    TCCR0A = _BV(WGM01);
    TIMSK0 = _BV(OCIE0A);

    TCCR1A = 0;
    TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

    //eeprom_factory_reset("xx");
    eeprom_init();

    MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
    wdt_enable(WDTO_2S);

    //uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );
    uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

    fht_init();
    tx_init();
    input_handle_func = analyze_ttydata;

    display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
    rf_router_init();
    display_channel |= DISPLAY_RFROUTER;
#endif

    checkFrequency();
    sei();

    for(;;) {
        uart_task();
        RfAnalyze_Task();
        Minute_Task();
#ifdef HAS_FASTRF
        FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
        rf_router_task();
#endif
#ifdef HAS_ASKSIN
        rf_asksin_task();
#endif
#ifdef HAS_MORITZ
        rf_moritz_task();
#endif
#ifdef HAS_RWE
        rf_rwe_task();
#endif
#ifdef HAS_RFNATIVE
        native_task();
#endif
#ifdef HAS_KOPP_FC
        kopp_fc_task();
#endif
#ifdef HAS_MBUS
        rf_mbus_task();
#endif
#ifdef HAS_ZWAVE
        rf_zwave_task();
#endif
    }

}
Beispiel #6
0
int
main(void)
{
  wdt_disable();

  // un-reset ethernet
  ENC28J60_RESET_DDR  |= _BV( ENC28J60_RESET_BIT );
  ENC28J60_RESET_PORT |= _BV( ENC28J60_RESET_BIT );

  MARK433_PORT |= _BV( MARK433_BIT ); // Pull 433MHz marker
  MARK915_PORT |= _BV( MARK915_BIT ); // Pull 915MHz marker
  
  led_init();
  LED_ON();

  spi_init();

  eeprom_init();
  
  // Reset the "Request Bootloader" flag in EEPROM, to avoid a permanent loop
  eeprom_update_byte( EE_REQBL, 0);

// Setup OneWire and make a full search at the beginning (takes some time)
#ifdef HAS_ONEWIRE
  i2c_init();
  onewire_Init();
  onewire_FullSearch();
#endif

  // Setup the timers. Are needed for watchdog-reset

#if defined (HAS_IRRX) || defined (HAS_IRTX)
  ir_init();
  // IR uses highspeed TIMER0 for sampling 
  OCR0A  = 1;                              // Timer0: 0.008s = 8MHz/256/2   == 15625Hz Fac: 125
#else
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
#endif

  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  clock_prescale_set(clock_div_1);

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;
#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel = (DISPLAY_USB|DISPLAY_RFROUTER);
#else
  display_channel = DISPLAY_USB;
#endif

#ifdef HAS_VZ
  vz_init();
#endif

  ethernet_init();
    
  LED_OFF();

#ifdef HAS_DMX
#ifdef DMX_CHANNELS
  dmx_initialize(DMX_CHANNELS);
#else
  dmx_initialize(16);
#endif
#endif

#ifdef HAS_HM485
  hm485_initialize();
#endif

#ifdef HAS_HELIOS
  helios_initialize();
#endif

#ifdef HAS_CUNOTTY
rf_cunotty_init();
#endif

  sei();

#ifdef HAS_DMX
  dmx_start();
#endif

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_CUNOTTY
	rf_cunotty_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_IRRX
    ir_task();
#endif
#ifdef HAS_ETHERNET
    Ethernet_Task();
#endif
#ifdef HAS_VZ
    vz_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_HM485
    hm485_task();
#endif    
#ifdef HAS_HELIOS
    helios_task();
#endif    
  }

}
Beispiel #7
0
int main(void)
{

    char wdrst = 0;
    uint8_t mcusr;

    mcusr = MCUSR;
    if ( mcusr & _BV(WDRF) ) {
        wdrst = 1;
    }
    MCUSR = 0;
    wdt_disable();

    cli();
#ifdef LED1
    LED1 = 1;
#endif
    uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(115200,F_CPU));
    stdout = &mystdout;
    sei();

    if ( wdrst ) {
        kputs("\n***WATCHDOG RESET***\n");
    }

    wdt_enable(WDTO_8S);
    wdt_reset();
    kputs("\nSetting DDR registers\n");
    DDRA = DDRA_SETTING;
    DDRB = DDRB_SETTING;
    DDRC = DDRC_SETTING;
    DDRD = DDRD_SETTING;
    DIDR0 = 0;
    DIDR1 = 0;
    /*
    kputs("Hi i2c\n");
    i2c_init();
    kputs("Hi humid\n");
    humid_init();
    humid_sleep();
    kputs("Hi accel\n");
    accel_init();
    accel_sleep();
    kputs("Hi light\n");
    light_init();
    light_sleep();
    kputs("Hi PIR\n");
    pir_wake();
    kputs("Hi RTC\n");
    rtctimer_init();
    kputs("Go away RTC\n");
    DDRC &= 0x3F;
    PORTC |= 0xC0;

    kputs("Go to sleep\n");
    uart_flush();
    ACSR = (1<<ACD);
    LED1 = LED2 = 0;
    cli();
    wdt_disable();
    SMCR = (2<<SM0) | (1<<SE);	 //Enable Power-Down Mode
    while(1) {
    	asm volatile ("sleep"); // __sleep(); // Go to sleep
    }
    */
    kputs("Initializing PCINT\n");
    pcint_init();

    kputs("Initializing Reports\n");
    report_init();

    board_init_devices();

    kputs("Initializing wireless mote\n");
    wdt_reset();
    datalink_init();


    /*
    PIR_VCC = 1;
    while(1) {
    	if(PIR_OUT_PIN) {
    		kputs("ON\n");
    	} else {
    		kputs("OFF\n");
    	}
    	_delay_ms(50);
    }*/

    kputs("Powering down all devices\n");
    board_power_down_devices();

    kputs("Init logic subsystem\n");
    logic_init();

    /*
    kputs("Turning on always-on devices\n");
    pir_wake();
    accel_wake();
    */

    board_setup_reporting();

    kputs("Starting RTC clock\n");
    rtctimer_init();
    rtctimer_set_periodic_alarm(report_interval_needed(),&rtc_timer_cb);
    wdt_reset();
    wdt_disable();
    while(1)
    {
        //wdt_enable(WDTO_2S);
        //wdt_reset();
        pcint_check();
        rtctimer_check_alarm();
        wdt_disable();

        datalink_tick();

#ifdef USE_PN532
        rtc_timer_cb(); // causes monitor list to be run
#else
#if defined LOW_POWER // do we have a RTC clock and battery-powered
        avr_sleep();
#else
        avr_doze();
#endif
#endif
    }
}
int main(void)
{
	int i;
	int count = 0;
	
	DDRB = 0;
	DDRC = 0;
	DDRE = 0;
	
	// Enable the pullup on RESET pin.
	#if defined(__AVR_AT90PWM316__)
	PORTE = (1<<PINE0);
	PORTE &= ~(1<<PINE0);
	#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
	PORTC = (1<<PINC6);
	PORTC &= ~(1<<PINC6);
	#else
	#warning "Didn't enable reset pin pullup"
	#endif
	
	// Setup all of port C as inputs, except for pin C5
	SETUP_DEBUG_PINS();
	
	// Set up the ADC single conversion pin.
	DDRC  &= ~(1<<PINC6);
	PORTC &= ~(1<<PINC6);
	
	// Disable all the ADC digital inputs.
	DIDR1 = 0xFF;
	DIDR0 = 0xFF & ~(1<<ADC1D);
	
	// populate the buffer with known values
	ringBuffer_initialize(&txbuffer,txbuffer_storage,TXBUFFER_LEN);
	ringBuffer_initialize(&adcbuffer,adcbuffer_storage,BUFFER_LEN);
	ringBuffer_initialize(&rxbuffer,rxbuffer_storage,RXBUFFER_LEN);
	
	// Populate the ADC read schedule with the mux indices that you want.
	adc_mux_schedule[0] = 2;
	adc_mux_schedule[1] = 10;
	adc_mux_schedule[2] = 6;
	adc_mux_schedule[3] = 3;
	
	
	uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU), &rxbuffer, &txbuffer);
	//uart_config_default_stdio();
	// Translate those indices and the mask specifying which MUXes to turn on,
	// to an encoded mux schedule that the ADC understands.
	adc_encode_muxSchedule(adc_mux_schedule, SCHEDULE_LEN);
	
	
	adc_init(ADC_MODE_MANUAL, &adcbuffer, adc_mux_schedule, SCHEDULE_LEN);
	timer0_init();
	sei();
	uart_puts_P("\f\r\n\r\nADC and UART Demo. Commands:\n"
				"b      Begin 4 channel read bursts at CLK/16K\n"
				"e      End reading.\n"
				"s      Single conversion.\n");
	
	DEBUG_PIN1_OFF();
	while(1)
	{
		do
		{
			i = uart_getc();
		} while (i == UART_NO_DATA);
		DEBUG_PIN1_ON();
		if(i == 'b'){
			uart_puts_P("Begin.\n");
			start_timer0();
		}
		else if(i == 'e'){
			stop_timer0();
			_delay_us(100);
			uart_puts_P("End.\n");
		}
		else if(i == 's'){
			uart_puts_P("ADC");
			uart_put_hex8(count);
			uart_puts_P(": ");
			i = adc_single_conversion(count);
			uart_put_hex8((i >> 8) & 0xFF);
			uart_put_hex8(i & 0xFF);
			uart_putc('\n');
			count = (count + 1) & 0xF;
			if(count == 11)
			{
				count = 13;
			}
		}
		else{
Beispiel #9
0
int
main(void)
{
  wdt_disable();
#ifdef HAS_16MHZ_CLOCK
  /* set clock to 16MHz/2 = 8Mhz */
  clock_prescale_set(clock_div_2);
#endif

//  LED_ON_DDR  |= _BV( LED_ON_PIN );
//  LED_ON_PORT |= _BV( LED_ON_PIN );

  led_init();
  LED_ON();

  spi_init();
 // init_adcw();

  //eeprom_factory_reset("xx");
  eeprom_init();

  // Setup the timers. Are needed for watchdog-reset
  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8


  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog
  wdt_enable(WDTO_2S);

#ifdef HAS_16MHZ_CLOCK
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
#else
  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );
#endif
  fht_init();
  tx_init();
  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef HAS_RF_ROUTER
  rf_router_init();
  display_channel |= DISPLAY_RFROUTER;
#endif

  checkFrequency(); 
  LED_OFF();

  sei();

  for(;;) {
    uart_task();
    RfAnalyze_Task();
    Minute_Task();
#ifdef HAS_FASTRF
    FastRF_Task();
#endif
#ifdef HAS_RF_ROUTER
    rf_router_task();
#endif
#ifdef HAS_ASKSIN
    rf_asksin_task();
#endif
#ifdef HAS_MORITZ
    rf_moritz_task();
#endif
#ifdef HAS_RWE
    rf_rwe_task();
#endif
#ifdef HAS_RFNATIVE
    native_task();
#endif
#ifdef HAS_KOPP_FC
    kopp_fc_task();
#endif
#ifdef HAS_MBUS
    rf_mbus_task();
#endif
  }

}
Beispiel #10
0
int
main(void)
{

  led_init();

#ifdef LED_RGB
  led_off(LED_CHANNEL_GREEN);
  led_off(LED_CHANNEL_RED);
  led_off(LED_CHANNEL_BLUE);
#else
  LED_ON();
#endif


  spi_init();


  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  clock_prescale_set(clock_div_1);

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef LED_RGB
  my_delay_ms(200);
  led_on(LED_CHANNEL_RED);
  my_delay_ms(200);
  led_off(LED_CHANNEL_RED);
  led_on(LED_CHANNEL_GREEN);
  my_delay_ms(200);
  led_off(LED_CHANNEL_GREEN);
  led_on(LED_CHANNEL_BLUE);
  my_delay_ms(200);
  led_off(LED_CHANNEL_BLUE);
#else
  LED_OFF();
#endif

  sei();

  /* start moritz function */
  moritz_func("Zr\n");
  for(;;) {
	led_process(ticks);

    uart_task();
    Minute_Task();
    rf_asksin_task();
    rf_moritz_task();
    if (rf_moritz_data_available()) {
        DC('Z');
        uint8_t *rf_data = (uint8_t*) &max_data;
        for (uint8_t i=0; i<=*rf_data; i++) {
        	DH2( *rf_data++ );
        }
        DNL();
        DS("length: ");
        DU(max_data.length, 2);
        DNL();
        DS("msg count: ");
        DU(max_data.message_count, 2);
        DNL();
        DS("msg type: ");
        DU(max_data.message_type, 2);
        DNL();
    }
  }

}