Hi, I have just taken a project already started on the ST10F168. My problem is to understand when I am obliged to use the _nop_() function. Because in my project, it's using in abundance...Is it really necessary ?? When you set a port or a state(input/output), do you put a _nop_() (or 2) after ?? In general, when the use of this function is necessary ?? Thanks in advance Regards JM
I have done several projects with C166 and I don't remember ever having used _nop_() (or the assembeler instruction NOP for that matter). There are some pipeline effects where the instruction could be used, but these are rare and usually you can do something useful instead of putting in a NOP. Also, there could be a place for a few NOPs when generating a short pulse with an I/O pin and there is some minimum width for the pulse.
if not associated with I/O should never be there Erik never say never :)
If it seems that there are too manu NOPs, there probably are. All the pipeline side effects are described in the microcontroller manual, and there are not many. One of the most important ones is when you want to disable interrupts: after the BCLR IEN instruction you have to wait for two or three NOPs before you can put the uniterruptable instruction sequence in. You can read the microcontroller manual to see if those NOPs are necessary or you can just leave them there and mark them with the comment /* just in case */. Regards, - mike
The only time I use them is when enabling/disabling interrupts to make sure the pipeline is flushed out before ending an atomic sequence. See this thread for more info. http://www.keil.com/forum/docs/thread1226.asp
Thanks all ! If i understand _nop_() function is used just for I/O. But in the example below, which NOP are necessary. Just 1 (or 2) for changing the state of the port direction, or all ?
void SetP8(void) { P8=0xFF; _nop_();_nop_(); DP8=0xFF; _nop_();_nop_(); }