Quoting Alexey Bishletov <nita@...>:
> 3:47:56 PM, Wednesday, March 1, 2006, Mukund wrote:
>
>> Thanks for the mail.
>> I am porting huge code from 8052 involving lots of port and bit variable.
>> I just want to know how a pin/bit is defined in header file of LPC2138, so
>> that rest of my 8051 code remains unchanged.
>> In 8051 to set a bit we use
>> P1_7=1;
>
> typedef struct
> {
> unsigned long n0:1;
> unsigned long n1:1;
> unsigned long n2:1;
> unsigned long n3:1;
> unsigned long n4:1;
> unsigned long n5:1;
> unsigned long n6:1;
> unsigned long n7:1;
> } BITS32;
> #define P1 (*((volatile BITS32 *) 0xE0028014))
>
> #define P1_7 (P1.7)
>
>
> WBR, Alex
Not portable even between compilers. For non-I/O code this is just
fine but for
operations involving I/O this may produce unexpected results. IE the compiler
may produce perfectly valid code from the viewpoint of what the language is
specified to do but it may not actually work with the I/O.
In particular with this construct you could get a 8 bit I/O operation,
a 16 bit
I/O operation or a 32bit I/O operation.
Also if you have a different read and write register at the same
address you may
get really odd results.
Basically bitfields are a very bad idea for I/O. Sooner or later thay
will bite
you in the fundament.
RobertMessage
Re: Re[2]: [lpc2000] Re: Bit addressing
2006-03-01 by Robert Adsett
Attachments
- No local attachments were found for this message.