【问题标题】:#include <xc.h> not accepted#include <xc.h> 不被接受
【发布时间】:2020-07-02 20:29:37
【问题描述】:

我正在尝试对 PIC 微控制器进行编程,但是,每次我尝试包含 时,我都会不断收到相同的错误,“未在包含文件中解析”。

这是我正在尝试的:

#include <stdio.h>
#include "Header.h"

#define _XTAL_FREQ 4000000

int main(void)
{

}

请注意,#include "Header.h" 内部是我的#pragma 和#include ,它们一直被识别为错误。有谁知道为什么 #include 一直这样失败?我也尝试将它直接包含在源文件中,但没有任何改变。

根据要求,我包含了头文件的内容,“Header.h”(多么有创意),我不建议阅读所有#pragma,它非常狭窄:

// PIC24EP32MC202 Configuration Bit Settings

// 'C' source line config statements

// FICD
#pragma config ICS = PGD1               // ICD Communication Channel Select bits (Communicate on PGEC1 and PGED1)
#pragma config JTAGEN = OFF             // JTAG Enable bit (JTAG is disabled)

// FPOR
#pragma config ALTI2C1 = OFF            // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
#pragma config ALTI2C2 = OFF            // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
#pragma config WDTWIN = WIN25           // Watchdog Window Select bits (WDT Window is 25% of WDT period)

// FWDT
#pragma config WDTPOST = PS32768        // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128           // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = ON              // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = ON              // Watchdog Timer Enable bit (Watchdog timer always enabled)

// FOSC
#pragma config POSCMD = NONE            // Primary Oscillator Mode Select bits (Primary Oscillator disabled)
#pragma config OSCIOFNC = OFF           // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = ON             // Peripheral pin select configuration (Allow only one reconfiguration)
#pragma config FCKSM = CSDCMD           // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are disabled)

// FOSCSEL
#pragma config FNOSC = FRCDIVN          // Oscillator Source Selection (Internal Fast RC (FRC) Oscillator with postscaler)
#pragma config PWMLOCK = ON             // PWM Lock Enable bit (Certain PWM registers may only be written after key sequence)
#pragma config IESO = ON                // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)

// FGS
#pragma config GWRP = OFF               // General Segment Write-Protect bit (General Segment may be written)
#pragma config GCP = OFF                // General Segment Code-Protect bit (General Segment Code protect is Disabled)

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

#include <xc.h>

【问题讨论】:

  • #include &lt;xc.h&gt; 仅在 xc.h 位于包含路径中时才有效。你试过#include "xc.h"吗?或者您可能没有正确安装完整的库套件。
  • 正如@WeatherVane 指出的初步想法是“头文件不在默认搜索路径中”。但是您的这一点“我也尝试将其直接包含在源文件中,但没有任何改变。”表示问题是别的。为什么不分享xc.h 头文件中的内容?谢谢。
  • @MohithReddy 我认为这意味着 OP 已将 #include &lt;xc.h&gt; 放入 .c 文件而不是其他头文件中——而不是复制/粘贴标题内容。
  • 请发布您尝试编译此文件时编译器打印的everything完整且未修改文本。我怀疑错误消息并不代表您的想法,但我需要确切地查看它所说的内容。
  • @Damascus 请尝试编译代码。有时,红色波浪线是由于编译器和您的开发工具不匹配而导致的误报。

标签: c microchip


【解决方案1】:

这是你应该开始的方式:

#include <xc.h>
#include <stdio.h>
#include "Header.h"

#define _XTAL_FREQ 4000000

int main(void)
{

}

并从您的文件 Header.h 中删除 #include &lt;xc.h&gt;

【讨论】:

  • 你知道为什么必须先包含它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-11
  • 2021-12-07
  • 2012-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多