« Return to Thread: using BREAK in 'C'

using BREAK in 'C'

by CDB-3 :: Rate this Message:

Reply to Author | View in Thread

 I'm writing some I2C code for someone using the hardware MSSP on a
18F242.

The following code works, but I'm not sure that it should.

Break should only short circuit a loop, in error I've coded it into an
IF statement that is inside a while loop - so whilst Break works for a
while loop, should it work when in an IF statement inside a loop?

Code below (note formatting may get mangled).

void I2C_hwStop()
{
     BYTE timeout = 50;
     
     SSPCON2 = SSPCON2 | (1<<PEN); // set stoP condition
     
     //In case the slave device gets stuck, we need to have a way of
exiting.
     //otherwise we are stuck here until the plug is pulled!
     while (!(PIR1 & (1<<SSPIF)))
     {
           timeout --;
           if (timeout == 0)
            {
              break;
            }
     }
     
     PIR1 = PIR1 &~(1<<SSPIF);  //clear completed flag
}
//end I2C_hwStop

Thanks

Colin
--
cdb,  on 26/06/2009






--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

 « Return to Thread: using BREAK in 'C'