• AVR Freaks

Hot!PIC16LF15313 MPLAB Help

Author
cbwelch
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2019/11/08 14:19:29
  • Location: 0
  • Status: offline
2019/11/12 18:44:21 (permalink)
0

PIC16LF15313 MPLAB Help

I am trying to build a project and keep running into problems. "number of arguments passed to function "___delay_ms" does not match function's prototype. How do I fix this? The goal is to read an analog voltage from port 0, and if it is above a certain value, pass high at port 1. Does the code make sense? This is my first project, I would appreciate any feedback.
 
#include "xc.h"
#include "PIC16LF15313.h"
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)

#define _XTAL_FREQ 1000000
 
unsigned int ADC_read(unsigned char channel){
ADCON1 = 0x60; //Left justify, Fosc/64, Vref connected to Vdd
ADCON0 = 0x01; //Turns on ADC and selects AN0
__delay_ms(2); //need to wait acquisition time, 2ms is a safe assumption
GOnDONE = 1; //start conversion
while(GOnDONE); //waits until the conversion is complete
return ((ADRESH<<2) + (ADRESL>>6)); //digital result, 10 bit char
}
void main() {
unsigned int a;
TRISA = 0x01; //RA 0 input; RA 1, 2, 3, 4 output
PORTA = 0x00; //All set to low, AN 2, 3, 4 will be not used
ANSELA = 0x01; //Channel A0 analog
OSCCON1 = 0x70; //Set internal oscillation to 4MHz
while(1){ //infinite loop
a = ADC_read(0); //read channel 0
if (a >= (0x12C)) {
RA1 = 1; //passes high, operating in synchronous
}
else{
RA1 = 0; //passes low, operating in asynchronous
}
__delay_ms(1000); //waits a second to read input again
}
}
#1

14 Replies Related Threads

    mpgmike
    Super Member
    • Total Posts : 332
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 09:02:59 (permalink)
    +1 (1)

    __delay_ms(2); //need to wait acquisition time, 2ms is a safe assumption
    GOnDONE = 1; //start conversion
    while(GOnDONE); //waits until the conversion is complete
    return ((ADRESH<<2) + (ADRESL>>6)); //digital result, 10 bit char

    These lines are obviously functional in nature, yet reside nowhere inside any defined function.  You haven't started main() yet, nor have you put them inside any other function.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #2
    pcbbc
    Super Member
    • Total Posts : 1388
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 09:10:12 (permalink)
    0
    mpgmike
    These lines are obviously functional in nature, yet reside nowhere inside any defined function.  You haven't started main() yet, nor have you put them inside any other function.



    What's this then?
    unsigned int ADC_read(unsigned char channel){
        ....
    }

     
    I agree if the OP had used [​code]//code tags around his code[​/code] it would be a whole lot easier to read...
    #3
    pcbbc
    Super Member
    • Total Posts : 1388
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 09:12:24 (permalink)
    +1 (1)
    Tidy up indentation and used [​code]//code tags around his code[​/code]....
    #include "xc.h"
    #include "PIC16LF15313.h"
    #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
    #pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)

    #define _XTAL_FREQ 1000000
     
    unsigned int ADC_read(unsigned char channel){
        ADCON1 = 0x60; //Left justify, Fosc/64, Vref connected to Vdd
        ADCON0 = 0x01; //Turns on ADC and selects AN0
        __delay_ms(2); //need to wait acquisition time, 2ms is a safe assumption
        GOnDONE = 1; //start conversion
        while(GOnDONE); //waits until the conversion is complete
        return ((ADRESH<<2) + (ADRESL>>6)); //digital result, 10 bit char
    }

    void main() {
        unsigned int a;
        TRISA = 0x01; //RA 0 input; RA 1, 2, 3, 4 output
        PORTA = 0x00; //All set to low, AN 2, 3, 4 will be not used
        ANSELA = 0x01; //Channel A0 analog
        OSCCON1 = 0x70; //Set internal oscillation to 4MHz
        while(1){ //infinite loop
            a = ADC_read(0); //read channel 0
            if (a >= (0x12C)) {
                RA1 = 1; //passes high, operating in synchronous
            } else {
                RA1 = 0; //passes low, operating in asynchronous
            }
            __delay_ms(1000); //waits a second to read input again
        }
    }

     
    #4
    mpgmike
    Super Member
    • Total Posts : 332
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 09:30:11 (permalink)
    0
    Now I see it.  That brings to my attention:

    unsigned int ADC_read(unsigned char channel){

    The first part, "unsigned int" states that the result of this function will return an unsigned int as the result.
     
    "(unsigned char channel){" states that when you call the function you will be passing an unsigned char variable that the function will do something with.  Yet, nowhere within the function "ADC_read();" do you use "channel", nor do you pass anything to this function when you call it.  Try:

    unsigned int ADC_read(void) {


    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #5
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 12:50:04 (permalink)
    +1 (1)
    ... and get rid of
    #include "PIC16LF15313.h"

    the line above has already included the same file.


    i.e. you only ever need <xc.h>, not the device specific header file.

    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!
    #6
    cbwelch
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2019/11/08 14:19:29
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 16:43:56 (permalink)
    0
    Thank you mpgmike & ric, I fixed those issues but am still getting the following error when trying to build the project:
     
    warning: (1518) direct function call made with an incomplete prototype (__delay_ms)
    warning: (1464) number of arguments passed to function "___delay_ms" does not match function's prototype
    warning: (1518) direct function call made with an incomplete prototype (__delay_ms)
     warning: (1464) number of arguments passed to function "___delay_ms" does not match function's prototype
    :0:: error: (499) undefined symbol:
     
     
    #7
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 16:56:01 (permalink)
    +1 (1)
    Which version of XC8 are you using?
    If it is version 2.xx, which "mode" is it in? ("C90", or "C99")

    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
    cbwelch
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2019/11/08 14:19:29
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 21:05:35 (permalink)
    0
    Version 2.10 and C99 mode
    #9
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 21:19:36 (permalink)
    +1 (1)
    Maybe try reinstalling the compiler.
    I just tried both versions of your code
    (i.e. from post#1 and post#4)
    and they both compile fine with no warnings or errors.
    This is using MPLABX 5.30, XC8 v2.10 and C99 mode.
     

    CLEAN SUCCESSFUL (total time: 19ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'C:/temp/code/16f15313/16f15313.X'
    make  -f nbproject/Makefile-default.mk dist/default/production/16f15313.X.production.hex
    make[2]: Entering directory 'C:/temp/code/16f15313/16f15313.X'
    "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe"  -mcpu=16LF15313 -c    -fno-short-double -fno-short-float -O0 -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default  -msummary=-psect,-class,+mem,-hex,-file  -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall   -std=c99 -gdwarf-3 -mstack=compiled:auto:auto     -o build/default/production/newmain.p1 newmain.c
    "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe"  -mcpu=16LF15313 -Wl,-Map=dist/default/production/16f15313.X.production.map  -DXPRJ_default=default  -Wl,--defsym=__MPLAB_BUILD=1    -fno-short-double -fno-short-float -O0 -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file  -ginhx032 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto      -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/16f15313.X.production.elf  build/default/production/newmain.p1     

    Memory Summary:
        Program space        used    5Bh (    91) of   800h words   (  4.4%)
        Data space           used     Fh (    15) of   100h bytes   (  5.9%)
        EEPROM space         None available
        Data stack space     used     0h (     0) of    F0h bytes   (  0.0%)
        Configuration bits   used     3h (     3) of     5h words   ( 60.0%)
        ID Location space    used     0h (     0) of     4h bytes   (  0.0%)

    make[2]: Leaving directory 'C:/temp/code/16f15313/16f15313.X'
    make[1]: Leaving directory 'C:/temp/code/16f15313/16f15313.X'

    BUILD SUCCESSFUL (total time: 2s)
    Loading code from C:/temp/code/16f15313/16f15313.X/dist/default/production/16f15313.X.production.hex...
    Loading completed


    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!
    #10
    cbwelch
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2019/11/08 14:19:29
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 22:01:59 (permalink)
    0
    Reinstalled and I'm still getting the same error code as my most recent post. I'm using iOS, would this affect this? Also in your code it same 16f15313 instead of 16lf15313, not sure if that makes a difference.
     
    Side note: regardless of the errors, can I use the delay functions without an external oscillator crystal?
     
    Thanks for your help thus far.
    #11
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 22:07:10 (permalink)
    0
    cbwelch
    Reinstalled and I'm still getting the same error code as my most recent post. I'm using iOS, would this affect this?

    I wouldn't have thought so, but I don't know.
     

    Also in your code it same 16f15313 instead of 16lf15313, not sure if that makes a difference.

    I had it set for PIC16LF15313. It's just the folder name you're looking at.
     

    Side note: regardless of the errors, can I use the delay functions without an external oscillator crystal?

    Yes you can.
     

    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!
    #12
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 22:31:00 (permalink)
    +1 (1)
    Please try this version. This is the post#4 version, but with line#1 changed, and line#2 deleted
    #include <xc.h>

    #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
    #pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored)

    #define _XTAL_FREQ 1000000
     
    unsigned int ADC_read(unsigned char channel){
        ADCON1 = 0x60; //Left justify, Fosc/64, Vref connected to Vdd
        ADCON0 = 0x01; //Turns on ADC and selects AN0
        __delay_ms(2); //need to wait acquisition time, 2ms is a safe assumption
        GOnDONE = 1; //start conversion
        while(GOnDONE); //waits until the conversion is complete
        return ((ADRESH<<2) + (ADRESL>>6)); //digital result, 10 bit char
    }

    void main() {
        unsigned int a;
        TRISA = 0x01; //RA 0 input; RA 1, 2, 3, 4 output
        PORTA = 0x00; //All set to low, AN 2, 3, 4 will be not used
        ANSELA = 0x01; //Channel A0 analog
        OSCCON1 = 0x70; //Set internal oscillation to 4MHz
        while(1){ //infinite loop
            a = ADC_read(0); //read channel 0
            if (a >= (0x12C)) {
                RA1 = 1; //passes high, operating in synchronous
            } else {
                RA1 = 0; //passes low, operating in asynchronous
            }
            __delay_ms(1000); //waits a second to read input again
        }
    }

     

    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
    cbwelch
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2019/11/08 14:19:29
    • Location: 0
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/13 23:48:53 (permalink)
    0
    Thank you very much! I appreciate your help ric.
    #14
    mlp
    boots too small
    • Total Posts : 825
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: PIC16LF15313 MPLAB Help 2019/11/14 08:45:58 (permalink)
    0
    cbwelch
    I'm using iOS

    I doubt this is relevant, as "iOS" is the operating system software for Apple's phone and tablet devices (and "IOS" is for Cisco routers), and neither XC8 nor MPLAB X run in that environment.
     
    But if you're using OSX on a Mac, you're using the same system as the XC8 developers.

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