You are using 'anonymous' structs/unions. I always found this potentially problematical, so I never use it. If you do your definition like this: > typedef union { > struct > { > unsigned ENC1UP :1; > unsigned ENC1DN :1; > unsigned ENC2UP :1; > unsigned ENC2DN :1; > unsigned ENC3UP :1; > unsigned ENC3DN :1; > unsigned ENC4UP :1; > unsigned ENC4DN :1; > } bits; > struct > { > unsigned all :8; > } all; > } T; Then you can say: T t; t.bits.ENC3DN =3D 1; t.all.all =3D 0; ~ Bob Ammerman RAm Systems > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of Josh Koffman > Sent: Wednesday, March 18, 2015 8:24 PM > To: Microcontroller discussion list - Public. > Subject: [PIC] Bit Field Setup >=20 > Hi all, >=20 > I'm trying to define a status register in XC8. I'd like to be able to reference > individual bits, but also be able to say, clear the variable as a whole. >=20 > I currently have it defined as this: >=20 >=20 > } EncStatus_t; >=20 > In another part of the code, I define a variable using the typedef EncStatus_t. >=20 > In my code, I have two lines that try to write to that variable: >=20 > EncStatus.ENC1DN =3D 1; > EncStatus =3D 0; // Clear encoder status register >=20 > The first line works perfect. The second line throws an error though - illegal > conversion between types - int -> volatile union. >=20 > I understand the basic problem here, but I can't seem to fix it. I've spent a > bunch of time looking at the header file for my processor, to see how I can > write to both PORTB and PORTBbits.RB0 successfully. Near as I can tell, it's > because both of those variables are explicitly being declared at the same > address, not because there's anything fancy in the union. >=20 > So...is there a way to deal with this when I don't know where the variabl= e will > be assigned? >=20 > To be clear, this isn't a work stopping problem, I'd just like to know if there's a > way to do this that is efficient. After all, I can always just clear each bit > individually. >=20 > Thanks! >=20 > Josh > -- > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete fools. > -Douglas Adams > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .