David Kelly wrote: > On Thu, Mar 22, 2007 at 09:28:01AM -0700, larry barello wrote: > >>One can define a struct for something like the USART peripheral and >>use bit fields. This has, in fact, been done for the GCC compiler. > > > BTDT. An inline mask usually results in smaller and faster code. Also > masks are much better when one is watching multiple bits. Me too, and it makes just as small of code as the bit shift code with GCC-AVR. I compiled both ways and looked at the assembly generated. I got spoiled by Microchip, which does this and I did it with the code that I was writing, but only for the registers that I wanted to use. > >>Better yet to use the GCC shorthand _BV() to get the "bit value" of a >>number. Personally I greatly dislike _BV since it is non-intuitive to read. >>#define _BV(A) (1<<(A)) >> >>While (UCSRA & _BV(UDRE)) >> ; > > > Yuck. I find (1<<5) or (1<<UDRE) immediately says what is happening > _BV(5) adds an extra level of indirection confusion and _BV(UDRE) > doubles the indirection confusion. I don't find (1<<UDRE) to be > confusing. > > We're pretty much bound by the definitions in Atmel's datasheets. But > when I don't have a historical mandate and am creating new definitions > for a project I'll do it more like this: > > #define UCSRA_UDRE_m (1<<5) yup. > Which is obvious when reading that it only applies to UCSRA and _m is a > reminder that its already in mask form. > DLC -- ------------------------------------------------- Dennis Clark TTT Enterprises www.techtoystoday.com -------------------------------------------------
Message
Re: [AVR-Chat] Re: Some C help please !
2007-03-23 by dlc
Attachments
- No local attachments were found for this message.