Skip to main content
added 699 characters in body
Source Link
Majenko
  • 56.4k
  • 9
  • 106
  • 190
 #define F_CPU 16000000UL
 #include <avr/io.h>
 #include <avr/interrupt.h>

  volatile char data;

 void USARTInit(uint16_t ubrr_value)
  {
 
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value>>8ubrr_value >> 8);
    UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
 UCSRB=   UCSRB = (1<<RXEN1 << RXEN) | (1<<TXEN1 << TXEN);
}
 

void USARTWriteChar(char data)
  {
    while (!(UCSRA & (1<<UDRE1 << UDRE)))
  { }     { }

    //Now write the data to USART buffer
 UDR=data;   UDR = data;                                                               
}
                                                                              
                                                                              
void main()
  {
                                                                  
    sei();                                                                    
    UCSRB |= (1<<RXCIE1 << RXCIE);                                                    
    USARTInit(51);                                                            
                                                                              
    while (1)
  {
                                                                
        if (data=='a')
data == 'a') {
                                                     
            USARTWriteChar(data);
 
     }
    }
    }
}

  ISR(USARTRXC_vect)
  {
 
data=    data = UDR;
 
}
 #define F_CPU 16000000UL
 #include <avr/io.h>
 #include <avr/interrupt.h>

  volatile char data;

 void USARTInit(uint16_t ubrr_value)
 {
 
 UBRRL = ubrr_value;
 UBRRH = (ubrr_value>>8);
 UCSRC = (1 << URSEL)| (1 << UCSZ0) | (1 << UCSZ1);
 UCSRB=(1<<RXEN)|(1<<TXEN);
}
 

void USARTWriteChar(char data)
 {
 while(!(UCSRA & (1<<UDRE)))
  { }    
   //Now write the data to USART buffer
 UDR=data;
}
 

void main()
 {
 
sei();
UCSRB |=(1<<RXCIE);
USARTInit(51);    

while(1)
 {
   
  if(data=='a')
  {
 
  USARTWriteChar(data);
 
     }
    }
   }

  ISR(USARTRXC_vect)
 {
 
data= UDR;
 
}
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>

volatile char data;

void USARTInit(uint16_t ubrr_value) {
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);
    UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    UCSRB = (1 << RXEN) | (1 << TXEN);
}

void USARTWriteChar(char data) {
    while (!(UCSRA & (1 << UDRE)))
        { }

    //Now write the data to USART buffer
    UDR = data;                                                               
}                                                                             
                                                                              
void main() {                                                                 
    sei();                                                                    
    UCSRB |= (1 << RXCIE);                                                    
    USARTInit(51);                                                            
                                                                              
    while (1) {                                                               
        if (data == 'a') {                                                    
            USARTWriteChar(data);
        }
    }
}

ISR(USARTRXC_vect) {
    data = UDR;
}
deleted 1586 characters in body
Source Link
#define F_CPU 16000000UL
#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>

volatile char data;


void USARTInit(uint16_t ubrr_value) {
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);
    UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
//Enable The receiver and transmitter
    UCSRB = (1 << RXEN) | (1 << TXEN);
}


char USARTReadChar()

{
//Wait untill a data is available
    while (!(UCSRA & (1 << RXC))) {
        //Do nothing
    }

//Now USART has got data from host
//and is available is buffer
    return UDR;
}


//the USART which then transmit it via TX line
void USARTWriteChar(char data) {
//Wait untill the transmitter is ready
    while (!(UCSRA & (1 << UDRE))) {
    }

//Now write the data to USART buffer
    UDR = data;
}

void main() {
    char data;
    sei();
    UCSRB |= (1 << RXCIE);
    USARTInit(51);    //UBRR = 51

    //Loop forever

    while (1) {
        //Read data
        //  data=USARTReadChar();
        if (data == 'a') {
            USARTWriteChar('[');
            USARTWriteChar(data);
            USARTWriteChar(']');
        }
    }
}

ISR(USARTRXC_vect) {
    data = UDR;

    if (data == 1)
    }
    ... corrupt code ...

so if i type "FOO" , Microcontroller should echo back with [FOO] instead there is no response, let me know where I was wrong.

I am also new to coding formats and as @majenko has suggested about the artistic style, I have installed it in atmel studio 5.2 but there seems to be no difference at all in the format.

 
#define F_CPU 16000000UL
#include <avr/io.h>
#include <inttypes.h>
#include <avr/interrupt.h>

volatile char data;


void USARTInit(uint16_t ubrr_value) {
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value >> 8);
    UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
//Enable The receiver and transmitter
    UCSRB = (1 << RXEN) | (1 << TXEN);
}


char USARTReadChar()

{
//Wait untill a data is available
    while (!(UCSRA & (1 << RXC))) {
        //Do nothing
    }

//Now USART has got data from host
//and is available is buffer
    return UDR;
}


//the USART which then transmit it via TX line
void USARTWriteChar(char data) {
//Wait untill the transmitter is ready
    while (!(UCSRA & (1 << UDRE))) {
    }

//Now write the data to USART buffer
    UDR = data;
}

void main() {
    char data;
    sei();
    UCSRB |= (1 << RXCIE);
    USARTInit(51);    //UBRR = 51

    //Loop forever

    while (1) {
        //Read data
        //  data=USARTReadChar();
        if (data == 'a') {
            USARTWriteChar('[');
            USARTWriteChar(data);
            USARTWriteChar(']');
        }
    }
}

ISR(USARTRXC_vect) {
    data = UDR;

    if (data == 1)
    }
    ... corrupt code ...

so if i type "FOO" , Microcontroller should echo back with [FOO] instead there is no response, let me know where I was wrong.

I am also new to coding formats and as @majenko has suggested about the artistic style, I have installed it in atmel studio 5.2 but there seems to be no difference at all in the format.

 
appended answer 144589 as supplemental
Source Link
Dave Tweed
  • 178.3k
  • 17
  • 242
  • 418

Thank you for your response everyone .

I am sorry for the corrupt code I had no idea what I was doing since I am newbie to this code indention in stack exchange.

I am also new to coding formats and as @majenko has suggested about the artistic style, I have installed it in atmel studio 5.2 but there seems to be no difference at all in the format.

The new code is attached below please kindly suggest

 #define F_CPU 16000000UL
 #include <avr/io.h>
 #include <avr/interrupt.h>

  volatile char data;

 void USARTInit(uint16_t ubrr_value)
{

 UBRRL = ubrr_value;
 UBRRH = (ubrr_value>>8);
 UCSRC = (1 << URSEL)| (1 << UCSZ0) | (1 << UCSZ1);
 UCSRB=(1<<RXEN)|(1<<TXEN);
}


void USARTWriteChar(char data)
{
 while(!(UCSRA & (1<<UDRE)))
  { }    
   //Now write the data to USART buffer
 UDR=data;
}


void main()
{

sei();
UCSRB |=(1<<RXCIE);
USARTInit(51);    

while(1)
{
  
  if(data=='a')
  {

  USARTWriteChar(data);

     }
    }
   }

  ISR(USARTRXC_vect)
{

data= UDR;

}

so here foo just represents my data='a', unfortunately avr is not responding to my inputs . when I type "a" .


Thank you for your response everyone .

I am sorry for the corrupt code I had no idea what I was doing since I am newbie to this code indention in stack exchange.

I am also new to coding formats and as @majenko has suggested about the artistic style, I have installed it in atmel studio 5.2 but there seems to be no difference at all in the format.

The new code is attached below please kindly suggest

 #define F_CPU 16000000UL
 #include <avr/io.h>
 #include <avr/interrupt.h>

  volatile char data;

 void USARTInit(uint16_t ubrr_value)
{

 UBRRL = ubrr_value;
 UBRRH = (ubrr_value>>8);
 UCSRC = (1 << URSEL)| (1 << UCSZ0) | (1 << UCSZ1);
 UCSRB=(1<<RXEN)|(1<<TXEN);
}


void USARTWriteChar(char data)
{
 while(!(UCSRA & (1<<UDRE)))
  { }    
   //Now write the data to USART buffer
 UDR=data;
}


void main()
{

sei();
UCSRB |=(1<<RXCIE);
USARTInit(51);    

while(1)
{
  
  if(data=='a')
  {

  USARTWriteChar(data);

     }
    }
   }

  ISR(USARTRXC_vect)
{

data= UDR;

}

so here foo just represents my data='a', unfortunately avr is not responding to my inputs . when I type "a" .

added 36 characters in body
Source Link
Majenko
  • 56.4k
  • 9
  • 106
  • 190
Loading
Source Link
Loading