static void switch_control_test_fsw_func(switch_control_t *sc)
{
    /* Turn light on when switch state goes low. */
    static uint32_t left_toggle, right_toggle;
    uint32_t data = *((uint32_t*)sc->data);
    switch (data) {
        case 1:
            if (switch_control_get_state(sc)) {
                left_toggle ^= 0x1;
                switch_control_set_state(sc,0x0);
            }
            break;
        case 2:
            if (switch_control_get_state(sc)) {
                right_toggle ^= 0x1;
                switch_control_set_state(sc,0x0);
            }
            break;
    }
    if (left_toggle) {
        led1_reset();
        led3_set();
    } else {
        led1_set();
        led3_reset();
    }
    if (right_toggle) {
        led5_reset();
        led7_set();
    } else {
        led5_set();
        led7_reset();
    }
}
static void switch_control_test_func(switch_control_t *sc)
{
    /* Turn light on when switch state goes low. */
    uint32_t data = *((uint32_t*)sc->data);
    switch (data) {
        case 1:
            if (!switch_control_get_state(sc)) {
                led1_set();
            } else {
                led1_reset();
            }
            break;
        case 3:
            if (!switch_control_get_state(sc)) {
                led3_set();
            } else {
                led3_reset();
            }
            break;
        case 5:
            if (!switch_control_get_state(sc)) {
                led5_set();
            } else {
                led5_reset();
            }
            break;
        case 7:
            if (!switch_control_get_state(sc)) {
                led7_set();
            } else {
                led7_reset();
            }
            break;
    }
}
Пример #3
0
void key1_event (void)      // кнопка T-
{
  if (curent_mode==SETUP_MODE) 
  {
    set_temp--;  // в режиме установки температуры убавляет значение 
    if (set_temp<1)set_temp=1;
    EEPROM_write(EEPROM_ADDR,set_temp); // запоминаем установленное значение
  }
  if (curent_mode==IDLE_MODE)curent_mode=SHOW_MODE;
    else curent_mode=SETUP_MODE;
  sec_counter=0;
  led1_set(1); // зажигаем светодиод. тухнет он по времени sec_counter
}
Пример #4
0
void led_status_update(void)
{
   if (synth_control_get_recordState()) {
      led1_set();
   } else {
      led1_reset();
   }
   if (synth_control_get_schedulerState()) {
       led3_set();
   } else {
       led3_reset();
   }
   if (synth_control_get_feedbackState()) {
       led5_set();
   } else {
       led5_reset();
   }
}
Пример #5
0
void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1

CLKPR=0x80; 
CLKPR=0x00;


// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=Out Func5=In Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTA=0x00;
DDRA=0x00;
DDRA_DDA7=1;

// Port B initialization
// Func3=In Func2=In Func1=In Func0=In 
// State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 4000,000 kHz
// Mode: Fast PWM top=FFh
// OC0A output: Disconnected
// OC0B output: Inverted PWM
TCCR0A=0x23;
TCCR0B=0x01;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-11: Off
MCUCR=0x00;
GIMSK=0x00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x01;
// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
ADCSRB=0x00;

 
SPI_init(); 
ADC_init();

unsigned char key0_counter=50;
unsigned char key1_counter=50;
unsigned char key0_state=KEY_OFF;
unsigned char key1_state=KEY_OFF;

// Global enable interrupts
SREG_I=1;
set_temp=EEPROM_read(EEPROM_ADDR);
FAN_SPEED_CONTROL=FAN_SPEED_OFF;
f_sr_temp_curent=40+TEMP_OFFSET;
ch_temp=40;
while (1)  
    {
//-----------проверяем кнопку KEY_0 PINB2-----------------
      if (PINB_PINB2) key0_counter--;
        else key0_counter++;
      if (key0_counter>KEY_TIME_OUT) // кнопка нажата 
      { 
        key0_counter=KEY_TIME_OUT;
        if (key0_state==KEY_OFF) 
        {
          key0_state=KEY_ON;
          key0_event(); // при детектировании нажатия кнопки- фиксируем событие
        }
      }
      if (key0_counter<1) // кнопка отжата 
      { 
        key0_counter=1;
        if (key0_state==KEY_ON) key0_state=KEY_OFF;
      }          
//----------------------------------------------------------------
//-----------проверяем кнопку KEY_1 PINB1-----------------
      if (PINB_PINB1) key1_counter--;
        else key1_counter++;
      if (key1_counter>KEY_TIME_OUT) // кнопка нажата 
      { 
        key1_counter=KEY_TIME_OUT;
        if (key1_state==KEY_OFF) 
        {
          key1_state=KEY_ON;
          key1_event(); // при детектировании нажатия кнопки- фиксируем событие
        }
      }
      if (key1_counter<1) // кнопка отжата 
      { 
        key1_counter=1;
        if (key1_state==KEY_ON) key1_state=KEY_OFF;
      }          
//---------------------------------------------------------------- 
//------управление дисплеем в разных режимах и  переключение режимов по времени---      
    switch (curent_mode) 
    {
      case    IDLE_MODE:                     
        Display_off();
      //  led0_set(triger);
        break;
      case    SETUP_MODE:                    
        if (sec_counter>SETUP_MODE_TIMEOUT) curent_mode=SHOW_MODE;
        if (triger)Display_on(); // мигаем дисплем
          else Display_off();
        Display(set_temp);      // на десплее настроенная темпеература
       // led0_set(0);
        break;
      case    SHOW_MODE:  
        Display_on();
        if (sec_counter>SHOW_MODE_TIMEOUT) curent_mode=IDLE_MODE;
        Display(ch_temp); // на десплее текущая темпеература
       // led0_set(1);
        break;        
    }
//---------------------------------------------------------------------------
 
// управление вентилятором в зависимости от текущей температуры и заданной температуры
    switch (FAN_SPEED_CONTROL) 
    {
      case    FAN_SPEED_OFF:
        //if (ch_temp>42)FAN_SPEED_CONTROL=FAN_SPEED_SLOW;//(set_temp+TEMP_OFF+FAN_MODE_OFFSET))//например Ттек>Туст+(-5)+1
        if (ch_temp>=(set_temp+TEMP_OFF+FAN_MODE_OFFSET))//например Ттек>Туст+(-5)+1
          FAN_SPEED_CONTROL=FAN_SPEED_SLOW;
          led0_set(0);led1_set(0);
        break; 
        
      case    FAN_SPEED_SLOW:
        if (ch_temp<=(set_temp+TEMP_OFF-FAN_MODE_OFFSET))
          FAN_SPEED_CONTROL=FAN_SPEED_OFF;
        if (ch_temp>=(set_temp+TEMP_SLOW+FAN_MODE_OFFSET))
          FAN_SPEED_CONTROL=FAN_SPEED_MEDI;
        led0_set(1);led1_set(0);
        break;
         
      case    FAN_SPEED_MEDI:
        if (ch_temp<=(set_temp+TEMP_SLOW-FAN_MODE_OFFSET))
          FAN_SPEED_CONTROL=FAN_SPEED_SLOW;
        if (ch_temp>=(set_temp+TEMP_MEDI+FAN_MODE_OFFSET))
          FAN_SPEED_CONTROL=FAN_SPEED_FAST;
        led0_set(0);led1_set(1);
        break;
        
      case    FAN_SPEED_FAST:
        if (ch_temp<=(set_temp+TEMP_MEDI-FAN_MODE_OFFSET))
          FAN_SPEED_CONTROL=FAN_SPEED_MEDI;
        led0_set(1);led1_set(1);
        break;        
    }
//-------------------------------------------------------------------    

    temp_chek();     
 // if (sec_counter==1) led1_set(0); // после нажатия кнопки через пол секунды гасим диод


    }
}
Пример #6
0
int main(void)
{
    portBASE_TYPE ret = 0;

    unsigned int v=0;

    ddk_init();

    // call HW function tests and FPGA ROM programming. This will program the FPGA bitstream
    // into flash ROM if FPGA is uninitialized.
    hw_test_main();

    led1_clr();
    led2_clr();
    led3_clr();
    led4_clr();


    // error
    while(g_test_done != 1) {
        led1_set();
        led2_set();
        led3_set();
        led4_set();
        ddk_delay(50000);
        led1_clr();
        led2_clr();
        led3_clr();
        led4_clr();
        ddk_delay(50000);
    }


    puts("[*] init done.");

    ret = xTaskCreate( vBlinkTask,
        _STR "BLINK",
        mainBASIC_BLINK_STACK_SIZE,
        ( void * ) NULL,
        tskIDLE_PRIORITY,
        &task_handles[TASK_BLINK_MAIN]
        );

    if(ret != pdTRUE)
    for(;;);

/*
    ret = xTaskCreate( vUART0Task,
        _STR "UART0",
        mainBASIC_UART0_STACK_SIZE,
        ( void * ) NULL,
        tskIDLE_PRIORITY,
        &task_handles[TASK_UART0_MAIN]
        );

    if(ret != pdTRUE)
    for(;;);
*/

    ret = xTaskCreate( vUART1Task,
        _STR "UART1",
        mainBASIC_UART1_STACK_SIZE,
        ( void * ) NULL,
        tskIDLE_PRIORITY,
        &task_handles[TASK_UART1_MAIN]
        );

    if(ret != pdTRUE)
    for(;;);

#ifdef WITH_UART2
    ret = xTaskCreate( vUART2Task,
        _STR "UART2",
        mainBASIC_UART2_STACK_SIZE,
        ( void * ) NULL,
        tskIDLE_PRIORITY,
        &task_handles[TASK_UART2_MAIN]
        );

    if(ret != pdTRUE)
    for(;;);
#endif

#ifdef WITH_UART3
    ret = xTaskCreate( vUART3Task,
        _STR "UART3",
        mainBASIC_UART3_STACK_SIZE,
        ( void * ) NULL,
        tskIDLE_PRIORITY,
        &task_handles[TASK_UART3_MAIN]
        );

    if(ret != pdTRUE)
    for(;;);
#endif


   ret = xTaskCreate( vCLITask,
      _STR"CLI",
      mainBASIC_CLI_STACK_SIZE,
      ( void * ) NULL,
      tskIDLE_PRIORITY,
      &task_handles[TASK_CLI_MAIN] );


   if(ret != pdTRUE)
      for(;;);


    vTaskStartScheduler();

    while (1) {
      // power down can go here if supported
      v++;
    }

    return 0;
}