I wrote:
> So, using my headers, your example test for tx completed or empty could
> be written:
>
[snip]
> if (UCSR0B & ((1 << bitTXC0) | (1 << bitUDRE0)))
> /* do stuff */
>
>
> and the generated code would look like this:
[snip]
> or this (somewhat more efficient):
>
>
> 15:test2.c *** if (UCSR0B & ((1 << bitTXC0) | (1 << bitUDRE0)))
>
> 324 0010 8AB1 in r24,42-0x20
> 325 0012 8076 andi r24,lo8(96)
> 326 0014 31F0 breq .L5
> *** /* do stuff */
> 338 .L5
And here we see the problem with the bit numbers: they're not connected
with the register.
I made the mistake of referring to UCSR0B, when TXC0 and UDRE0 are
actually in UCSR0A.
This is a not-uncommon error using this idiom. You don't have the
ability to make this error when using bitfields.
The above should be:
if (UCSR0A & ((1 << bitTXC0) | (1 << bitUDRE0)))
/* do stuff */
I spent some time making a safer version using C++ templates, but
haven't been satisifed with its ease of use.
--
Ned Konz
ned@bike-nomad.com
http://bike-nomad.comMessage
Re: [AVR-Chat] Re: Some C help please !
2007-03-25 by Ned Konz
Attachments
- No local attachments were found for this message.