We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I want to create a bit field structure for a group of bits associated with 'sfr P1' /* Bit definitions within sfr P1 */ #define NRAMEN (1 << 5) #define A20 (1 << 4) #define A19 (1 << 3) #define A18 (1 << 2) #define A17 (1 << 1) #define A16 (1 << 0) #define NCSDUART NRAMEN+A18 struct myp1 { unsigned char bankSelect :6; /* select banked device */ unsigned char wdog :1; }; struct myp1 data port1 _at_ 0x90; /* problem line doesnt work */ My problem is the last line, how do i get my struct to use P1 so I can do the following ? port1.bankSelect = NCSDUART; /* set/res the appropriate bits on port1 */ Or will i have to start doing something like the following (which i was trying to avoid)? P1 = (P1 & 0xC0) + NCSDUART; /* mask off unwanted bits then select appropriate banked device */ Thanks Mark.
The ability to describe a port and other addresses as bit-fields would be a very nice feature indeed. In principle, a compiler should be able to do this and generate different object code for accessing bit-addressable and non-bit-addressable locations in an efficient way. Of course, compilers can vary in their placing of bit fields within words (that is a weakness of C). However, the advantage is that a statement such as:
select.bank = 3;