• AVR Freaks

Hot!Where to find the registers and variable associations

Author
ArakelTheDragon
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2016/12/11 07:12:00
  • Location: 0
  • Status: offline
2020/02/17 02:53:35 (permalink)
0

Where to find the registers and variable associations

Hi,
 
I have started using XC8 to program my chips(I have about 10 PIC16F690), I met a lot of problems, the first on is:
 
1. XC8 exposes register variables as union bit fields that can be accessed as a whole port or by individual bits. Where are the variable associations?

#include <xc.h>


/***** CONFIGURATION *****/
// ext reset, no code protect, no watchdog, 4 MHz int clock
__CONFIG(MCLRE_ON & CP_OFF & WDT_OFF & IOSCFS_OFF & OSC_IntRC_RB4EN);

// Pin assignments
#define LED     PORTCbits.RC3   // indicator LED on RC3
#define nLED    3               //   (port bit 3)


/***** MAIN PROGRAM *****/
void main()
{
    //*** Initialisation
    
    // configure ports
    TRISC = ~(1<<nLED);         // configure LED pin (only) as an output
    ADCON0 = 0;                 // disable analog inputs -> C1OUT usable
    
    // configure comparator 1
    CM1CON0bits.C1PREF = 1;     // +ref is C1IN+
    CM1CON0bits.C1NREF = 0;     // -ref is 0.6 V internal ref
    CM1CON0bits.C1POL = 1;      // normal polarity (C1IN+ > 0.6 V)
    CM1CON0bits.nC1OUTEN = 0;   // enable C1OUT (for hysteresis feedback)
    CM1CON0bits.C1ON = 1;       // turn comparator on

    
    //*** Main loop
    for (;;)
    {
        // continually display comparator output (inverted)
        LED = !CM1CON0bits.C1OUT;  
    }
}

 
Compiler error:
Not a member of structure/union.
#1

18 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27071
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/17 05:28:31 (permalink)
    0
    When you include xc.h, it automatically included the device specific header for the PIC you selected in the project properties.
    In your case, that will be pic16f690.h
    You did not mention which version of XC8. If it is XC8 v2.10, that file is located at:
    C:\Program Files (x86)\Microchip\xc8\v2.10\pic\include
     
    Which line are you getting that compile error on?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/17 05:35:58 (permalink)
    0
    I use v2.10. I will check the headers as soon as I go home.
    EDIT:
    I am trying to measure the Li-IOn battery which is powering the mcu and turn off a relay at 3.2V, the internal absolute voltage reference should be the correct way to do this?

    Also please do not change the datasheet register names and the compiler register names. This is makes it so much easier for us to use other MCUs and port the code, as the hardware names are the same and software names are the same too.
    post edited by ArakelTheDragon - 2020/02/17 08:32:48
    #3
    ric
    Super Member
    • Total Posts : 27071
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/17 05:41:38 (permalink)
    0
    You have several bad field names in there.
    Here is the structure in the header file
    typedef union {
        struct {
            unsigned C1CH                   :2;
            unsigned C1R                    :1;
            unsigned                        :1;
            unsigned C1POL                  :1;
            unsigned C1OE                   :1;
            unsigned C1OUT                  :1;
            unsigned C1ON                   :1;
        };
        struct {
            unsigned C1CH0                  :1;
            unsigned C1CH1                  :1;
        };
    } CM1CON0bits_t;

     These names exactly match the datasheet.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 11:42:44 (permalink)
    0
    Thanks for the help, now I get a different error:
     

    main.c:
        39: __config("__CONFIG", "pic", "MCLRE_ON & CP_OFF & WDT_OFF & IOSCFS_OFF & OSC_IntRC_RB4EN");
                                        ^ (0) Unknown macro (WDT_OFF) used in __CONFIG()
                                        ^ (0) Unknown macro (IOSCFS_OFF) used in __CONFIG()
                                        ^ (0) Unknown macro (OSC_IntRC_RB4EN) used in __CONFIG()
    main.c: main()
        56: CM1CON0bits.CH = 2;
                           ^ (255) not a member of the struct/union ""
                              ^ (182) illegal conversion between types
    int -> volatile union S112
        57: CM1CON0bits_t.C1R = 0;
                         ^ (285) no identifier in declaration
                         ^ (314) ";" expected
        58: CM1CON0bits_t.C1POL = 1;
                         ^ (285) no identifier in declaration
                         ^ (314) ";" expected
        59: CM1CON0bits_t.OE = 0;
                         ^ (285) no identifier in declaration
                         ^ (314) ";" expected
        60: CM1CON0bits_t.C1ON = 1;
                         ^ (285) no identifier in declaration
                         ^ (314) ";" expected

    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 18678
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 12:07:13 (permalink)
    0
    main
    39  is that your code?  where did you find that syntax.
    56 what it says.
    57 CM1CON0bits.C1R  not CM1CON0bits_t.C1R
     
    #6
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 12:09:16 (permalink)
    0

    #include <xc.h>

    /***** CONFIGURATION *****/
    // ext reset, no code protect, no watchdog, 4 MHz int clock
    //__CONFIG(MCLRE_ON & CP_OFF & WDT_OFF & IOSCFS_OFF & OSC_IntRC_RB4EN);
    #pragma config FOSC = 0x7, WDTE = 0x0, PWRTE = 0x0, MCLRE = 0x0, CP = 0x0, CPD = 0x0, BOREN = 0x3, IESO = 0x1, FCMEN = 0x1

    // Pin assignments
    #define LED     PORTCbits.RC3   // indicator LED on RC3
    #define nLED    3               //   (port bit 3)


    /***** MAIN PROGRAM *****/
    void main()
    {
        //*** Initialisation
        
        // configure ports
        TRISC = ~(1<<nLED);         // configure LED pin (only) as an output
        ADCON0 = 0;                 // disable analog inputs -> C1OUT usable
        
        // configure comparator 1
        CM1CON0bits_t.CH = 1;     // +ref is C1IN+
        CM1CON0bits_t.C1R = 0;     // -ref is 0.6 V internal ref
        CM1CON0bits_t.C1POL = 1;      // normal polarity (C1IN+ > 0.6 V)
        CM1CON0bits_t.OE = 0;   // enable C1OUT (for hysteresis feedback)
        CM1CON0bits_t.C1ON = 1;       // turn comparator on alwasy after settings its other bits

        
        //*** Main loop
        for (;;)
        {
            // continually display comparator output (inverted)
            LED = !CM1CON0bits.C1OUT;  
        }
    }

    #7
    ric
    Super Member
    • Total Posts : 27071
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 12:18:20 (permalink)
    +1 (1)
    As Neil said, get rid of all the "_t"
    Also, you used ".CH" where you should have used ".C1CH"
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    du00000001
    Just Some Member
    • Total Posts : 3678
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 12:54:59 (permalink)
    +1 (1)
    What is this?
    A dyslexic or an ID-10-T problem ?
     
    @ Arakel the whatever
    Why did you skive the "C 101" course ?
     

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #9
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 12:57:20 (permalink)
    0
    du00000001
    What is this?
    A dyslexic or an ID-10-T problem ?
     
    @ Arakel the whatever
    Why did you skive the "C 101" course ?
     


    Dude the language you are speaking in is not English. Please don't post if you are not going to make it clear. Chinese styles are not really used in the international fields.
    #10
    du00000001
    Just Some Member
    • Total Posts : 3678
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:04:23 (permalink)
    0
    @ Arakel the ...
     
    Might be I'm not a native English speaker.
     
    But I "speak" C/C++/C#  Smile
    And it's obvious that you missed the very basics of C programming.
     
    P.S.: What do you think is "Chinese Style" ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #11
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:09:10 (permalink)
    0
    I think that there are many Chinese styles, from which the Mandarin is internationally accepted, just like there are many English styles of speaking depending on the country you are in, also people from different countries convert English to their own language, which makes it almost impossible for us to understand what it means.
     
    And I don't think I am missing any basics, maybe I skipped some unimportant detail, but then programming requires the checkup of thousands of symbols per day, its not like its impossible.
    #12
    ric
    Super Member
    • Total Posts : 27071
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:11:39 (permalink)
    +2 (2)
    Enough of the small talk. Have you fixed the two things I pointed out?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #13
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:12:44 (permalink)
    +1 (1)
    Yes, it works now.
    #14
    ArakelTheDragon
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:19:52 (permalink)
    0
    NKurzman
    main
    39  is that your code?  where did you find that syntax.
    56 what it says.
    57 CM1CON0bits.C1R  not CM1CON0bits_t.C1R
     


    I can't find these lines.
    #15
    NKurzman
    A Guy on the Net
    • Total Posts : 18678
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:38:27 (permalink)
    +1 (1)
    ArakelTheDragon
    NKurzman
    main
    39  is that your code?  where did you find that syntax.
    56 what it says.
    57 CM1CON0bits.C1R  not CM1CON0bits_t.C1R
     


    I can't find these lines.


    it is in YOUR Post, Post #5
     
    I do not think your Config Statement line is valid.  it maybe an old stlye.
    #16
    1and0
    Access is Denied
    • Total Posts : 10783
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:58:03 (permalink)
    +2 (2)
    The postfix "_t" is a standard naming convention for data types, usually defined by typedefs. It is NOT used for a variable name.
     
    #17
    Mysil
    Super Member
    • Total Posts : 3670
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/19 13:58:49 (permalink)
    +2 (2)
    Hi,
    Specification of Configuration bits with documentation of settings and keywords recognized, 
    is available in: /docs/*  directory installed together with the XC32 compiler and it's associated files.
    There is a separate .html file for each PIC device type.
     
    Also, in MPLAB X  there is a special editing tool for configuration bits (aka. fuses),
    with possibility to generate: #pragma config setting lines.
     
        Mysil
    #18
    mlp
    boots too small
    • Total Posts : 916
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Where to find the registers and variable associations 2020/02/20 10:32:45 (permalink)
    +2 (2)
    ArakelTheDragon
    du00000001
    A dyslexic or an ID-10-T problem ?
    Why did you skive the "C 101" course ?

    Dude the language you are speaking in is not English.

    True. He's speaking geek, with an old-fart accent.
     

    Mark (this opinion available for hire)
    #19
    Jump to:
    © 2020 APG vNext Commercial Version 4.5