You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#defineF_CPU 16000000
#include<avr/io.h>#include<util/delay.h>voidUSART_init(void){
UBRR0=103; //set Baudrate// enables USART Receiver, enables USART TransmitterUCSR0B= (1<<RXEN0) | (1<<TXEN0);
// sets Character Size to 8bitUCSR0C= (1<<UCSZ01) | (1<<UCSZ00);
}
voidUSART_transmit(unsigned chardata){
// If UDREn is set, the buffer is empty and therefore ready to be written.while(!(UCSR0A& (1<<UDRE0)));
UDR0=data;
}
unsigned charUSART_receive(){
// Flag is set when unread data in receive buffer // Flag is cleared when the receive buffer is emptywhile(!(UCSR0A& (1<<RXC0)));
returnUDR0;
}
unsigned chartext[] = {"Hello\r\n"};
intmain(void){
USART_init();
while(1){
if(USART_receive() =='r'){
for(inti=0;i<7;i++){
USART_transmit(text[i]);
}
}
_delay_ms(100);
}
}