A quick look at the PIC16F1459 datasheet tells us that
the TX and RX signals are found on pins RB7 and RB5,
respectively. To direct the UART signals to the prototype
cable connector, we must place I/O selection jumpers at
positions B7 and B5. This jumper arrangement can be
visualized by referencing Photo 3. The TX and RX signals
are also identified in the prototyping stick’s Exercise Book.
Transmit signals will emanate from the red conductor of
the prototyping cable, while receive signals enter on the
white conductor. With the inclusion of the green
conductor (ground), our prototyping cable represents a
simple three-wire RS-232 TTL interface.
Since the prototyping stick’s USB engine and UART
are separate entities, we can write some code to form a
communications link between them. The USB-to-UART
link is great for processing the data stream. However, we
routed the UART signals to the prototyping connector to
expose the three-wire RS-232 port to external devices.
We cannot attach the Rapid USB stick’s three-wire
serial port directly to a regulation RS-232 port. True
RS-232 signal levels fall in the ± 15 VDC range. The
prototyping stick’s UART levels lie in the TTL voltage
domain (0 VDC to + 5.0 VDC). Attaching the stick to a
regulation RS-232 port would release the magic smoke
that is held within the PIC16F1459.
To verify the operation of the prototyping stick’s
UART, the most logical plan would be to use a laptop and
a terminal emulator program to capture its transmission.
Since my laptop is only equipped with USB portals, we
must convert the prototyping stick’s UART output stream
to a USB-compatible data stream.
The easiest way to perform the conversion is to use
an off-the-shelf USB-to-UART converter. I happen to have
such a device. However, my USB-to-UART converter is
designed to operate using 3. 3 volt logic levels. The Rapid
USB prototyping stick is a 5.0 volt module. Thus, the stick
uses 5.0 volt logic levels. I’ve got an idea about the
hardware. So, let’s go ahead and write the RS-232
verification code:
CCS
Rapid USB Prototyping Stick
CCS C Compiler
www.ccsinfo.com
Digi International
XBee
www.digi.com
■ Screenshot 1. This
is not just a simple
blinker application.
Its components
represent a working
framework we can
use as a template to
code our projects.
of the Rapid USB prototyping stick, that include file exists
in the form of RapidUSB.h, which is loaded into our CCS
compiler directory by the prototyping stick setup program.
You do not have to run the Project Wizard to construct
Rapid USB projects. Everything is taken care of within
RapidUSB.h. Just include the RapidUSB.h file and start
writing your application.
The hw_init function is located within RapidUSB.h
and should always be called first. An examination of the
hw_init source code indicates that hw_init is actually a
macro that only affects the comparator setup. With that,
we could also write the LED blinker code in this manner:
#include <RapidUSB.h>
#define RED_LED PIN_C6
#define GREEN_LED PIN_A5
void init(void)
{
hw_init();
output_low(RED_LED); //Both LEDs off
output_low(GREEN_LED);
}
void main(void)
{
init();
while(TRUE)
{
output_high(RED_LED); // Turns the LED on
delay_ms(50);
output_low(RED_LED); // Turns the LED off
delay_ms(50);
}
}
#include <RapidUSB.h>
#define RED_LED PIN_C6
#define GREEN_LED PIN_A5
#use RS232(baud=9600, xmit=PIN_B7, rcv=PIN_B5,
stream=RADIO)
Our revised code simply herds all of the initialization
routines including hw_init into the init function. Compiling
and loading our LED blinker program is as easy as clicking
Build & Run. The bootloader process utilizes the services
of the C compiler IDE, coupled with the built-in terminal
emulator program (serial input/output monitor).
void init(void)
{
hw_init();
output_low(RED_LED); //Both LEDs off
output_low(GREEN_LED);
}
RS-232 and the Rapid USB
Prototyping Stick
void main(void)
{
init();
while(TRUE)
{
fprintf(RADIO,”RapidUSB Toggle RED
LED\r\n”);
output_toggle(RED_LED);
delay_ms(500);
fprintf(RADIO,”RapidUSB Toggle GREEN
LED\r\n”);
54 November 2014