Hot!XC8 Delay Macro

Author
Russell Allsop
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2016/03/19 07:20:26
  • Location: 0
  • Status: offline
2019/03/24 08:15:33 (permalink)
0

XC8 Delay Macro

Hi,
Hope someone can help with a very basic but frustrating problem I have trying to test a simple delay with a LED after upgrading my MPLAB X (ver 5.15) and XC8 (ver 2.05).
The delay macro is not recognized by the compiler "unable to resolve built in identifier" 
I have tried including the frequency definition #define _XTAL_FREQ 1000000 without success. As far as I am aware the header file generated by MCC includes all the paths for the device etc and the only include required is the one below:
 
#include "mcc_generated_files/mcc.h"
/*
Main application
*/
void main(void)
{
// initialize the device
SYSTEM_Initialize();
while (1)
{
LED_Toggle();
__delay_ms(100);
_delay();
}
}
Looking forward to your comments,
Regards,
Russell Allsop
#1

10 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 2556
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 08:19:13 (permalink)
    +2 (2)
    Does mcc.h include xc.h?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    Russell Allsop
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2016/03/19 07:20:26
    • Location: 0
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 08:24:26 (permalink)
    0
    Yes details below;
    #ifndef MCC_H
    #define MCC_H
    #include <xc.h>
    #include "device_config.h"
    #include "pin_manager.h"
    #include <stdint.h>
    #include <stdbool.h>
    #3
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3118
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 08:36:04 (permalink)
    -3 (3)
    This one:
    #include <delays.h>

    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.
    #4
    davekw7x
    Entropy++
    • Total Posts : 1692
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 09:12:08 (permalink)
    +2 (2)
    Russell Allsop (emphasis added by davekw7x
     
    The delay macro is not recognized by the compiler "unable to resolve built in identifier" 
    LED_Toggle();
    __delay_ms(100);
    _delay();




    Where do you define the _delay() function?  I am pretty sure it isn't defined in any MCC-generated files (at least it isn't for any project I have ever created).  What the heck is a function/macro named _delay, (with no arguments) supposed to do, anyhow?  Have you ever used it in any non-MCC project?
     
    Regards,
     
    Dave
    post edited by davekw7x - 2019/03/24 09:18:49

    Sometimes I just can't help myself...
    #5
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3118
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 10:46:47 (permalink)
    -2 (2)
    Whoever is trolling me with constant negative feedback will be reported to the Moderators.
     
    Carry on for a ban.
    post edited by Gort2015 - 2019/03/24 11:16:49

    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.
    #6
    katela
    Super Member
    • Total Posts : 1194
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 11:04:15 (permalink)
    +1 (1)
    Russell Allsop
     
     
    _delay();



    What is this second delay? If you configure your system settings well with MCC, the delay should work fine.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #7
    qhb
    Superb Member
    • Total Posts : 9673
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: XC8 Delay Macro 2019/03/24 12:16:38 (permalink)
    +2 (2)
    Gort2015
    This one:
    #include <delays.h>

    No.
    That is a C18 file, XC8 does not require it.
     
    #8
    Russell Allsop
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2016/03/19 07:20:26
    • Location: 0
    • Status: offline
    Re: XC8 Delay Macro 2019/03/25 04:12:55 (permalink)
    0
    Thanks for your replies, _delay_ms() macro works with XC18 Ver 1.45 but not with Ver 2.05 for some reason.
     
    #9
    qhb
    Superb Member
    • Total Posts : 9673
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: XC8 Delay Macro 2019/03/25 04:19:25 (permalink)
    +2 (2)
    Russell Allsop
    Thanks for your replies, _delay_ms() macro works with XC18 Ver 1.45 but not with Ver 2.05 for some reason.

    Yes it does (when you spell it correctly, i.e. with two underscores at the start), and have defined _XTAL_FREQ correctly.
     
    #10
    davekw7x
    Entropy++
    • Total Posts : 1692
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: XC8 Delay Macro 2019/03/25 07:39:16 (permalink)
    +4 (4)
    qhb
    ...when you spell it correctly...

    +1.  And I note that the original post spelled it correctly.  That's why people should be very careful to show us the exact code they are testing, not just re-type what they think they are using.
     
    Also, as I tried to hint at in my previous post, _delay works if you give it an argument, for example
    _delay(100);

    What I don't see is how the heck using _delay() with no argument can give the error message reported in the first post.
    A prototype for _delay with an argument is declared in pic.h or pic18.h depending on the processor used.
    [Edit]
    And the appropriate one of those is automatically included when you #include <xc.h>
    [/Edit]
     
    With XC8 version 2.05 in C99 mode invoking _delay() with no argument in a PIC16 MCC project gives me the compiler error
    main.c:110:12: error: too few arguments to function call, expected 1, have 0
        _delay();
        ~~~~~~ ^
    /opt/microchip/xc8/v2.05/pic/include/pic.h:92:1: note: '_delay' declared here
    extern __nonreentrant void _delay(unsigned long);


    A similar, but slightly less informative, error message occurs for the C90 mode.
     
    Both modes accept and generate viable code for _delay(100);
     
    It seems to me that to get the error reported in the original post, one would have to, somehow, get the compiler to accept the function invocation with no arguments.  I don't know how the heck you could do that, and that's why I asked the question the way I did
     
    Regards,

    Dave
     
    post edited by davekw7x - 2019/03/25 12:21:47

    Sometimes I just can't help myself...
    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5