I fell over the following problem using a 24MHz C8051F060 to strobe data out of a NAND chip and compare it against 0xFF. My object had been to get the loop as tight as possible so I was content with four instructions.
mov a,#0xFF
Loop: clr strobe_bar
cjne a,P5,NotAllOnes
setb strobe_bar
djnz dpl,Loop
clr C
ret
NotAllOnes:
setb strobe_bar
set C
ret
I wrote that to replace some C code a bit like like the following.
bit NAND_IsAllOnes(BYTE n)
{bit Failed = false;
do
{strobe_bar = 0
Failed = ( P5 != 0xFF );
strobe_bar = 1;
if ( Failed )
break;
}while(n--)
return Failed;
}Worked fine on the the first set of hardware and then failed randomly (never when single stepped) on new hardware. Of course it's obvious, once you've seen it, but it had me tearing my hair out for a couple of days (there were lots of other things it might have been and it worked on some boards). Still, if it crops up at the next interview, I'm ready.
Rgds,
Bill
PS Ignore