The Design Cycle
PIC18F452 instead of the PIC16F877 called out in the
In addition to the mods on the LAB-X2 board itself, I
had to fabricate an interface cable to allow the MPLAB ICD
2 to connect to the LAB-X2’s 10-pin EPIC programming
interface. A before and after view of the LAB-X2 is shown
schematically in Figure 3, along with the pinout of the new
LAB-X2/MPLAB ICD 2 programming cable. The bulk of
the LAB-X2 mods were performed in the MCLR and
PORTB program/clock pin areas. Basically, I eliminated
the 10K pullup on the program clock pin (RB6) and the
MCLR series resistor (R2). I replaced R2 with an SMT
blocking diode, added a 0.1 µF manual RESET capacitor,
and closed JP1.
The blocking diode insures isolation of the Vpp
programming voltage when using the MPLAB ICD 2. At
the same time, the voltage drop across the 1N5819
blocking diode is not great enough to prevent the MCLR
pin from receiving the proper reset and run voltages.
Shorting JP1 allows the MPLAB ICD 2 to receive power
from the LAB-X2 power supply. The 0.1 µF RESET
capacitor is optional and only comes into play when
the RESET button is depressed. The MPLAB ICD 2
programming/debugging cable assembly is terminated
on the MPLAB ICD 2 end with a standard male six-pin
RJ- 12 connector. The LAB-X2 end of the cable is fitted
with a dual-row 10-pin female connector. The cable itself
is a one-foot length of standard six-conductor flat cable
that is also known as silver satin cable. A shot of
my modified LAB-X2 and the MPLAB ICD 2 interface
assembly can be seen in Photo 1.
After completing the LAB-X2 mods and rechecking
my work, I applied power to the LAB-X2/MPLAB ICD 2
combination. Nothing appeared to be hot to the touch
and the PIC18F452 and MPLAB ICD 2 weren’t sending
smoke signals, so I knew that the hardware was ready
and now I could start writing the USART initialization
Enabling the USART ...
The very first coding task involves initializing the
USART hardware in the LAB-X2’s PIC18F452. Here’s
what the PicBasic Pro USART initialization code looks
define OSC 20 ‘define clock speed for the compiler
define HSER_RCSTA 90h ‘binary 10010000
define HSER_TXSTA 24h ‘binary 00100100
define HSER_BAUD 57600
PicBasic Pro assumes you are using a 4 MHz clock
unless you specify otherwise. In the code snippet above,
we have overridden the default clock rate and
defined a 20 MHz microcontroller clock. The USART
receiver module is activated by setting the SPEN (Serial
Port Enable-bit7) and CREN (Continuous Receive
Photo 1. The LAB-X2 has just enough goodies to make it useful.
The board works as designed right out of the box. I modified the
board to allow the use of Microchip’s MPLAB ICD 2.
Enable-bit4) bits in the RCSTA (Receive Status and
Control) register. By not setting other bits in the RCSTA
register, we set the asynchronous protocol to eight data
bits, no parity.
The USART transmitter module is awakened by setting
the TXEN (Transmit Enable-bit5) bit in the TXSTA
Circle #76 on the Reader Service Card.