gpt4 book ai didi

C程序编译错误(带头文件)

转载 作者:行者123 更新时间:2023-11-30 17:51:40 24 4
gpt4 key购买 nike

这是我的头文件代码。

头文件名16f877a.h

其代码为from this link

我的文件名led.c

#include "16f877a.h" //IC selection
#fuses XT, NOWDT, NOPROTECT, NOLVP
#use delay (clock =20000000) //clock 20MHz
void main(){
while(1){
output_B(0xff); //hex to binary output on port B
delay_us(500); // delay = 500 x clock period.
output_B(0x00);
delay_us(500);
}
}

这些文件位于同一文件夹

/home/company/Documents/CCPP/PIC/LedProject

我使用UBUNTU 12.04。使用gcc我编译了一个简单的hello world程序并且它运行正确。这是我在终端中的命令历史记录

mkdir -p PIC/LedProject
cd PIC/LedProject/
gedit led.c
gcc -Wall -W -Werror led.c -o LedProC

这是我的错误。请帮我解决这个问题

In file included from led.c:1:0:
16f877a.h:91:0: error: ignoring #pragma maxram [-Werror=unknown-pragmas]
16f877a.h:99:0: error: ignoring #pragma memmap INDF_ADDR [-Werror=unknown-pragmas]
16f877a.h:100:0: error: ignoring #pragma memmap TMR0_ADDR [-Werror=unknown-pragmas]
16f877a.h:101:0: error: ignoring #pragma memmap PCL_ADDR [-Werror=unknown-pragmas]
16f877a.h:102:0: error: ignoring #pragma memmap STATUS_ADDR [-Werror=unknown-pragmas]
16f877a.h:103:0: error: ignoring #pragma memmap FSR_ADDR [-Werror=unknown-pragmas]
16f877a.h:104:0: error: ignoring #pragma memmap PORTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:105:0: error: ignoring #pragma memmap PORTB_ADDR [-Werror=unknown-pragmas]
16f877a.h:106:0: error: ignoring #pragma memmap PORTC_ADDR [-Werror=unknown-pragmas]
16f877a.h:107:0: error: ignoring #pragma memmap PORTD_ADDR [-Werror=unknown-pragmas]
16f877a.h:108:0: error: ignoring #pragma memmap PORTE_ADDR [-Werror=unknown-pragmas]
16f877a.h:109:0: error: ignoring #pragma memmap PCLATH_ADDR [-Werror=unknown-pragmas]
16f877a.h:110:0: error: ignoring #pragma memmap INTCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:111:0: error: ignoring #pragma memmap PIR1_ADDR [-Werror=unknown-pragmas]
16f877a.h:112:0: error: ignoring #pragma memmap PIR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:113:0: error: ignoring #pragma memmap TMR1L_ADDR [-Werror=unknown-pragmas]
16f877a.h:114:0: error: ignoring #pragma memmap TMR1H_ADDR [-Werror=unknown-pragmas]
16f877a.h:115:0: error: ignoring #pragma memmap T1CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:116:0: error: ignoring #pragma memmap TMR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:117:0: error: ignoring #pragma memmap T2CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:118:0: error: ignoring #pragma memmap SSPBUF_ADDR [-Werror=unknown-pragmas]
16f877a.h:119:0: error: ignoring #pragma memmap SSPCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:120:0: error: ignoring #pragma memmap CCPR1L_ADDR [-Werror=unknown-pragmas]
16f877a.h:121:0: error: ignoring #pragma memmap CCPR1H_ADDR [-Werror=unknown-pragmas]
16f877a.h:122:0: error: ignoring #pragma memmap CCP1CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:123:0: error: ignoring #pragma memmap RCSTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:124:0: error: ignoring #pragma memmap TXREG_ADDR [-Werror=unknown-pragmas]
16f877a.h:125:0: error: ignoring #pragma memmap RCREG_ADDR [-Werror=unknown-pragmas]
16f877a.h:126:0: error: ignoring #pragma memmap CCPR2L_ADDR [-Werror=unknown-pragmas]
16f877a.h:127:0: error: ignoring #pragma memmap CCPR2H_ADDR [-Werror=unknown-pragmas]
16f877a.h:128:0: error: ignoring #pragma memmap CCP2CON_ADDR [-Werror=unknown-pragmas]
16f877a.h:129:0: error: ignoring #pragma memmap ADRESH_ADDR [-Werror=unknown-pragmas]
16f877a.h:130:0: error: ignoring #pragma memmap ADCON0_ADDR [-Werror=unknown-pragmas]
16f877a.h:131:0: error: ignoring #pragma memmap OPTION_REG_ADDR [-Werror=unknown-pragmas]
16f877a.h:132:0: error: ignoring #pragma memmap TRISA_ADDR [-Werror=unknown-pragmas]
16f877a.h:133:0: error: ignoring #pragma memmap TRISB_ADDR [-Werror=unknown-pragmas]
16f877a.h:134:0: error: ignoring #pragma memmap TRISC_ADDR [-Werror=unknown-pragmas]
16f877a.h:135:0: error: ignoring #pragma memmap TRISD_ADDR [-Werror=unknown-pragmas]
16f877a.h:136:0: error: ignoring #pragma memmap TRISE_ADDR [-Werror=unknown-pragmas]
16f877a.h:137:0: error: ignoring #pragma memmap PIE1_ADDR [-Werror=unknown-pragmas]
16f877a.h:138:0: error: ignoring #pragma memmap PIE2_ADDR [-Werror=unknown-pragmas]
16f877a.h:139:0: error: ignoring #pragma memmap PCON_ADDR [-Werror=unknown-pragmas]
16f877a.h:140:0: error: ignoring #pragma memmap SSPCON2_ADDR [-Werror=unknown-pragmas]
16f877a.h:141:0: error: ignoring #pragma memmap PR2_ADDR [-Werror=unknown-pragmas]
16f877a.h:142:0: error: ignoring #pragma memmap SSPADD_ADDR [-Werror=unknown-pragmas]
16f877a.h:143:0: error: ignoring #pragma memmap SSPSTAT_ADDR [-Werror=unknown-pragmas]
16f877a.h:144:0: error: ignoring #pragma memmap TXSTA_ADDR [-Werror=unknown-pragmas]
16f877a.h:145:0: error: ignoring #pragma memmap SPBRG_ADDR [-Werror=unknown-pragmas]
16f877a.h:146:0: error: ignoring #pragma memmap ADRESL_ADDR [-Werror=unknown-pragmas]
16f877a.h:147:0: error: ignoring #pragma memmap ADCON1_ADDR [-Werror=unknown-pragmas]
16f877a.h:148:0: error: ignoring #pragma memmap EEDATA_ADDR [-Werror=unknown-pragmas]
16f877a.h:149:0: error: ignoring #pragma memmap EEADR_ADDR [-Werror=unknown-pragmas]
16f877a.h:150:0: error: ignoring #pragma memmap EEDATH_ADDR [-Werror=unknown-pragmas]
16f877a.h:151:0: error: ignoring #pragma memmap EEADRH_ADDR [-Werror=unknown-pragmas]
16f877a.h:152:0: error: ignoring #pragma memmap EECON1_ADDR [-Werror=unknown-pragmas]
16f877a.h:153:0: error: ignoring #pragma memmap EECON2_ADDR [-Werror=unknown-pragmas]
16f877a.h:206:1: error: unknown type name ‘data’
16f877a.h:206:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:207:1: error: unknown type name ‘sfr’
16f877a.h:207:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:208:1: error: unknown type name ‘data’
16f877a.h:208:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:209:1: error: unknown type name ‘sfr’
16f877a.h:209:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before numeric constant
16f877a.h:267:1: error: unknown type name ‘sbit’
16f877a.h:267:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
16f877a.h:268:1: error: unknown type name ‘sbit’
16f877a.h:485:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
16f877a.h:486:1: error: unknown type name ‘sbit’
16f877a.h:486:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
led.c:2:2: error: invalid preprocessing directive #fuses
led.c:3:2: error: invalid preprocessing directive #use
led.c:4:6: error: return type of ‘main’ is not ‘int’ [-Werror=main]
led.c: In function ‘main’:
led.c:6:3: error: implicit declaration of function ‘output_B’ [-Werror=implicit-function-declaration]
led.c:7:3: error: implicit declaration of function ‘delay_us’ [-Werror=implicit-function-declaration]
cc1: all warnings being treated as errors
bellvantage@BVPC00024:~/Documents/CCPP/PIC/LedProject$ mkdir -p PIC/LedProject
bellvantage@BVPC00024:~/Documents/CCPP/PIC/LedProject$ cd PIC/LedProject/
bellvantage@BVPC00024:~/Documents/CCPP/PIC/LedProject/PIC/LedProject$ gedit led.c
bellvantage@BVPC00024:~/Documents/CCPP/PIC/LedProject/PIC/LedProject$ gcc -Wall -W -Werror led.c -o LedProC
gcc: error: led.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

我指的是this blog对于我的电路

最佳答案

您使用的源代码并非严格意义上的 C,而是包含许多预处理器命令的扩展,例如

#fuses XT, NOWDT, NOPROTECT, NOLVP
#use delay (clock =20000000) //clock 20MHz

这些用于配置 PIC 处理器。这种类 C 语言的编译器具有对诸如

之类的函数的内置理解
delay_us()

您使用的兼容 C 编译器 (gcc) 不了解 fusion、delay_us 等,因此声明了许多错误。

如果您的目标是使用这种类型的 C 对 PIC 进行编程 - 我认为是这样,请访问 MicroChip、CCS 或其他地方并获取他们的 PIC C > 编译器。

如果您的目标是在 UBUNTU 机器上使用 gcc 进行编程,请不要使用为 PIC 设计的代码。

顺便说一句:可能存在可以在您的 UBUNTU 上编译的 PIC 交叉编译器,但我不知道。

搜索gcc PIC交叉编译器的问题,你可能会找到答案。

关于C程序编译错误(带头文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16580141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com