Pic C18 basic question - if statement

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.

Reply to
Dennis
Loading thread data ...

In message , Dennis writes

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

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Reply to
Chris H

;

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
Reply to
Rich Webb

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

cheers!

Reply to
Dennis

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

Andrew

Reply to
Andrew Jackson

Thanks Andrew - almost obvious in hindsight!

Reply to
Dennis

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.