I would strongly advise against using bitfields. They come with a large number of undefined and unspecified behavior, making them completely non-portable and unreliable. Professional embedded programmers never use them.
The way bitfields are defined in the CW headers is also non-standard code where they use char instead of int for bitfields. This is not allowed in C, and the CW headers will not compile in an ISO compliant C compiler. Set CW to "Strict ANSI" and see for yourself.
Instead, I strongly recommend to use bit masks:
#define PORTX (*(volatile unsigned char*)0x1234)
#define PORTX_PIN1 0x01
#define PORTX_PIN2 0x02
#define PORTX_PIN3 0x04
...
PORTX |= PORTX_PIN1; /* set pin to active */
PORTX &= ~PORTX_PIN1; /* set pin to passive */
This code is pure ISO C and is portable to any compiler or computer in the world.
Message Edited by Lundin on
2008-11-13 10:39 AM