I am new here. I am using the XC8 compiler and a PIC18F25K22 from Microchip. When I am building the code, I get the error
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
if I comment this code line out, I am getting the error with the next register command (in my case: SSP1CON1) - I tried it with including xc.h and htc.h but there is also the same error.
I found a similar problem in stackoverflow, but the problem was solved by putting these commands in a function, but mine are in a function.
Here is my code:
#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
*/
}
All the register declarations (SSP1CON1
, TRISCbits
, etc., are declared in xc.h
(and it's nested includes). Your problem may be that code in the i2c.h
include is referencing definitions that appear in xc.h
Try reversing the order of your includes to place the system includes before your own (or third-party) includes.
In general, you should always place all system includes (i.e. those where the file is specified with <>
) before your own (those with "").