微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MPLAB X XC8 错误:0:(499) 未定义符号VS 代码

如何解决MPLAB X XC8 错误:0:(499) 未定义符号VS 代码

我是 C 编码的新手,我无法找出将我的文件链接在一起的正确方法,以便我可以在另一个类中使用来自一个类的代码。我正在做一个可能会成为一个很长的程序的项目,所以我试图避免用一堆函数弄乱我的主类。相反,我希望将它们分开,以便将代码转移到任何未来的项目中。

通过查找类似的问题,我假设这有点简单,而且我可能为此苦苦挣扎,因为我缺少 C 中编码的基础知识。

这是终端显示内容

> Executing task in folder Led-Pot_Circuit_Test: .\Build.cmd 16f887 <


C:\Users\raymu_000\Documents\Programming\VisualStudioCode\PIC_C++_on_VSCode\Led-Pot_Circuit_Test>mkdir output-files
A subdirectory or file output-files already exists.

C:\Users\raymu_000\Documents\Programming\VisualStudioCode\PIC_C++_on_VSCode\Led-Pot_Circuit_Test>C:\Progra~1\microchip\xc8\v2.32\bin\xc8.exe --chip=16f887 --outdir=".\output-files" ".\main.c"
C:\Progra~1\microchip\xc8\v2.32\pic\bin\picc --chip=16f887 --outdir=.\output-files .\main.c
microchip MPLAB XC8 C Compiler V2.32
Build date: Feb  1 2021
Part Support Version: 2.32
copyright (C) 2021 microchip Technology Inc.
License type: Node Configuration

0: (499) undefined symbol:
        _adc_convert(output-files\main.obj)
(908) exit status = 1
(908) exit status = 1

C:\Users\raymu_000\Documents\Programming\VisualStudioCode\PIC_C++_on_VSCode\Led-Pot_Circuit_Test>C:\Progra~1\microchip\xc8\v2.32\bin\xc8.exe --chip=16f887 --outdir=".\output-files" ".\Project\InitApp.c"
C:\Progra~1\microchip\xc8\v2.32\pic\bin\picc --chip=16f887 --outdir=.\output-files .\Project\InitApp.c
microchip MPLAB XC8 C Compiler V2.32
Build date: Feb  1 2021
Part Support Version: 2.32
copyright (C) 2021 microchip Technology Inc.
License type: Node Configuration

Non line specific message: (1091) main function "_main" not defined
(908) exit status = 1
(908) exit status = 1
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command .\Build.cmd 16f887" terminated with exit code: 1.

Terminal will be reused by tasks,press any key to close it.

我的主要课程:

//main.c

// CONfig1
#pragma config FOSC = INTRC_NOCLKOUT// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin,I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input,MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FcmeN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O,HV on MCLR must be used for programming)

// CONfig2
#pragma config BOR4V = BOR21V   // brown-out Reset Selection bit (brown-out Reset set to 2.1V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

#define _XTAL_FREQ 8000000 // 8Mhz

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <pic16f887.h>
#include "Project\user.h"


void main(void) {

    //InitApp();

    unsigned short adc_value; // variable to hold ADC conversion result in/* Configure the oscillator for the device

    ANSELbits.ANS0 = 0; // disable analog on pin RA0
    TRISAbits.TRISA0 = 0; // Set pin RA0 as output

    while(1) {
        PORTAbits.RA0 = 0; // Set RA0 to LOW
        // calculate wait time
        adc_value = adc_convert(1); // perform A/D conversion using input from channel 1 (AN1)
        __delay_ms(500); // Right shift adc_value two spaces to convert to milliseconds
        PORTAbits.RA0 = 1; // Set RA0 to HIGH
        adc_value = adc_convert(1);
        __delay_ms(500);
    }
}

这是我尝试制作一个库,以便我以后可以“轻松”将一些有用的代码转移到另一个项目中:

//user.h

#ifndef USER_H
#define USER_H

void init_adc(void);
unsigned short adc_convert(unsigned char);

#endif

有用的代码

//InitApp.c

#include <xc.h>
#include <pic16f887.h>
#include "user.h"

/*
 Initialize the Analog to Digital Converter
 */
void init_adc(void) {
    TRISAbits.TRISA1 = 0b1; // Set pin RA1 as Input
    //ANCON0bits.ANSEL1   =0b1;
    ADCON1bits.VCFG0 = 0; // set v+ reference to Vdd
    ADCON1bits.VCFG1 = 0; // set v- reference to Vss (Gnd)
    ADCON1bits.ADFM = 1; // right justify the output
    ADCON0bits.ADCS = 0b01; // use Fosc/8 for clock source
    ADCON0bits.ADON = 1; // turn on the ADC
}

/*
 Preform an analog to digital conversion. 
@param channel The ADC input channel to use. 
@return The value of the conversion.
*/
unsigned short adc_convert(unsigned char channel) {
    ADCON0bits.CHS = channel; // select the given channel
    ADCON0bits.GO = 1; // start the conversion
    while(ADCON0bits.GO_DONE); // wait for the conversion to finish
    return(ADRESH<<8)|ADRESL; // return the result
}

图片供参考:

enter image description here

这是“输出文件文件夹的内容,当我运行“Build.cmd”任务时,编译器中的所有文件都放在这里,但我缺少一些(如“.hex”文件),因为程序无法正确编译。

enter image description here

我需要在 InitApp.c 类中有一个主类吗? 如何正确编译和链接 C 文件

感谢艾米的帮助和建议,谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?