TomF 0 Posted October 29, 2007 Report Share Posted October 29, 2007 Hi, Attempting to check for a bit in GPIO being set: if( gpio & (1 << 5) == (1 << 5) ) { set_bit(gpio, PIN_TRIAC); // bit is set } else { clear_bit(gpio, PIN_TRIAC); // bit is clear } if( gpio & (1 << 5) == (1<<5) ) 002E 1C05 BTFSS gbl_gpio,0 002F 2832 GOTO label268439188 0032 label268439188 { set_bit(gpio, PIN_TRIAC); 0030 1505 BSF gbl_gpio,2 } else 0031 282E GOTO label268439185 { clear_bit(gpio, PIN_TRIAC); 0032 1105 BCF gbl_gpio,2 } This does not work, the code below does work as expected: if( (gpio & (1 << 5)) == (1<<5) ) { set_bit(gpio, 1);// bit is set } else { clear_bit(gpio, 1);// bit is clear } if( (gpio & (1 << 5)) == (1<<5) ) 002E 3020 MOVLW 0x20 002F 0505 ANDWF gbl_gpio, W 0030 3A20 XORLW 0x20 0031 1D03 BTFSS STATUS,Z 0032 2835 GOTO label268439188 0035 label268439188 { set_bit(gpio, PIN_TRIAC); 0033 1505 BSF gbl_gpio,2 } else 0034 282E GOTO label268439185 { clear_bit(gpio, PIN_TRIAC); 0035 1105 BCF gbl_gpio,2 } Is this a bug? Im using 12F683, and BoostC 6.81 - Everything on the left of the == operator should be evaluated as a whole, so the resultant should be the same in both cases, which by looking at the .casm files (when added to the project, this files gets placed in the source dir rather than the output dir, another bug?) the generated ASM is different?? Quote Link to post Share on other sites
Pavel 0 Posted October 29, 2007 Report Share Posted October 29, 2007 See no error here. Here is a link to C operator precedence table http://www.difranco.net/cop2220/op-prec.htm The equal to peration has higher precedence than bitwise and and is evaluated first. Regards, Pavel 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.