--- In lpc2000@yahoogroups.com, "pitstock_kiwi" <keith@...> wrote:
>
>
> Bit addressing can be a lot simpler than all the stuff I have seen
so
> far.
>
> Firstly the LPC214X.H is missing the byte access registers. Why
write
> 32 bit address unless you need to? Also why use the old (slower)
> legacy port IO? FAST IO should be the standard from what I see.
>
> Use this line to turn on your fast ports unless you have some
reason
> to use the old stuff.
> SCS |= 0x00000003; // enable FIQ on port 0 and 1
>
> I have an led on port 0.20 so heres the initialisation for it
>
> // LED on port 0.20, 0x10
> FIO0DIR2 |= 0x10; // Led pin as output
> FIO0MASK2 |= ~0x10; // Led masked for use
> FIO0SET2 |= 0x10; // turn on led
>
> And heres how I toggle the port
>
> if (FIO0PIN2 & 0x10){ // if led is on Same as if (P0_20 == 1)
> FIO0CLR2 |= 0x10;} // turn off led. Same as P0_20 = 0;
> else{
> FIO0SET2 |= 0x10;} // turn on led Same as P0_20 =1;
>
> Because we have masked only one bit it could be even simpler if we
> want
> FIO0SET2 = 0xFF; // turn on led
> FIO0CLR2 = 0x00; // turn off led
>
> Hope this helps
> Kiwi Keith
>
>
> Heres what I added to the LPC214X.H so I could byte access the
port
> as the UM10139_1.pdf mentioned
>
This is indeed a simpler approach than the version I posted.
The version I use has the advantage of being able to use the same
include file (for register definitions) for both assembler and 'C':
the MACRO is used to get the "volatile" and type correct. It's a
fairly minor advantage, though: the clarity of the above version is
probably preferable.
On your other points, most hardware registers on the LPC2000 series
are 32-bit wide as far as I know. In any case, even if they're not,
there's no advantage (that I'm aware of) to accessing them as bytes.
Finally, I used the "old style" I/O port access simply because that
was the example I had to hand. As others have pointed out, they have
certain advantages (no need for read/modify/write), but you clearly
you should use whatever's easiest/most suitable.
BrendanMessage
Re: Bit addressing
2006-03-02 by brendanmurphy37
Attachments
- No local attachments were found for this message.