C语言 XC8 寄存器冲突声明(例如 TRIS、SSP1CON1,..)



我是新来的。我正在使用XC8编译器和Microchip的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

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

通常,您应该始终将所有系统包含(即用 <> 指定文件的那些)放在您自己的(带有 " 的那些)之前。

相关内容

  • 没有找到相关文章

最新更新