Re: [AVR-Chat] Re: Some C help please !
2007-03-22 by np np
I would never write code this way. I would always have everything named properly and once. Any places where numbers are entered could result in an error.
Show quoted textHide quoted text
----- Original Message ----
From: kernels_nz <kernels@slingshot.co.nz>
To: AVR-Chat@yahoogroups.com
Sent: Thursday, 22 March, 2007 8:44:08 PM
Subject: [AVR-Chat] Re: Some C help please !
Hi Guys, I started this conversation, but after asking the initial
question and getting a few replies, it has become glaringly obvious to
me why (UCSRA &(1 << UDRE)) is better than UCSRA.5
By the way, UCSRA.5 compiles fine in codevision and was how we were
taught to access the AVR registers way back in uni. I realise now that
it is a fairly simplistic way to write the code, and not good if you
want to re-use the code on any other AVR.
The huge advantage of using the shift and mask method is that it makes
pre-written code completely portable to any other AVR micro with the
same names for bits, and generally when two AVR micros have the same
peripherals, they also use the same bit-names, but not necessarily in
the same bit position.
My 2c, glad I asked the question to start of with, the help from
everyone in this group is amazing.
Cheers
Hein B
Auckland, New Zealand.
--- In AVR-Chat@yahoogroup s.com, Dennis Clark <dlc@...> wrote:
>
> Mike,
>
> What makes the former syntax nicer is that it has no "magic numbers"
> embedded in the code. UCSRA.5 does not mean as much as UCSRA.UDRE (if
> that is defined) or as UCSRA & (1<<UDRE) - The latter does not
require a
> library of structures defining the bits, just a bunch of #defines.
> You'll pick it up as you go along. :)
>
> DLC
>
> Mike Bronosky wrote:
> > All this is fine. But for many of us hobbyists that know just
enough about
> > C, especially when it comes to AVRs, to be down-right-dangerou s...
> >
> > For me something like the following, is good, proper and works. It
is not
> > fully understood until I dissect.
> > while ((UCSRA & (1<<UDRE))== 0);
> >
> > while(UCSRA. 5 == 0); //while(USART Data Register Empty)
> > Haven't tried this but I think it should work and means "while the
data
> > register is empty sit right here".
> > Now to the Xsperts may disagree. I'm a hobbiest, it works for me
and best of
> > all I understand why it works.
> >
> > Mike
> >
> > On 3/14/07, David Appleton <englsprogeny@ ...> wrote:
> >
> >> I am going to learn so much from this group......
> >>Glad I joined.
> >>
> >>
> >>: )
> >>
> >>[Non-text portions of this message have been removed]
> >>
> >>
> >>
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
>
> --
> ------------ --------- --------- ---------
> Dennis Clark TTT Enterprises
> ------------ --------- --------- ---------
>
<!--