O.K., I guess I need to review typedefs, unions, and structs. Hypothetically, would this have been a better way to define OSCCON, in a wo= rld where it was a good idea to modify Microchip?s device .h files? __extension__ typedef struct tagOSCCONBITS { union { unsigned int VALUE; //Note we can now access OSCCONBITS type OSCCON as an u= nsigned int via OSCCON.VALUE struct { unsigned char HVALUE; //Access to the high unsigned char LVALUE; //and low bytes of OSCCON }; struct { unsigned OSWEN:1; unsigned LPOSCEN:1; unsigned :1; unsigned CF:1; unsigned :1; unsigned LOCK:1; unsigned IOLOCK:1; unsigned CLKLOCK:1; unsigned NOSC:3; unsigned :1; unsigned COSC:3; }; struct { unsigned :8; unsigned NOSC0:1; unsigned NOSC1:1; unsigned NOSC2:1; unsigned :1; unsigned COSC0:1; unsigned COSC1:1; unsigned COSC2:1; }; }; } OSCCONBITS; extern volatile OSCCONBITS OSCCON __attribute__((__sfr__)); =20 =20 One thing that always bugs me about programming languages is when you have = only one of something, but you have to name a struct/union/class/whatever f= or it. Now, that can be useful if you have more than one item, or if you wa= nt to copy it, modify it, and pass it as a parameter, but if there?s genuin= ely only one of it, and always will be, why do we need to name its arrangem= ent, instead of simply declaring it? On 12/29/11, piclist-request@mit.edu wrote: =20 Message: 32 Date: Thu, 29 Dec 2011 17:20:30 +0100 From: Jan-Erik Soderholm Subject: Re: [PIC] PIC24H Oscillator, OSCCON register To: "Microcontroller discussion list - Public." Message-ID: <4EFC934E.1080704@telia.com> Content-Type: text/plain; charset=3DISO-8859-1; format=3Dflowed bladetooth@verizon.net wrote 2011-12-29 16:37: > But OSCCON is a union, isn?t it? Shouldn?t that mean I can address its > structured bits? Or am I reading this part of the header file wrong? > Yes, you are. OSCCON is an simple "unsigned int". Then there is another definition of OSCCONBITS that is a struct (or rather an union of two structs...). Jan-Erik. > > ? extern volatile unsigned int OSCCON __attribute__((__sfr__)); > > __extension__ typedef struct tagOSCCONBITS { union { struct { unsigned > OSWEN:1; unsigned LPOSCEN:1; unsigned :1; unsigned CF:1; unsigned :1; > unsigned LOCK:1; unsigned IOLOCK:1; unsigned CLKLOCK:1; unsigned > NOSC:3; unsigned :1; unsigned COSC:3; }; struct { unsigned :8; unsigned > NOSC0:1; unsigned NOSC1:1; unsigned NOSC2:1; unsigned :1; unsigned > COSC0:1; unsigned COSC1:1; unsigned COSC2:1; }; }; } OSCCONBITS; ? > > > > > Ryan Pettigrew > > On 12/28/11, piclist-request@mit.edu wrote: > >> but can?t seem to do simple things like ?OSCCON.OSWEN =3D true;? > > It is always a good idea to look at the appropriate header file. > > In most cases, what you want is something like > > OSCCONbits.OSWEN =3D 1; > > The symbol OSCCON itself refers to the entire register. If it were a > struct you wouldn' tbe able to say things like > > OSCCON =3D 0x1234; > > so the struct has a different name. Almost always the register name > followed by "bits". > > But once in a while there are surprises, so don't be shy about studying > the .h file. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .