XC8 compiler: Register bits + 2?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Nov 13, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,873
    996
    I just started using the XC* compiler. I noticed the the member properties that correspond to the bits are listed twice. One with the bit name and another with the bit name followed by a 2.

    For example:

    TXSTA2bits.SYNC

    and

    TXSTA2bits.SYNC2 are both defined in the header file.

    But there really is not a SYNC2. What is the purpose of this additional definition?
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,138
    1,789
    Bits for a 2nd UART?!!?

    I thought the convention was to use a 1 for the first UART and a 2 for the second one.

    In some parts it might be 0 and 1
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    To reduce unnecessary compile errors. We always had a Foo.bit when there was just one Foo. But when it changes to Foo1 and Foo2 there are a few people out there that will see this as Foo1.bit and Foo2.bit, and some as Foo1.bit1 and Foo2.bit2.

    So both are defined as the name space remains clean.
     
  4. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,873
    996
    Not sure I understand. Why would you get compile errors? Maybe the compiler should be fixed?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It could also be that this is something to make the XC8 compiler more compatible with the former Microchip C compiler
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    You will always get an error when you use an undefined symbol. The compiler is just fine.

    To use Foo2.bit2 you need to define Foo2.bit2.

    If you only define Foo2.bit then Foo2.bit will raise an error.

    If you want to see an extreme case of a redundant naming convention, check out how many different names you can call bit 1 of the ADCON register for any device having an analog to digital module. There are some 8 different names for this bit: GO_NOT_DONE, GO_nDONE, DONE, GO, NOT_DONE, nDONE, GODONE, and GO_DONE.

    So XC8 is the latter Microchip C compiler?
     
    Last edited: Nov 15, 2012
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The XC8 compiler is the former Hi-Tech C compiler for 16/18 series PICs combined into one compiler. The Microchip C compiler will live on for others PICs. But will be renamed to fit under the XC family
     
  8. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,873
    996
    Maybe it is my senility creeping in but I'm still not getting it. TXSTA2bits is just a structure. I have been coding in C for near twenty years and have never had this issue with compile errors and structures. And this is the first I have seen this done. Maybe things are different when it comes to pics?


    Looking at it, there is actually a union of two structures. Maybe the reason they define the member variables twice is for how the structure needs to be mapped into memory? I have done this before my adding dummy variables for the structure.
     
  9. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Which PIC are you using, please?
     
  10. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,873
    996
    I am using the 18f47j53.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    No no no no no. You are way over thinking this. The union in the header file is there just to add an alternate name for the bit. It's all referring to the same thing, the same bit in the same register.

    There is probably no compelling reason for defining both TXSTA2bits.SYNC and TXSTA2bits.SYNC2 in the header beyond some tutorial or demo program back when the first PIC with 2 UARTs came out and the demo code had the bit named wrong, and it became a sort of de facto standard.

    And a rose by any other name...
     
Loading...