PICProto
USB
The
reader response to my column titled “A P89C668 Development
Board for 8051 Fans” was enough to tell me that the
BASIC programming language is—as it relates to the
8051, PIC, and AVR—alive and well (Circuit Cellar
151). ME Labs offers a good PIC BASIC compiler called
PicBasic. I got a copy of PicBasic Pro because it’s
more than a decent BASIC compiler. The professional
version is relatively inexpensive, and it supports
Microchip’s flavor of low-speed USB, which is driven
by the PIC16C745 and PIC16C765 microcontrollers.
The
PICProto USB development board was refreshing because
I had to build it completely from scratch. I had to
fly in two components, a 6-MHz ceramic resonator and
a series-B USB connector. Otherwise, the through-hole
assembly process was quick and easy. A schematic and
bill of materials are included with the bare silk-screened
PICProto USB PCB.
For
a complex interface, the USB hardware is just as simple
as basic RS-232 hardware. In fact, I’ll go out on
a limb and say that a PIC-based USB hardware interface
is actually simpler than a PIC-based RS-232 hardware
interface.
The
PIC16C745 and PIC16C765 USB microcontrollers are self-contained
and don’t require any of the auxiliary level-shifting
circuitry that is common for true RS-232 implementations.
Using the PIC16C765 or PIC16C745, a bare-bones USB
hardware interface consists of the PIC, a couple of
0.1-µF bypass capacitors, a VUSB filter capacitor,
a ceramic resonator, a resistor, and the series-B
USB connector. Even though the PIC USB solution provides
for a simpler hardware interface, USB communication
requires much more effort to implement.
On
the PICProto USB development board, the 28-pin PIC16C745
IC socket lies inside the 40-pin PIC16C765 IC socket.
I wanted to be able to mount either the 40-pin PIC16C765
or the 28-pin PIC16C745 on the PICProto USB development
board. So, I used machined header pins to populate
the 40-pin socket pads instead of a standard 40-pin
socket. This allowed me to solder a standard 0.3²
28-pin socket inside the 40-pin socket footprint.
My completed PIC-less PICProto USB development board
is shown in Photo 3.
 |
| Photo
3—All of the goodies that complement the everyday
PIC are included with this board. There are a
couple of potentiometers, a pair of LEDs, and
two push-button switches. The 25-pin connector
pad layout suggests that a serial-to-USB thing
could happen in the prototype area. |
Because
there is no “F” in their names, the PIC16C745 and
PIC16C765 microcontrollers are available as either
windowed ultraviolet erasable parts or one-time programmable
(OTP) parts. I have a fancy timer-equipped EEPROM
eraser, but I’ve been spoiled by the easy-to-program,
flash memory-based PICs. Because the new generation
of flash memory-based USB PICs wasn’t available when
I started this article, I used the MPLAB ICE 2000
and a PCM16XQ1 processor module to stand in for the
windowed PIC16C745 and PIC16C765.
Before
attempting to read the PIC-Proto USB development board’s
USB datastream with the USB Tracker 110, it may be
a good idea to check to see if all of the solder joints
took. A small USB demo program that moves the test
computer’s cursor is included with the PicBasic Pro
compiler. I loaded that puppy into the MPLAB ICE 2000
to see if I could twirl the cursor.
Using
the MPLAB ICE 2000 instead of the real thing required
that I invoke the MPLAB IDE. Normally, that would
have meant loading and running a separate IDE for
the PicBasic Pro compiler. Not in this case. The PicBasic
Pro compiler is capable of running as a language toolset
within the latest version of the MPLAB IDE. Although
being able to run PicBasic Pro and MPLAB in a single
IDE is a good thing in terms of development, there
is another upside to this union: PicBasic Pro generates
a standard .cod file that allows for debugging using
the MPLAB ICE 2000 hardware.
After
plugging in the MPLAB ICE 2000 PCM16XQ1 USB processor
module and attaching a 40-pin DIP device attachment
module to the end of the processor module’s cable,
I carefully plugged the MPLAB ICE 2000 device attachment’s
gold-plated 40-pin DIP header into the 40-pin header
socket that I had installed on the PICProto USB development
board. Then, I jumpered the PICProto USB development
board for USB-supplied power.
At
that point, I loaded the PicBasic Pro USB demo, USBMOUSE.BAS,
in the MPLAB IDE. I couldn’t get a good reset on the
MPLAB ICE 2000. After clicking the MPLAB IDE Run icon
a few times without success, I figured that something
wasn’t working correctly.
I
first took the software problem determination route.
(After all, my soldering should be perfect.) I muddled
around, trying this and that with files and such with
no joy. OK, maybe I did have a problem with the PICProto
USB development board hardware. So, I disconnected
the PICProto USB development board and took it to
the bench for a look under the magnifier. As I had
expected, all was well with the soldering job and
component placement.
I
did not cut any of the default jumpers on the PICProto
USB development board. The only live jumper pins were
the power-source pins. I decided to reattach the MPLAB
ICE 2000 and move the powered-by jumper from USB to
external. The MPLAB ICE 2000 reset was successful,
and I was able to configure the MPLAB ICE 2000 to
use the PICProto USB development board’s power and
clock. Obviously, the emulator and associated electronics
drew a bit more current than the USB was willing to
supply at that point. Despite the little drawback,
it was good.
I
had already created a project directory and copied
the USBMOUSE.BAS file into it. A study of the USB
documentation that was included with the PicBasic
Pro compiler indicated that I would need to add supporting
files to the project as well. These files, which were
included with the compiler, provide a basis for the
USB hardware layer that is intended to reside in the
PIC firmware. The PicBasic Pro USB support files are
based on the original Microchip USB support files
and have been modified to compile under PicBasic Pro.
Having
put my emulator hardware problem behind me, I was
on my way to compiling the USB demo code and controlling
a cursor. Well, not quite on my way. I clicked the
MPLAB IDE’s Build icon and was greeted with what seemed
to be a million error messages, which wasn’t good.
My
first clue was the first error, which stated that
it could not open a particular include file, P16C765.INC.
That’s easy enough, I said to myself. I’ll just rename
the PicBasic Pro 16C765.INC to P16C765.INC and things
will once again be good. Ha! My mouth was still open
when the dust stirred by a million more error messages
had settled. OK, maybe the list file would reveal
an answer. Duh. My second clue was on the first error
line of the listing. MPASM header was the comment
beside the lost P16C765.INC file.
You
can configure the PicBasic Pro to use either the MPLAB
assembler (MPASM) or the internal PicBasic Pro assembler
(PM). Well, there’s a big check mark in the “Use MPASM
Assembler” box under the MPLAB IDE’s project build
options. I had renamed the PM include file (16C765.INC)
to fool the MPLAB IDE assembler, but the MPLAB IDE
assembler didn’t bite on the contents of the newly
monikered file.
I
checked my Win2K path variable and indeed the entry
for the Microchip MPLAB IDE include files was there.
Without question (I was desperate), I simply copied
the Microchip-provided MPLAB IDE P16C765.INC and P16C764.INC
include files into my PicBasic Pro USB project directory.
Here
we go. After clicking on the MPLAB IDE Build icon,
I was humming my favorite Bob Marley tune, “Jammin’.”
After another click on the MPLAB IDE Run button, I
was growing dreadlocks. The test machine’s cursor
was going in circles and dancing to the reggae beat.
It was good indeed.