Reynard 0 Posted November 23, 2007 Report Share Posted November 23, 2007 The code below gives errors: CaseTest.c(13): error: missing right brace CaseTest.c(10): error: missing semicolon CaseTest.c(10): error: failure It appears that the case statement constant does not like having the left shift operator in it. (It may not like the right shift operator either but have not tried it.) Replacing the I2C_STATE_1 definition with (0x09) works OK. #include <system.h> #define SSPSTAT_MASK (1 << D_A | 1 << S | 1 << R_W | 1 << BF) #define I2C_STATE_1 (1 << S | 1 << BF) // I2C write, last byte an address. void main(void) { } void I2C_SerialInterrupt(void) { pir1.SSPIF = false; // clear interrupt flag. switch (sspstat & SSPSTAT_MASK) { case (I2C_STATE_1): break; } // end switch. } void interrupt(void) { if (pir1.SSPIF) { // I2C interrupt ? I2C_SerialInterrupt(); // yes, process I2C interrupt. } } Using BoostC 6.81, PIC16F873A, WinXP Pro SP2. Cheers Reynard Quote Link to post Share on other sites
cac001 0 Posted November 29, 2007 Report Share Posted November 29, 2007 It looks like a bug when bit-wise operators are used in a case expression. /* File: bug21.C Target: PIC16F876A OS: WinXP, SP2 SourceBoostIDE: 6.81 Compiler: BoostC 6.81 Reproducible: always Expected behavior: compile without error Description: case statment reports a compile error when bit-wise operator is used in expression. "case (I2C_STATE_1):" reports an error "case ((1 << S | 1 << BF)):" reports an error "case (0x08 | 0x01):" reports an error changing #define for I2C_STATE_1 to an enum is a work around */ #include <system.h> #define SSPSTAT_MASK (1 << D_A | 1 << S | 1 << R_W | 1 << BF) //#define I2C_STATE_1 (1 << S | 1 << BF) enum { I2C_STATE_1 = (1 << S | 1 << BF) }; void main(void) { } void I2C_SerialInterrupt(void) { pir1.SSPIF = false; // clear interrupt flag. switch (sspstat & SSPSTAT_MASK) { // case ((1 << S | 1 << BF)): // case (0x08 | 0x01): case (I2C_STATE_1): break; } // end switch. } void interrupt(void) { if (pir1.SSPIF) { // I2C interrupt ? I2C_SerialInterrupt(); // yes, process I2C interrupt. } } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.