serial.c 684 Bytes
#include "serial.h"

void init_serial(unsigned long int speed) //initialisation de la liaison série
{
/* Set baud rate */
UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1;

/* Enable transmitter & receiver */
UCSR0B = (1<<TXEN0 | 1<<RXEN0);

/* Set 8 bits character and 1 stop bit */
UCSR0C = (1<<UCSZ01 | 1<<UCSZ00);

/* Set off UART baud doubler */
UCSR0A &= ~(1 << U2X0);
}

void send_serial(uint8_t c) //envoyer un carctère sur le port série
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
}


uint8_t get_serial(void) //récupérer un caractère envoyé sur le port série
{
loop_until_bit_is_set(UCSR0A, RXC0);
return UDR0;
}

void send_ack(void){
  send_serial(0x01);
}