can anyone explain this condition???

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please explain these conditions...if I want to write it differently....using if/else....can anyone explains it in words...I have tried but not sure...

1. while (!(UCSR0A & (1<<UDRE0)));

2. while((UCSR0A&(1<<RXC0)) == 0);

as my compiler is different I have to write it differently...

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
// this code waits until you can write a new char to TX 
// this just reads the status register.
// ANDs with   0b0010000 
// so if the   0b0010000 bit is set the loop will end
// anything in 0b1101111 bits is ignored
while (!(UCSR0A & (1<<UDRE0)))  // test bit 5 of USART status
    ;                           // do nothing

// this code waits until a char is received in RX
// exactly the same procedure (except bit 7)
while((UCSR0A&(1<<RXC0)) == 0)  // test bit 7
    ;                           // just loop again

I suspect that your AVR has different bit-names like RXC or RXC1. So just change to your bit-names and re-compile

David.

p.s. download the data sheet for the AVR that this code was written for. download the data sheet for your AVR. Search for 'UDRE'. Understand any difference between AVRs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have seen the datasheet...above conditions are written in the datasheet of the atmega16....but I am bit confused.....whether I should wait until UCSRA.UDRE=1 or UCSRA.UDRE=0....when should I transfer the byte..when flag becomes 1 or 0...

same UCSRA.RXC=1 or 0....

solved.... :idea:

I have finally got it right..... :wink:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the name of the bit is 'Usart Data Register Empty', then when the bit is on/true/hi/one the data register is empty?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

using if/else....

The while()'s are looping constructs, if/else are not so to make them loop I fear you would also want to employ a "goto" which would be quite horrendous. I guess one way to do it is to reverse the sense of the test:

while (1) {
  if (UCSR0A & (1<<UDRE0)) break;
}

Or if you really insist on using goto:

loop:
  if (!(UCSR0A & (1<<UDRE0))) goto loop;