working. At the top of the program, though,
are a few statements that might confuse the
beginner. These are shown below:
ANSEL = 0
CM1CON0 = 0
CM2CON0 = 0
‘ Intialize A/D ports off
‘ Initialize Comparator 1 off
‘ Initialize Coparator 2 off
■ FIGURE 2. Step Three of Project Creation.
you need to click on the VIEW menu and select the
PROJECT and OUTPUT windows. By clicking on these, a
check mark will show up next to the menu selection,
and the windows will appear in the MPLAB IDE with the
project files shown in the Project window. The Output
window will be blank. Figure 4 shows the final view. The
BLINK.BAS and P16F690.INC files are listed and can be
opened by double clicking on them. To actually run the
BLINK.BAS file on the PIC16F690 MCU, we need to
modify the basic file slightly. The sample file is written to
work on the PORTB register, and we need to drive the
PORTC pins. I modified the sample program to look like
Listing 1. This is really a simple program, which makes it
easier to prove out all the steps to get your first program
These statements are required for using
the PIC16F690 MCU’s I/O as digital pins. The
PIC16F690, like many other PIC MCUs, multi-plexes the pin connections with other features.
The PIC16F690 MCU has both Analog-to-Digital
Converter (ADC) ports and comparators that
share the actual pin connections with the digital
I/O circuitry. To use the digital I/O pins, you
must make sure the ADC and comparators are
disconnected. For this project, we’ll disconnect
them by clearing the bits in these registers —
Analog Select Register (ANSEL), Comparator 1
Control Register (CM1CON0), and Comparator
2 Control Register (CM2CON0).
The rest of the program is just a High, Low, and
Pause loop that acts on the PORTC pin, RC0. This pin is
connected to the DS1 LED on the PICkit 2 starter board.
By flipping the level on the RC0 pin from high to low with
a pause in between and looping through that sequence
multiple times, we make the LED flash.
Once the program is written, simply press the F10
button to compile the PICBASIC PRO file into a binary
.hex file. If everything compiles without errors, you will
see a “Build Succeeded” message in the output window.
If you receive an error message, it will tell you in which
line of code it is so that you can see what typo you may
have accidentally made.
PROGRAMMING THE PIC16F690 MCU
■ FIGURE 3. Step Four of Project Creation.
Now that we have a binary .hex file, we need
to load it into the PIC16F690 MCU so that it can
run. For this, I will use the PICkit 2 Starter Kit (see
Figure 5), with the PICkit 2 Programmer connected
to the PC’s USB port. The PICkit 2 Programmer
will then power the development board from the
USB port and program the PIC16F690 MCU
when inserted into its socket through the board’s
programming connecter. Because the MCU is
connected to the LEDs, switch, and potentiometer on the development board, we will
use the In-Circuit Serial Programming™ feature
to download the .hex file into the PIC16F690
MCU. This just means that you don’t have to
remove the MCU in order to program it.
To move forward from this point, we need
to connect the PICkit 2 Programmer to the
USB port and then enable the programmer in
the MPLAB IDE. We do so by selecting the
PICkit 2 from the “Programmer” menu at the
top of the MPLAB screen (see Figure 6).