【发布时间】:2020-07-25 07:36:55
【问题描述】:
screenshot of my code and error data
这是我的 main.c 文件
#include "services_initialisations_prototype.h"
#include "services_functions_prototype.h"
void main(void)
{
initSfr();
while(1){
updateMatrix(404, 1);
}
return;
}
这是我的 services_initialisations_prototype.h
#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include <xc.h> // include processor files - each processor file is guarded.
#include <stdint.h>
//these are my function declarations
extern void initInterrupt();
extern void initIoc();
extern void initAdc();
extern void initTimer2();
extern void initSfr();
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */
这是我的 services_functions_prototype.h
#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include <xc.h> // include processor files - each processor file is guarded.
#include <stdint.h>
//these are my function declarations
extern void updateMatrix(int, int);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */
当我尝试在 MPLAB X IDE 4.05 版中包含两个头文件时,它似乎无法识别第二个头文件。我尝试交换订单,但仍然没有检测到第二个。
services_initialisation_prototype.h 包含 SFR 的初始化,services_functions_prototype.h 包含其他函数的原型。这些功能是相互独立的。
当我编译时,它显示
函数 updateMatrix() 被声明为隐式 int。 变量 _updateMatrix() 的声明冲突
这说明头文件services_functions_prototype没有被识别出来。
所附截图显示services_functions_prototype.h中的代码为灰色,似乎部分代码没有执行。
当我将整个声明从头文件复制到我的主文件时,它工作得非常好。
【问题讨论】:
-
请不要张贴错误信息图片的链接。请编辑您的帖子并将您的代码作为文本添加到您的帖子中。请发布minimal reproducible example。请在您的帖子中逐字包含错误消息作为文本。请花点时间研究How to Ask。我也推荐question checklist。 “不起作用”是什么意思?什么“不起作用”,以什么方式以及您如何知道?您是否阅读了错误消息?您做了哪些研究,结果如何?
-
本着本论坛的精神 - 您有问题要问吗?你的问题是什么?你在编译什么MCU? (而且您似乎正在使用免费版本的 xc8 编译器 - 我建议改用 sdcc,免费 xc8 总是很糟糕。如果您无缘无故使用 pic18*,我建议将它们放入垃圾箱并移至stm32 或 nrf 代替)。
-
@KamilCuk 我已经编辑了代码。当我将整个声明作为 extern 复制到我的主文件时,它工作正常。另外,我是一名学生,使用免费的编译器对我的作品来说已经足够了。我正在使用 pic16f1787。