up and perform any SPI master tasks the application
would require. The Moray’s strength lies in its ability to
communicate via Wi-Fi radio. The Moray’s GPIO
capabilities are gravy on the biscuit.
Firmware — From the Beginning
To be successful, we must think out our firmware
design in the same way we have to plan and prepare our
hardware design. The CCS C compiler is super capable
and super easy to use. Thus, our firmware thought process
shouldn’t produce a lot of ear smoke.
Let’s take it from scratch. We know our target
microcontroller is a PIC18F27J13. According to Schematic
1, there is no external clocking device (such as a crystal)
incorporated into the design. So, we can bet on using the
PIC’s internal clocking mechanism. Since there are no
predetermined crystal frequencies specified in the
schematic, we can call the shots ourselves.
The PIC18F27J13 is equipped with an internal
oscillator that ranges from 31 kHz to 8 MHz. We can use
the PIC18F27J13’s 4x PLL to kick the MCU clock
frequency up to a maximum of 32 MHz. Our alternative
PLL-boosted frequency is derived from the 4 MHz internal
clock setting and is presented to the MCU as 16 MHz.
We don’t need lightning in a bottle. So, we’ll drive our
PIC18F27J13 at 8 MHz.
We can construct the proper C source by hand to
define our PIC selection and the clock speed of 8 MHz.
However, that is not necessary. The C compiler comes
standard with a Project Wizard that does a lot of this
manual coding work for us. Take a look at Screenshot 1.
In this screen capture, we enter the PIC type, the desired
clock frequency, and clock source. We also specify if we
want to debug this project’s code. A watch dog timer
(WDT) check box lets us decided if we want to enable the
WDT or let is sleep quietly in the dog house.
If we move methodically and logically in our Project
Wizard path, the next configuration item will be
Communications. Recall that the Moray is perfectly
capable of performing any analog functions that we know
we may need at this moment. We configure the PIC’s
communications resources within Screenshot 2, which is a
screen capture of the Project Wizard’s Communications
configuration window. All we need is simple RS-232
capability in a three-wire configuration (RX, TX, GND).
As you can see in the screen capture, we have
selected the PIC18F27J13’s native RS-232 port at pins C6
and C7. The PIC18F27J13’s serial port configuration is set
for eight data bits, no parity, and one stop bit. The Moray
defaults to 115200 baud and we have set our PIC serial
port up likewise. In the event that we need to use the
PIC18F27J13’s other serial port, we can provide another
unique Stream name other than MORAY.
Streams allow us to direct serial I/O to a specific serial
port by name. In this case, we are only using the default
74 March 2015
Post comments on this article and find any associated files and/or downloads at www.nutsvolts.com/
index.php?/magazine/article/march2015_DesignCycle.
■ Screenshot 1. This is a screen capture of the CCS C
Project Wizard. This window is where the clocking, watch
dog timer, and debugger information is entered for our
selected device. Our entries automatically generate the
necessary configuration code, which we will plug into our
application's C source code.
■ Screenshot 2. Right now, all we need are
the resources provided by the PIC18F27J13's
native serial port (Tx1-Rx1) which resides at
pins C6 and C7, respectively.
Lemos International
Wi-Fi Development
Board
www.lemosint.com
CCS
CCS C Compiler
www.ccsinfo.com
Microchip
PICkit3
PIC18F27J13
www.microchip.com
RESOURCES