#include void usart_init(void) { UBRRL = 25; // 9600 bps UCSRB |= _BV(TXEN); } void usart_putchar(uint8_t c) { UDR = c; while(bit_is_clear(UCSRA, TXC)); UCSRA = _BV(TXC) ; } void adc_init(void) { ADMUX = 0; // channel 0 ADCSRA |= _BV(ADEN) | _BV(ADPS1) | _BV(ADPS2); } void start_conversion(void) { ADCSRA |= _BV(ADSC); } int conversion_not_over(void) { return !(ADCSRA & _BV(ADIF)); } void clear_adif(void) { ADCSRA |= _BV(ADIF); } main() { usart_init(); adc_init(); while(1) { // send a 0xff in the beginning and // and end to make it easier for the // receiver to decode. usart_putchar(0xff); start_conversion(); while (conversion_not_over()); clear_adif(); usart_putchar(ADCL); usart_putchar(ADCH & 3); usart_putchar(0xff); } }