[Exercise 1.4 (ex14.c)]

The program we have written will make the LED flash, but we need to run the PICmicro at low speed to make it work. If you run the program at the speed of the crystal clock (remember to reload the program into the PICmicro with the new clock settings) you will not see a flashing LED, you will see a glowing one.

What is required is a way of "pausing" the processor once the LED has been switched on. Unfortunately we can't do this, but we can keep it busy with a loop. To do this you will need to make a for loop which does nothing. The PICmicro will run this, and it will provide a pause in the execution of the program.

I have used a for loop to give a nice big delay. I has also used an integer as the counter. This slows things down in two ways, we can count to a larger limit if we use integers, and the actual mathematics takes longer with integer variables.

If you run this program on the PICmicro (it would take around a month to execute on the Virtual CPIC!) you will find that the LED flashes at around 1 Hz.

Please note to run this program you will need to set the PICmicro FAST/SLOW switch to FAST.

Note that I am using the same colour coding as the C2C compiler will use:

blue - a part of the C language: a keyword or pre-processor directive

red - a built in C2C function or variable

green - a comment

black - an identifier or punctuation mark