Pic C18 basic question - if statement

Sep 07, 2010 5 Replies

I'm slugging away learning C / C18 using pics and have a problem.


I only want the code below to execute if (RCIF is set) AND (the value of gMode is 0x02).


With RCIF set (ie =1) and gMode = 0x03 the "if" code is entered as if gMode = 0x02 when I can set its value as 0x03 in a watch window.


volatile unsigned char gSDI12Mode;


if ((PIR1bits.RCIF == 1) && (gMode == 0x02)); //only recognise uart rx in rcv mode { // interrupt code here.... }


Can anyone please point me in the right direction?



Thanks.


In message , Dennis writes

Move to a more sensible MCU? :-))))))

\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

;

Or, to expand on that a bit (no pun intended), if the snippet above is truly cut from the code then you have "short circuited" the if statement with the semi-colon at "... 0x02));" which is interpreted as a nul-statement making up the body of the if. So, the if either does nothing or skips doing nothing and then the interrupt code is executed, every time.

Rich Webb Norfolk, VA

Ahh! Thanks Rich - that makes sense, I'll go fix it!

cheers!

Remove the semicolon. Your "if" statement is executing that.

Andrew

Thanks Andrew - almost obvious in hindsight!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required