コード例 #1
0
ファイル: main.c プロジェクト: N5QM/FireFlyJar
// power saving steps
void powerSaving(void)
{
    // disable adc
    power_adc_disable();
    
    // disable universal serial interface
    power_usi_disable();
}
コード例 #2
0
void main() {
  ADCSRA = 0; // DIE, ADC!!! DIE!!!
  ACSR = _BV(ACD); // Turn off analog comparator - but was it ever on anyway?
  power_adc_disable();
  power_usi_disable();
  power_timer1_disable();
  TCCR0A = _BV(COM0A0) | _BV(WGM01); // mode 2 - CTC, toggle OC0A
  TCCR0B = _BV(CS00); // prescale = 1 (none)
  OCR0A = 0; // as fast as possible
  DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2); // all our pins are output.
  PORTB = 0; // Initialize all pins low.

  // And we're done.
  while(1);

}
コード例 #3
0
ファイル: main.c プロジェクト: mibe/electronics
/*
 * Setup the system.
 */
void setup(void)
{
	// Set clock prescaler to run at 31.25 kHz (prescaler of 256)
	CLKPR = _BV(CLKPCE);
	CLKPR = _BV(CLKPS3);
	
	// Setup I/O ports: PB4 == Debug; PB0 == PWM for piezo (OC0A)
	DDRB |= _BV(PB4) | _BV(PB0);
	// Enable pull-up on button and unused pins
	PORTB |= _BV(BTN) | _BV(PB1) | _BV(PB3);
	
	// Disable unused modules to save more battery power
	power_usi_disable();
	power_adc_disable();
	
	// Enable interrupts
	sei();
}
コード例 #4
0
void setup() {
	initDebug();
	setupChangeModePin();
	if (isCycleVoltageModeActive()) {
		cycleVoltageMode = true;
		sk720Mode = SK720Mode_off;
		debugln("Cycle mode activated");debug("Switching states every ");debugNum(CYCLE_MODE_DELAY_MS);debugln("ms.");
	} else {
		debugln("Normal mode activated");
		setupLEDPins();
		setuptInitialLedStates();
		setupWatchdogTimer();
		setupPinChangeInterrupts();
	}
	setupFastPWM();
	power_adc_disable();
	power_usi_disable();
}
コード例 #5
0
void main() {
  // power management setup
  clock_prescale_set(clock_div_16); // 500 kHz clock
  ADCSRA = 0; // DIE, ADC! DIE!!!
  power_adc_disable();
  power_usi_disable();
  power_timer1_disable();
  ACSR = _BV(ACD);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // millisecond timer setup
  TCCR0A = _BV(WGM01); // mode 2 - CTC
  TCCR0B = _BV(CS01) | _BV(CS00); // prescale = 64
  TIMSK0 = _BV(OCIE0A); // OCR0A interrupt only.
  OCR0A = IRQ_CYCLE_LENGTH + 1;
  millis_counter = 0;
  irq_cycle_pos = 0;
  sei();
  
  // I/O port setup 
  DDRA = _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA7);
  DDRB = _BV(PB0) | _BV(PB1) | _BV(PB2);
  PORTA = _BV(PA5); // enable the pull-up on the button pin
  PORTB = 0;
  
  unsigned char pattern = eeprom_read_byte(EE_PATTERN_NUM);
  if (pattern >= PATTERN_COUNT) pattern = 0;
  place_in_pattern = -1;
  milli_of_next_change = 0;
  button_debounce_time = 0;
  button_press_time = 0;
  ignoring_button = 0;

  while(1) {
    unsigned long now = millis();

    // poll for button events
    unsigned int event = checkEvent();
    switch(event) {
      case EVENT_LONG_PUSH:
        sleepNow();
        continue;
      case EVENT_SHORT_PUSH:
        if (++pattern >= PATTERN_COUNT) pattern = 0;
        place_in_pattern = -1;
        milli_of_next_change = 0;
        eeprom_write_byte(EE_PATTERN_NUM, pattern);
        continue;
    }

    // If it's time to move to the next step in a pattern, pull out its
    // mask and clear all of the LEDs.

    // Note that now > milli_of_next_change is wrong here because our
    // time wraps. now - milli_of_next_change > 0 *looks* the same,
    // but handles cases where the sign differs.
    if (milli_of_next_change == 0 || ((long)(now - milli_of_next_change)) >= 0) {
      // It's time to go to the next step in the pattern
      place_in_pattern++;
      const struct pattern_entry *our_pattern = (struct pattern_entry *)pgm_read_ptr(&(patterns[pattern]));
      struct pattern_entry entry;
      do {
        memcpy_P(&entry, (void*)(&(our_pattern[place_in_pattern])), sizeof(struct pattern_entry));
        // A duration of 0 is the end of the pattern.
        if (entry.duration != 0) break;
        place_in_pattern = 0;   
      } while(1); // This means a pattern of a single entry with 0 duration is kryptonite.
      current_mask = entry.mask;
      // Turn out all the lights
      for(int i = 0; i < LED_COUNT; i++) {
        *((unsigned char *)pgm_read_ptr(&(LED_PORT[i]))) &= ~_BV(pgm_read_byte(&(LED_PIN[i])));
      }
      milli_of_next_change = now + entry.duration;
      current_led = 99; //invalid
    }

    // Now multiplex the LEDSs. Rotate through all of the set bits in the
    // current mask and turn the next one on every pass through this loop.
    if (current_mask != 0) { // if it IS zero, then all the lights are out anyway.
      unsigned char next_led = current_led;
      while(1) { // we know it's not zero, so there's at least one bit set
        if (++next_led >= LED_COUNT) next_led = 0;
        if (current_mask & (1 << next_led)) break; // found one!
      }
      if (next_led != current_led) {
        // turn the old one off and the new one on.
        if (current_led < LED_COUNT) // is it safe?
          *((unsigned char *)pgm_read_ptr(&(LED_PORT[current_led]))) &= ~_BV(pgm_read_byte(&(LED_PIN[current_led])));
        *((unsigned char *)pgm_read_ptr(&(LED_PORT[next_led]))) |= _BV(pgm_read_byte(&(LED_PIN[next_led])));
        current_led = next_led;
      }
    }
  }
}