morse_code_transcoder/transcodeur/saisieuart.c

41 lines
No EOL
619 B
C

/*
* saisieuart.c
*
* Created: 18/05/2021 15:40:37
* Author: yboujon1
*/
#include "saisieuart.h"
void uart_init(unsigned int ubrr)
{
DDRD|=(1<<PD1);
UBRRL=ubrr;
UCSRB|=(1<<RXEN)|(1<<TXEN);
UCSRC|=(1<<URSEL)|(1<<UPM1)|(3<<UCSZ0); //mode synchrone, parité paire, mode 8 bit
}
char uart_getchar(void)
{
do{
//nothing
}while ((UCSRA & (1<<RXC))==0);
return UDR;
}
void saisie(char tab[], int *n)
{
int i=0;
do
{
tab[i]=uart_getchar();
i++;
}
while((tab[i-1]!=13) && (i<MAX));
tab[i-1] = '\0';
if (!(i<MAX))
{
fflush(stdin);
}
*n=strlen(tab)+1;
}