This program is a little more ambitious, in that it lights three LEDs one after another and then turns them off. Note that we have to set three bits of TRISA for output, rather than just one.

Run Program 1.2. When the PICmicro runs each light is actually lit one after another, but you will probably not see this because if you run the PICmicro at full speed it happens in a few millionths of a second!

Now configure the PICmicro development board for the RC clock and set the speed switch to SLOW. Run the program again (remember to reload the program with the new settings for the PICmicro itself). Note that the lights come on in sequence, after a brief pause. This is because PICmicro is running very slowly, and we can see the changes in the LEDs as each individual line of the program is obeyed.

The program turns the LEDs on and then off, and then appears to stop. However, if you leave the PICmicro alone for a while the program seems to run again, with the lights flashing and then stopping again.

What is really happening is that your program doesn't stop when it reaches the last statement. Instead it continues down memory, executing whatever statement is held in the PICmicro. At some point it "falls off" the range of instruction addresses and, just like a car mileometer, the program wraps around and returns to the start. The PICmicro we are using has enough ROM for 1,024 instructions (this means it has a 10 bit program counter). When the counter hits its limit it goes back to 0, just like a mileometer in a car.

Note that in this respect the CPIC differs from the real thing!