Blame view

Robot/serial.c 513 Bytes
d2f14e3c   pfrison   Debut programme a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <avr/io.h>
  
  #define CPU_FREQ 16000000L
  
  void init_serial(int speed){
  	UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; //Set baud rate
  	UCSR0B = (1<<TXEN0 | 1<<RXEN0); //Enable transmitter & receiver
  	UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); //Set 8 bits character and 1 stop bit
  	UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler
  }
  void send_serial(unsigned char c){
  	loop_until_bit_is_set(UCSR0A, UDRE0);
  	UDR0 = c;
  }
  unsigned char get_serial(void){
  	loop_until_bit_is_set(UCSR0A, RXC0);
  	return UDR0;
  }