Electronic – I2C Implementation on PIC error

i2cpic

I am referencing this project: http://www.8051projects.net/wiki/I2C_Implementation_on_PIC

I am using PIC16F1847 and XC8 as opposed to PIC16F877 and HiTech C so I've had to make a few changes to the code. After making changes, my compiler gave me an error for the I2CWait function for the while statement. It says "unexpected token amp".

Here is the line in question:

while ((SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );

I changed the register names to be consistent with my PIC's registers (below) but it didn't solve the problem.

while ((SSP1CON2 & 0x1F ) || ( SSP1STAT & 0x04 ) );

What changes do I need to make to this function so that this error does not occur?

[ Edited Wed Jun 29 2016, 03:37 PM ]

Best Answer

while ((SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );

That is a website (HTML encoding) mistake and will never work, as it is invalid "C". That line should read:

while ((SSPCON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );

I can't speak to the correctness of the code overall on that webpage you quoted, but you will find many webpages discussing code, which includes the corrected line that I have given.

Related Topic