Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:49:08+00:00 2026-05-30T22:49:08+00:00

The following code is from a PIC microcontroller header file, but I assume it’s

  • 0

The following code is from a PIC microcontroller header file, but I assume it’s plain old C.
I understand that the code is to be used for accessing individual bits at an address in memory, but as a C novice, I’d like some help in understanding what is going on here, and how I’d go about using it in my code to set or get bits from ADCON1.

volatile unsigned char           ADCON1              @ 0x09F;

volatile bit VCFG0               @ ((unsigned)&ADCON1*8)+4;
volatile bit VCFG1               @ ((unsigned)&ADCON1*8)+5;
volatile bit ADFM                @ ((unsigned)&ADCON1*8)+7;

volatile union {
    struct {
        unsigned                        : 4;
        unsigned    VCFG0               : 1;
        unsigned    VCFG1               : 1;
        unsigned    : 1;
        unsigned    ADFM                : 1;
    };
} ADCON1bits @ 0x09F;

tagged to C and C++. Let me know if it’s not C++ compatible code, and I’ll remove the tag

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:49:10+00:00Added an answer on May 30, 2026 at 10:49 pm
    volatile unsigned char ADCON1 @ 0x09F;
    

    This simply declares the ADCON1 variable. volatile means accesses should not be optimized out, because the variable contents may change during execution. (ie. the hardware updates the value.)

    I’m guessing the @ syntax is non-standard C; I’ve never seen it before. But I figure it means the value is to be found at offset 0x09F.

    volatile bit VCFG0 @ ((unsigned)&ADCON1*8)+4;
    volatile bit VCFG1 @ ((unsigned)&ADCON1*8)+5;
    volatile bit ADFM  @ ((unsigned)&ADCON1*8)+7;
    

    These again declare variables. The bit type is also not standard C, as far as I know, but should be self-explanatory.

    The @ syntax is again used here to declare the location, but the interesting thing is that apparently the offset is in type-increments, because the address of ADCON1 is multiplied by 8. (A char is 8 times the size of a bit.)

    It’s much the same as you’d index an array or do pointer arithmetic in regular C, for example: char foo[4] is an array 4 bytes in size, but int bar[4] is an array 32 bytes in size. Except in this case, your ‘array’ is the processor’s entire address space.

    So basically, these variables represent specific bits of ADCON1, by taking the char-address (&ADCON1), converting it to a bit-address (*8), then addressing the specific bit (+4).

    volatile union {
        struct {
            unsigned          : 4;
            unsigned    VCFG0 : 1;
            unsigned    VCFG1 : 1;
            unsigned          : 1;
            unsigned    ADFM  : 1;
        };
    } ADCON1bits @ 0x09F;
    

    This declaration is independent from the above, but achieves about the same.

    A union of one struct is declared, and a variable of that type is declared at offset 0x09F. The :4 syntax you see in the struct indicates a bit-size of the member. Nameless struct members are simply inaccessible.

    The union doesn’t seem to really add anything here. You’d access bits as ADCON1bits.VCFG0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following code from here to read an Excel file using
Using code from open source MusicDroid with the following code that I found during
I have the following code from a GWT Project that is part of the
I've used the following code from this link. Getting signals from a MIDI port
I used the following code from a previous posting to detect (most of) the
I have some JS on my site that should prevent the following code from
Hi i used the following code from this tutorial to list all of the
I use following code to delete old image from ftp... unlink(getcwd() . '/images/' .
Am calling the following code from backgroundworker, but instead of setting the desired text,
the following code (from a database object created for each new view): -(void)update:(NSString *)queryText{

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.