Ejemplo n.º 1
0
// Public functions called from main.c
void initDigital() {
  DIGITAL_PULLUP_ON(IN0);
  DIGITAL_SET_HIGH(IN1);
  DIGITAL_SET_LOW(IN2);
  DIGITAL_SET_LOW(IN3);

  // TODO(tobinsarah): allow configuration as input/output for each relevant pin
  DIGITAL_SET_IN(IN0);
  DIGITAL_SET_OUT(IN1);
  DIGITAL_SET_OUT(IN2);
  DIGITAL_SET_OUT(IN3);
}
Ejemplo n.º 2
0
// Public functions called from main.c
void initBuzzer() {
    // Does everything to set up the analog stuffs.
    // Turn on pin PC1 (which maps to IN0)
    ADMUX |= (1 << MUX3) | (1 << MUX1);
#if F_CPU != 8000000
#error Clock speed not correct
#endif
    // Enable the ADC and set the division factor between
    // the system clock frequency and the input clock to the ADC.
    // Division factor: 111 = 128
    ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADEN);

    // Set PA6 pin as output in order to see PWM signal
    // Set pulse width to 1/2 of entire duration.
    OCR1BL = 0x7F;
    DIGITAL_SET_OUT(PWM0);
    // DIGITAL_SET is also ANALOG_SET apparently...
    DIGITAL_SET_IN(IN1);
    DIGITAL_SET_IN(IN2);
    DIGITAL_SET_IN(IN3);

    // Testing
    DIGITAL_SET_OUT(PWM1);
    DIGITAL_SET_HIGH(PWM1);
    // End Testing

    // Set PWM to Fast PWM Mode Operation, with non-inverting PWM
    // Clear OC1B on Compare Match
    // Clock prescaler = 1/64
    TCCR1A = (1 << COM1B1) | (1 << WGM10);
    TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10);

    // Enable Timer/Counter1 Overflow Interrupt
    TIMSK = (1 << TOIE1);

    sei();
}