[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Bit-wise structure and unions
From: |
Joerg Wunsch |
Subject: |
Re: [avr-gcc-list] Bit-wise structure and unions |
Date: |
Wed, 22 Nov 2006 09:12:09 +0100 (MET) |
Keith Gudger <address@hidden> wrote:
> But I would rather not have the union. Is there any other way
> around this? Thanks.
While I agree with David and Eric that your non-union version prevents
you from manipulating multiple bits at once, the following will work:
struct port_reg {
unsigned char bit0: 1;
unsigned char bit1: 1;
unsigned char bit2: 1;
unsigned char bit3: 1;
unsigned char bit4: 1;
unsigned char bit5: 1;
unsigned char bit6: 1;
unsigned char bit7: 1;
};
#define PORTB_BITS (*((volatile struct port_reg *)0x37))
void
foo(void)
{
PORTB_BITS.bit0 = 1;
PORTB_BITS.bit1 = 0;
}
You forgot the "volatile" anyway.
--
cheers, J"org .-.-. --... ...-- -.. . DL8DTL
http://www.sax.de/~joerg/ NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)