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;
// enables USART Receiver, enables USART TransmitterUCSR0B= (1<<RXEN0) | (1<<TXEN0);
// sets Character Size to 8bitUCSR0C= (1<<UCSZ01) | (1<<UCSZ00);
UBRR1=103;
// enables USART Receiver, enables USART TransmitterUCSR1B= (1<<RXEN1) | (1<<TXEN1);
// sets Character Size to 8bitUCSR1C= (1<<UCSZ11) | (1<<UCSZ10);
}
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 charUSART_Receive1(){
// Flag is set when unread data in receive buffer // Flag is cleared when the receive buffer is emptywhile (!(UCSR1A& (1<<RXC1)));
returnUDR1;
}
voidUSART_transmit1(unsigned charsData){
// If UDREn is set, the buffer is empty and therefore ready to be written.while(!(UCSR1A& (1<<UDRE1)));
UDR1=sData;
}
voidUSART_transmit(unsigned charsData){
// If UDREn is set, the buffer is empty and therefore ready to be written.while(!(UCSR0A& (1<<UDRE0)));
UDR0=sData;
}
intsearch_x(unsigned charregen[]){ //?intnumber=0;
for(inti=0;i<5;i++){
number++;
}
returnnumber;
}
unsigned chartext[5];
intmain(void){
USART_init();
intnumber=0;
charnumber_char;
while (1){
for(inti=0; i<5; i++){
text[i] =USART_Receive1();
}
for(inti=0; i<5; i++){
if(text[i] =='x'||text[i] =='X'){
number++;
}
}
number_char=number+'0';
USART_transmit(number_char);
//USART_transmit("\n");
}
}