serial port. So, we can opt to use MORAY in a stream
statement if we wish. Otherwise, we can successfully
execute serial operations using the PIC18F27J13’s
EUSART without specifying a Stream name.
The selections you see in Screenshot 2 will generate
the necessary code to initialize the PIC18F27J13’s
EUSART as we have specified. The baud rate calculation
will use the 8 MHz clock speed we defined in Screenshot
1. One of the biggest strengths of the CCS compiler is its
built-in delay functions. By simply declaring the delay time,
the compiler can produce the code necessary to delay in
CPU cycles, milliseconds, or microseconds. The delay
functions are also based on the CPU clock speed.
Now that we have laid the groundwork for our RS-232
communications portal, we’ll need to build a framework to
deal with the data it will handle. The best way to corral
incoming RS-232 data is to use an interrupt at the corral
gate. The CCS compiler’s Project Wizard will generate the
interrupt handler skeleton, but it will not generate our
interrupt handler code. We’ll worry about the interrupt
handler code later. Right now, let’s just get the posts in the
ground.
Our corral post hole digger can be found in the
Interrupts shed of the Project Wizard. All we have to do is
check the correct box in Screenshot 3. How do we know
which check box to select? We are calling the shots,
remember? Let’s choose to only interrupt on received
characters. There is no real need to interrupt on
transmitted characters. We know what we’re sending. It’s
the responses from the Moray that are important to us.
So, we must build a firmware mechanism to capture and
store the Moray’s responses until we’re ready to process
them. That’s a to-do we’ll take care of a bit later.
If you add hardware, odds are you’ll also be adding
code. If we’re going to use that “activity” LED, we have to
announce its presence to the firmware. Normally, we
would simply code an alias for the LED and set up the I/O
pin that services the LED as an output. Nothing changes
with our C compiler except we instruct the Project Wizard
March 2015 75
■ Screenshot 3.
This may seem
trivial, but it sure
beats looking up
the interrupt
handler syntax in
the CCS C compiler
user manual.
■ Screenshot 4. According to Schematic 1, we
have an LED hanging on I/O pin A2. So, here we
name the LED and specify the I/O pin it is
attached to as an output pin.
www.ccsinfo.com/NV315
262-522-6500 x 35
sales@ccsinfo.com
PIC® MCU is a registered trademark of Microchip Technology Inc.
Download FREE Full Evaluation:
Easy to Use & Quick to Learn Highest Level of Optimization
Code is easy to port between PIC processors
Extensive & Easy-to-Use Libraries for:
One Compiler for any PIC® MCU
C-Aware IDE and debugger
ZLWK;FRGH;SURƜOLQJ
CCS C Compilers for Microchip
PIC® MCUs & dsPIC® DSCs
USB
I2C
SPI
Timing
E-mail
Telnet
Serial EEs
ADCs
RS232
DACs
PWM
TCP/IP
Segmented LCDs
ZĞĂ ͲƟŵĞ;Đ ŽĐŬƐ
tĞď;WĂŐĞ;,ŽƐƟŶŐ;Θ;ŵŽƌĞ͊
;ĂƉĂĐŝƟǀĞ;dŽƵĐŚ
WƌŽŐƌĂŵŵĞƌƐ;ĞŶĂď Ğ;ƉƌŽĚƵĐƟŽŶ;ŝŶƚĞŐƌĂƟŽŶ;ĨŽƌ;
ƐĞƌŝĂ ;ŶƵŵďĞƌŝŶŐ;Θ;ƉƌŽĚƵĐƟŽŶ;ƟŵĞ;ĐĂ ŝďƌĂƟŽŶ͊
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;