--- In lpc2000@yahoogroups.com, "wickedmonster2002" <karim@...> wrote:
>
> I am confused. What does #define SPIF (1<<7) mean? Everything else I
> understand.
>
As others have pointed out discovering **what** it means is very
simple: it's just standard 'C'.
What's less obvious is **why** this construct is used. I believe the
following is the main reason:
In many peripheral register descriptions, you will see the function of
individual bits described. This is the case for "SPIF", which is bit 7
in SPSR. Rather than work out by hand (and perhaps getting it wrong),
the simplest thing is to get the pre-processor to do it for you. In the
general case:
#define BIT_NAME (1 << bit_position)
That way it's easy to cross check the definition in the code against
the documentation.
You can then use it in code to select the bit of interest as follows:
if (S0SPSR & SPIF)
{
do_something();
}
BrendanMessage
Re: LPC2200 Application Note on SPI (AN10369)
2006-05-11 by brendanmurphy37
Attachments
- No local attachments were found for this message.