Hot!Exception when working with pins

Page: 12 > Showing page 1 of 2
Author
Taarak
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2018/02/08 08:20:07
  • Location: 0
  • Status: offline
2018/02/13 08:22:41 (permalink)
0

Exception when working with pins

Hi guys.
I am learning C (along with assembly, as posted in other thread) for PIC devices, and the current one is the PIC24FJ256GA606.
Currently the assembly is fine, but what I want originally to do is a little bit too impossible to do with assembly. Maybe it is not impossible, but is at least very hard, because is a project that involves text processing and dynamic variables.
So, I started the C curve, and at the first glance something failed. Every place when I search, to power on or off a pin, first I need to set the register AD1PCFG to 1, but the problem is that this register doesn't exists! First, it just stays ok, but when it start compiling it fails, and a error warn stay on the line with "AD1PCFG = 1" saying that it is a undeclared symbol. This occurs too when trying to change values of TRISA, TRISB or anything related to that (but essential C works, like variable declaration, loops, etc).
And, I have installed XC16. And, I have the line "#include "xc.h"".
And here is the full Output:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/vthmgnpipola/MPLABXProjects/PICTesting.X'
make -f nbproject/Makefile-default.mk dist/default/debug/PICTesting.X.debug.elf
make[2]: Entering directory '/home/vthmgnpipola/MPLABXProjects/PICTesting.X'
"/opt/microchip/xc16/v1.33/bin/xc16-gcc" main.c -o build/default/debug/main.o -c -mcpu=24FJ256GA606 -MMD -MF "build/default/debug/main.o.d" -g -D__DEBUG -D__MPLAB_DEBUGGER_SIMULATOR=1 -mno-eds-warn -omf=elf -DXPRJ_default=default -legacy-libc -O0 -msmart-io=1 -Wall -msfr-warn=off
main.c: In function 'main':
main.c:11:5: error: 'AD1PCFG' undeclared (first use in this function) <-- Here is the undeclared error
main.c:11:5: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [build/default/debug/main.o] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:98: recipe for target 'build/default/debug/main.o' failed
make[2]: Leaving directory '/home/vthmgnpipola/MPLABXProjects/PICTesting.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory '/home/vthmgnpipola/MPLABXProjects/PICTesting.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 41s)

#1

23 Replies Related Threads

    NorthGuy
    Super Member
    • Total Posts : 5054
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:00:29 (permalink)
    +1 (1)
    The explanation is simple. This chip doesn't have AD1PCFG register.
    #2
    rodims
    Super Member
    • Total Posts : 1353
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:10:15 (permalink)
    0

    Every place when I search, to power on or off a pin, first I need to set the register AD1PCFG to 1, but the problem is that this register doesn't exists!

     
    That's evident, as NorthGuy said, your PIC does not have this, and the p24FJ256GA606.h file, which is included by xc.h thus also does not provide this.  You possibly should read about the ANSx registers,- but you did not show any source code,- no idea what you are trying to do. Possibly you are porting your code from a different PIC
     

    This occurs too when trying to change values of TRISA, TRISB or anything related to that (but essential C works, like variable declaration, loops, etc).
    And, I have installed XC16. And, I have the line "#include "xc.h"".

     
    I doubt this, please repeat your question for e.g. TRISB and give more details, including source code and a copy of the compiler error message.
    Also check that you have selected the right PIC processor for your project.
     
     
     
     
    #3
    Taarak
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2018/02/08 08:20:07
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:13:10 (permalink)
    0
    NorthGuy
    The explanation is simple. This chip doesn't have AD1PCFG register.

    The first thing I thought is that. But, everyone I told says "no, this chip need to have this register because every chip has this register and everyone use this register, there is something wrong with your code" so I just picked a example code from somewhere, configured the target chip of the example and the same thing and then they say "so there is something wrong with your computer or your mplab x ide installation" then I asked here.
    #4
    rodims
    Super Member
    • Total Posts : 1353
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:17:38 (permalink)
    0
    But, everyone I told says "no, this chip need to have this register because every chip has this register and everyone use this register, there is something wrong with your code"

     
    Your experts were wrong. Better start with your own code, than to use code which has been written for another PIC.
    You cannot just switch the target PIC. They may be completely different, the AD1PCFG is just a minor difference ...
     
    #5
    KTrenholm
    Super Member
    • Total Posts : 478
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:18:15 (permalink)
    0
    "everyone" doesn't seem to have read the datasheet for the PIC24FJ256GA606.  That part does not have that register.  PICs can be very different from part to part, switching the target PIC for an application is usually not so simple as changing the target and building.
     
    If things like PORT and TRIS are not working, post your code so we can have an actual look rather than guessing. 
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2668
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:22:31 (permalink)
    0
    Look in the pdf doc. for this chip.
     
    Special Function Register Maps

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #7
    Taarak
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2018/02/08 08:20:07
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:41:24 (permalink)
    0
    KTrenholm
    switching the target PIC for an application is usually not so simple

    yeah, I don't changed the pic device of the same project, I created another.
     
    My code is just that:
     
    #include "xc.h"

    int main(void) {
        AD1PCFG = 1;
        TRISA.TRISA = 0x0000;
    }

    And is just that, because what I do got wrong and I just deleted everything.
    And if the register is not this on the pic24fj256ga606 so what is?
    #8
    NorthGuy
    Super Member
    • Total Posts : 5054
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:50:56 (permalink)
    0
    Taarak
    The first thing I thought is that. But, everyone I told says "no, this chip need to have this register because every chip has this register and everyone use this register, there is something wrong with your code" so I just picked a example code from somewhere, configured the target chip of the example and the same thing and then they say "so there is something wrong with your computer or your mplab x ide installation" then I asked here.



    You cannot trust other people. You need to read the datasheet instead.
     
    Like, when I say the register doesn't exist, you don't trust me until you consult the datasheet and verify it is true.
     
    Of course, the reality might be somehow different from the datasheet, but that's another story.
     
    #9
    KTrenholm
    Super Member
    • Total Posts : 478
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:52:04 (permalink)
    0
    Remove ADPCFG1, that is not a register on your PIC as mentioned earlier.  Read the datasheet.  Presumably you are trying to specify a pin as analog or digital.  Look in the datasheet for the register that controls that functionality (It's probably ANSA).
     
    TRIS registers are not accessed in that fashion,
    If you want to set the whole 16-bit register it is simply:
    TRISA = 0x0000; //Initialize Port A to all outputs

     
    For single bits in the register:
    TRISAbits.TRISA0 = 0; //Initialize Pin A0 to an output

     
    post edited by KTrenholm - 2018/02/13 09:54:24
    #10
    NorthGuy
    Super Member
    • Total Posts : 5054
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Exception when working with pins 2018/02/13 09:52:36 (permalink)
    0
    Taarak
     
    #include "xc.h"

    int main(void) {
        AD1PCFG = 1;
        TRISA.TRISA = 0x0000;
    }

    And is just that, because what I do got wrong and I just deleted everything.
    And if the register is not this on the pic24fj256ga606 so what is?



    ANSA I would guess.
    #11
    1and0
    Access is Denied
    • Total Posts : 8396
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:02:22 (permalink)
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2668
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:16:36 (permalink)
    0
    ANSELx A - K (except I)

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2668
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:17:58 (permalink)
    0
    Clear bit to enable digital.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #14
    NorthGuy
    Super Member
    • Total Posts : 5054
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:27:40 (permalink)
    0
    1and0
    Stop guessing ;)
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/30010074e.pdf



    I guess, my guess is as good as the datasheet :) 
    #15
    NKurzman
    A Guy on the Net
    • Total Posts : 16447
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:35:47 (permalink)
    0
    #include "xc.h"

    int main(void) {
        //AD1PCFG = 1;
        TRISA = 0x0000;
    }
    #16
    Taarak
    New Member
    • Total Posts : 18
    • Reward points : 0
    • Joined: 2018/02/08 08:20:07
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:41:57 (permalink)
    0
    hmmmmm
    ANSA register also doesn't exists. TRISAbits and TRISA too. The only ones are from ANSB and up.
    I will read the datasheet now, but it is huge. What should I search to find the correct registers?
    #17
    KTrenholm
    Super Member
    • Total Posts : 478
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: Exception when working with pins 2018/02/13 10:45:29 (permalink)
    0
    Page 23, Table 1-1 says your device (PIC24FJ256GA606) has Ports B, C, D, E, F, G
     
    Port A does not exist on your PIC, so the associated registers (such as TRISA, LATA, PORTA, ANSA) are not valid.
    #18
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2668
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Exception when working with pins 2018/02/13 11:07:22 (permalink)
    0
    It's ANSELA, not ANSA

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #19
    1and0
    Access is Denied
    • Total Posts : 8396
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Exception when working with pins 2018/02/13 11:12:28 (permalink)
    0
    Gort2015
    It's ANSELA, not ANSA

    NO!!!!  There is neither ANSELA nor ANSA.  Read the datasheet or check the header file.
    post edited by 1and0 - 2018/02/13 11:14:33
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5