START OF TUTORIAL 2

Development board users should load the PICmicro with program TUTA2. Click on the Full Listing button to see the settings needed.

This program can be simulated on the Vlab.

INTRODUCTION TO LISTING 2

A PICmicro without program commands, as is the case when TUTA1 is loaded, is of no benefit to us! We shall now demonstrate a simple program which just turns on the series of eight LEDs connected to Port B.

If you are using the development board, you now need to load the PICmicro with program TUTA2.HEX. Click on the Full Listing button to see what settings are required, and then load the PICmicro via the Program button. After which, press the Reset switch to restart the program running from the beginning. There will be a few seconds wait before you see anything happening. Return to this page.

To examine the operation of this program in the Vlab, click on the Vlab button, and then return to this page.

At present, the oscillator which controls the PICmicro is only running at a very slow speed, about 1Hz or so. The internal workings of the PICmicro automatically divide any clock frequency by four, taking four counts to process a single command. During each of the four intervening pulses, different aspects of the command are processed. To all intents and purposes, most commands take 4 clock pulses (certain commands such as GOTO take 8 clock pulses).

The results of the first four commands will not produce any visible result (all commands will be discussed later). After a few seconds, though, each LED of Port B will come on in turn, in order of LB0 to LB7, with a pause between each change.

When the final LED (LB7) has come on, there are no more instructions to perform, so nothing more happens (in fact, the PICmicro is actually working its way through each of the remaining null commands which were programmed in from the TUTACLR program, but you won't see any result from these commands).

Press the Reset switch to see the sequence again. The rate at which it runs can be changed by adjusting preset RV1.

But, how does the program do what you see it has done? Look again at Listing 2.

As discussed for Listing 1 in Tutorial 1, you will see comments at the start of the listing and within it, all preceded by a semicolon. You will also see the ORG and END statements. Sandwiched between them are several lines of commands and comments.

Ignoring the numbers following each command, there are only three different commands in use here: CLRF, BSF and BCF. They simply stand for CLeaR File, Bit Set File and Bit Clear File. An allied command to CLRF is CLRW (CLeaR Working register).

First we will explain the meaning of a few terms that we shall use frequently throughout the tutorials, and then explain what the listed commands CLRF, BSF and BCF do.

Now use the contents tree to navigate to Tutorial 2.2.