// Oscilloscope firmware, Roman Pavelka, 2011
// written for atmega8

#define F_CPU 16000000
#define BAUD 1000000
//#define MYUBRR F_CPU/8/BAUD-1
#define MYUBRR 1

#include "./libs/usart.h"
#include "./libs/spi.h"

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <inttypes.h>

int main (void) {
  USART_Init(MYUBRR);

  DDRB  =  0b00100100; //SCK, SS out
  PORTB =  0b00000000; // CONV low

  SPI_MasterInit();


  while(1)
  {
    PORTB |= 0b00000100;
    _delay_us(4);
    PORTB &= 0b11111011; //one conversion

    USART_Transmit(SPI_MasterTransmit(0x0)); //Binary transfer
    USART_Transmit(SPI_MasterTransmit(0x0)); 
    _delay_us(4);
  }
  return 0;
}