Test Program
The test program LPC1 (Program 7.1) exercises the analogue input and LEDs, and is used to explain the testing and downloading processes. Its function is to rotate an LED through the bits of port B, with the speed controlled by the pot. The test program has the following structure:
In the processor configuration word !MCLR (reset input) is enabled as this allows the program execution in the LPC board to be controlled from the MPLAB programming toolbar. Bank selection is used to access the control registers, in descending order (bank 2, 1, 0) so the port data register bank does not need to be reselected at the end of the register initialization sequence.
The main sequence lights up an LED, rotates it through port B bits, reads the pot voltage and uses that value in the delay counter, with the result that the pot controls the speed of the LED sequence. At the mid-position of the pot, with a clock rate of 4 MHz, the whole cycle takes about 1 second. Note the high bit is rotated through all 8 bits but only 4 are displayed, so there is a delay between the last LED going out and the first coming on.