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 ]

  • \$\begingroup\$ Compiler talk to You very clearly: "unexpected token amp". \$\endgroup\$ Jun 29, 2016 at 21:13
  • 1
    \$\begingroup\$ This is a good example of why copying/pasting code without understanding it has its pitfalls. \$\endgroup\$
    – uint128_t
    Jun 30, 2016 at 0:30

1 Answer 1


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.

  • \$\begingroup\$ @dyoussef - Of course you make the corresponding change to the second example that you gave, if you need those different register names. Good luck! \$\endgroup\$
    – SamGibson
    Jun 29, 2016 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.