コード例 #1
0
ファイル: assign65.c プロジェクト: iWuzHere/SYSC2003-project
void clock(void) {
  ++time.deci_seconds;
  next_hour(&time);
	
  if (stopwatch_on) {
    ++stopwatch.deci_seconds;
	next_hour(&stopwatch);
  }
  
  if(time.deci_seconds % 10 == 0) {
    ATD0CTL5 = 0x86;  //Check the temp, yo.
  }
  
  // Stop beeping, if necessary.
  if (time.deci_seconds == end_beep_deciseconds) {
    end_beep_deciseconds = MAX_DECISECONDS;
	CLRMSK(PORTK, BUZZER_MASK);
  }
  
  // Activate the alarm beep if appropriate.
  if (time_equals(&time, &alarm)) alarm_on = true;
  
  // Activate the timer beep if necessary.
  if (time_equals(&time, &timer)) {
    timer_on = true;
	timer.hours = MAX_HOURS;
  }
  
  if (alarm_on ) {
    if (time.deci_seconds % 5 == 0) {
      TOGGLEMASK(PORTK, BUZZER_MASK);
	}
  } if (timer_on) {
    if (time.deci_seconds % 3) {
      TOGGLEMASK(PORTK, BUZZER_MASK);
	}
  }
  
  TC0 += TC0_TICK_LENGTH; // Prepare for a new tick.
}
コード例 #2
0
ファイル: main.c プロジェクト: swilmet/ingi1113-projet-pic
static void on_timeout (void)
{
    if (_mode != TIME_CONFIG)
        increment_time (&_time);

    if (_mode != NORMAL)
    {
        _alarm_on = 0;
        led_off ();
        return;
    }

    /* Normal mode */

    print_time ();

    // Alarm triggered?
    if (_alarm_set && time_equals (&_time, &_alarm))
    {
        _alarm_on = 1;
        _alarm_duration = 0;
    }

    if (_alarm_on)
    {
        // Shut down the alarm
        if (ALARM_MAX_DURATION <= _alarm_duration)
        {
            _alarm_on = 0;
            led_off ();
        }

        // Continue the alarm
        else
        {
            _alarm_duration++;
            led_toggle ();
        }
    }
}