gpt4 book ai didi

c - XC8 寄存器声明冲突(例如 TRIS、SSP1CON1 等)

转载 作者:太空宇宙 更新时间:2023-11-04 08:07:12 24 4
gpt4 key购买 nike

我是新来的。我正在使用 Microchip 的 XC8 编译器和 PIC18F25K22。当我构建代码时,出现错误

xc8.exe --pass1 --errformat="Error at file %%f line %%l column %%c: (%%n) %%s" --warnformat="Warning at file %%f line %%l column %%c: (%%n) %%s" --msgformat="Message at file %%f line %%l column %%c: (%%n) %%s" -G --chip=18F25K22  -O"main.p1" "../main.c"
Microchip MPLAB XC8 C Compiler (Free Mode) V1.37
Build date: Mar 10 2016
Part Support Version: 1.37
Copyright (C) 2016 Microchip Technology Inc.
License type: Node Configuration

Warning at file line column : (1273) Omniscient Code Generation not available in Free mode
Error at file ../i2clcd.c line 11 column 8: (195) expression syntax
Error at file ../i2clcd.c line 11 column 8: (312) ";" expected
Error at file ../i2clcd.c line 11 column 12: (285) no identifier in declaration
Error at file ../i2clcd.c line 11 column 12: (314) ";" expected
Error at file ../i2clcd.c line 14 column 10: (195) expression syntax
Error at file ../i2clcd.c line 14 column 10: (312) ";" expected
Error at file ../i2clcd.c line 14 column 14: (285) no identifier in declaration
Error at file ../i2clcd.c line 14 column 14: (314) ";" expected
Warning at file ../i2clcd.c line 23 column 1: (361) function declared implicit int
Error at file ../i2clcd.c line 51 column 11: (195) expression syntax
Error at file ../i2clcd.c line 51 column 11: (312) ";" expected
Error at file ../i2clcd.c line 51 column 15: (285) no identifier in declaration
Error at file ../i2clcd.c line 51 column 15: (314) ";" expected
Error at file ../i2clcd.c line 84 column 1: (192) undefined identifier "lcddata"
Error at file ../i2c.c line 10 column 1: (1098) conflicting declarations for variable "I2C_INIT" (../i2c.c:9)
(908) exit status = 1
make: *** [main.p1] Error 1

Error code 2

如果我将此代码行注释掉,我会在下一个注册命令(在我的例子中是:SSP1CON1)中收到错误 - 我试过包含 xc.h和 htc.h 但也有同样的错误。

我在stackoverflow上发现了一个类似的问题,但是通过把这些命令放在一个函数中解决了这个问题,但是我的是在一个函数中。

这是我的代码:

#include "i2c.h"
#include <xc.h>
#include <htc.h>
/*
* subroutine: I2C_INIT()
* access from: main.c/BOOT()
* description: Initialisises MSSP port for I2C Master-Mode
*/
void I2C_INIT(0)
{
TRISCbits.TRISC3=1; //config SCL-Line as Input;
TRISCbits.TRISC4=1; //config SDA-Line as Input;

SSP1CON1 = 0b00101000;
/*
* bit 5: Enables the serial port and configures the SDA and SCL pins as the
* source of the serial port pins
*bit 0-3: 1000: I2C Master Mode, clock = FOSC/(4*(SSPASS+1))
*/

SSP1CON2 = 0x00;

SSP1ADD = 39; //clock = FOSC/(4*(SSPASS+1)) - 100 kHz @ 16MHz FOSC
SSP1STAT = 0b11000000;
/*
* bit 7: Slew rate control disabled for standard speed mode (100 kHz and 1 MHz)
* bit 6: Data transmitted on rising edge of SCK
*/
}

最佳答案

所有寄存器声明( SSP1CON1TRISCbits 等,都在 xc.h 中声明(并且它是嵌套的包含)。您的问题可能是 i2c.h 中的代码包含引用出现在xc.h

尝试颠倒您的包含顺序,将系统包含放在您自己的(或第三方)包含之前。

一般来说,您应该始终将所有系统包含(即用 <> 指定文件的那些)放在您自己的(用“”)之前。

关于c - XC8 寄存器声明冲突(例如 TRIS、SSP1CON1 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41943430/

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