We have seen that our program will eventually wrap around and run again. If we were daft enough we could fill the entire PICmicro memory with instructions which turn the LEDs on and off, but this program would take a long time to write. What we really want is a way of repeating the flashing sequence. We can use the while loop construction to do this.

This program uses a while loop to repeatedly turn the led on bit 0 of PORTA. Load the program into the PICmicro and run it. Note that the led flashes (and will flash for ever). Remember that to see the light flash you must have the PICmicro set to use the RC clock and set the clock to slow. (See the PICmicro Parallel Programmer page for details)

You should notice something odd. The LED does not spend as much time switched on as switched off. If you think about how our program works this is not that surprising. The set and clear instructions follow each other immediately, so the light is turned off as soon as it has been turned on. However, once the LED has been turned off the PICmicro has to execute the instructions which make the loop work, which take some time. Hence the way the light blinks rather than flashes.

You will see the same effect when you simulate the program using the CPIC.