Searching \ for 'Piclist Digest, Vol 89, Issue 21' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'Piclist Digest, Vol 89, Issue 21'.

Truncated match.
PICList Thread
'Piclist Digest, Vol 89, Issue 21'
2011\12\29@132237 by bladetooth

picon face
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 world 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 unsigned 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__));
 
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 for it. Now, that can be useful if you have more than one item, or if you want to copy it, modify it, and pass it as a parameter, but if there?s genuinely only one of it, and always will be, why do we need to name its arrangement, instead of simply declaring it?



On 12/29/11, spam_OUTpiclist-requestTakeThisOuTspammit.edu wrote:
Message: 32
Date: Thu, 29 Dec 2011 17:20:30 +0100
From: Jan-Erik Soderholm <.....jan-erik.soderholmKILLspamspam@spam@telia.com>
Subject: Re: [PIC] PIC24H Oscillator, OSCCON register
To: "Microcontroller discussion list - Public." <piclistspamKILLspammit.edu>
Message-ID: <.....4EFC934E.1080704KILLspamspam.....telia.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed



EraseMEbladetoothspam_OUTspamTakeThisOuTverizon.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.


{Quote hidden}

> the .h file

2011\12\29@143353 by Bob Blick

face
flavicon
face
Note: when you reply to a Piclist Digest message, it makes sense to
restore the subject line, in this case:

Re: [PIC] PIC24H Oscillator, OSCCON register

Other than the obvious reasons for having a correct subject line, you
want to have the correct topic tag. Many users do not receive untagged
posts, as per their personal Piclist distribution ruleset.

Bob


-- http://www.fastmail.fm - Does exactly what it says on the tin

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...