/** * \fn void note(char temps, int note) * \brief Permet de jouer une note pendant un certain temps * \param [IN] temps est la duree pendant laquelle on souhaite jouer la note - temps ne doit pas depasser la valeur 11 ( 2^8 / 5760 ) [IN] note est la fréquence d'OCR0A que l'on souhaite jouer */ void note(char temps, int note) { start_timer0(note); start_timer1(temps * 5760); // 100 ms wait_OCR1A_timer1(); stop_timer1(); stop_timer0(); }
int main(void) { int i; int count = 0; DDRB = 0; DDRC = 0; DDRE = 0; // Enable the pullup on RESET pin. #if defined(__AVR_AT90PWM316__) PORTE = (1<<PINE0); PORTE &= ~(1<<PINE0); #elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) PORTC = (1<<PINC6); PORTC &= ~(1<<PINC6); #else #warning "Didn't enable reset pin pullup" #endif // Setup all of port C as inputs, except for pin C5 SETUP_DEBUG_PINS(); // Set up the ADC single conversion pin. DDRC &= ~(1<<PINC6); PORTC &= ~(1<<PINC6); // Disable all the ADC digital inputs. DIDR1 = 0xFF; DIDR0 = 0xFF & ~(1<<ADC1D); // populate the buffer with known values ringBuffer_initialize(&txbuffer,txbuffer_storage,TXBUFFER_LEN); ringBuffer_initialize(&adcbuffer,adcbuffer_storage,BUFFER_LEN); ringBuffer_initialize(&rxbuffer,rxbuffer_storage,RXBUFFER_LEN); // Populate the ADC read schedule with the mux indices that you want. adc_mux_schedule[0] = 2; adc_mux_schedule[1] = 10; adc_mux_schedule[2] = 6; adc_mux_schedule[3] = 3; uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU), &rxbuffer, &txbuffer); //uart_config_default_stdio(); // Translate those indices and the mask specifying which MUXes to turn on, // to an encoded mux schedule that the ADC understands. adc_encode_muxSchedule(adc_mux_schedule, SCHEDULE_LEN); adc_init(ADC_MODE_MANUAL, &adcbuffer, adc_mux_schedule, SCHEDULE_LEN); timer0_init(); sei(); uart_puts_P("\f\r\n\r\nADC and UART Demo. Commands:\n" "b Begin 4 channel read bursts at CLK/16K\n" "e End reading.\n" "s Single conversion.\n"); DEBUG_PIN1_OFF(); while(1) { do { i = uart_getc(); } while (i == UART_NO_DATA); DEBUG_PIN1_ON(); if(i == 'b'){ uart_puts_P("Begin.\n"); start_timer0(); } else if(i == 'e'){ stop_timer0(); _delay_us(100); uart_puts_P("End.\n"); } else if(i == 's'){ uart_puts_P("ADC"); uart_put_hex8(count); uart_puts_P(": "); i = adc_single_conversion(count); uart_put_hex8((i >> 8) & 0xFF); uart_put_hex8(i & 0xFF); uart_putc('\n'); count = (count + 1) & 0xF; if(count == 11) { count = 13; } } else{