Example #1
0
int main() {
    pin_test();
    gc_ptr<A> a = gc_new<A, int>(0xdeadbeef);
    gc_ptr<B> b = gc_new<B, gc_ptr<A> >(a);
    A* ptr = a.get();
    int value = ptr->value;
    gc();
    assert(ptr != a.get());
    assert(value == a->value);
    assert(b->a.get() == a.get());
    return 0;
}
void get_char(volatile unsigned char *pins, unsigned char pin, char *rxbyte) {
   //
   // read character into rxbyte on pins pin
   //    assumes line driver (inverts bits)
   //
   *rxbyte = 0;
   while (pin_test(*pins,pin))
      //
      // wait for start bit
      //
      ;
   //
   // delay to middle of first data bit
   //
   half_bit_delay();
   bit_delay();
   //
   // unrolled loop to read data bits
   //
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 0);
   else
Example #3
0
int main(void) {
  // set clock divider to /1
  CLKPR = (1 << CLKPCE);
  CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);

  // initialize rgb output pins
  set(led_r_port, led_r_pin);
  set(led_g_port, led_g_pin);
  set(led_b_port, led_b_pin);
  output(led_r_direction, led_r_pin);
  output(led_g_direction, led_g_pin);
  output(led_b_direction, led_b_pin);

  input(buttons_direction, button_0_pin);
  input(buttons_direction, button_1_pin);
  input(buttons_direction, button_2_pin);
  input(buttons_direction, button_3_pin);
  pullup(buttons_port, button_0_pin);
  pullup(buttons_port, button_1_pin);
  pullup(buttons_port, button_2_pin);
  pullup(buttons_port, button_3_pin);

  unsigned int elapsed_us = 0;
  int button_polls_per_second = 10;
  int button_states[4] = {0, 0, 0, 0};
  int rgb_pulses_per_ms[3] = {0, 0, 0};

  while (1) {
    _delay_us(1);
    elapsed_us++;

    // poll button state
    if (elapsed_us % 1000 < button_polls_per_second) {
      if (!pin_test(buttons_pins, button_0_pin)) {
        button_states[0] = 10;
      } else if (button_states[0]) {
        button_states[0]--;
      }
      if (!pin_test(buttons_pins, button_1_pin)) {
        button_states[1] = 10;
      } else if (button_states[1]) {
        button_states[1]--;
      }
      if (!pin_test(buttons_pins, button_2_pin)) {
        button_states[2] = 10;
      } else if (button_states[2]) {
        button_states[2]--;
      }
      if (!pin_test(buttons_pins, button_3_pin)) {
        button_states[3] = 10;
      } else if (button_states[3]) {
        button_states[3]--;
      }
    }

    // calculate rgb values
    set_rgb_pulse_rates(button_states, rgb_pulses_per_ms);

    // update red led
    if (elapsed_us % 1000 < rgb_pulses_per_ms[0]) {
      clear(led_r_port, led_r_pin);
    } else {
      set(led_r_port, led_r_pin);
    }
    // update green led
    if (elapsed_us % 1000 < rgb_pulses_per_ms[1]) {
      clear(led_g_port, led_g_pin);
    } else {
      set(led_g_port, led_g_pin);
    }
    // update blue led
    if (elapsed_us % 1000 < rgb_pulses_per_ms[2]) {
      clear(led_b_port, led_b_pin);
    } else {
      set(led_b_port, led_b_pin);
    }
  }
}