GETTING STARTED WITH PICs
which is a wonderfully useful
expression mechanism in C — just
about everything can be used as a
boolean value (those things zero are
FALSE, those non-zero are TRUE).
Since the while() loop conditional
will always return TRUE, it will loop
forever. The commands within while()
sets RB0 or PortB bit 0 to a one, which
turns on the LED.
The program is completed by
putting the closing braces for both the
main() function and while() loop. It
closes with an end command.
One thing to note with the
structure of C is that all command lines
— AKA statements — end with a semi-colon. This is one of the biggest errors
for beginners, as it is not required in
assembly or Basic. Also, comment lines
start with a double backslash — not a
colon or semi-colon like assembly or
Basic. If you can get past the braces
and colons, the program doesn’t look
much different than a PICBasic program. You can see some of the differences between the HI-TECH PICC-Lite
and the CCS C compilers by comparing
Listing 3 to Listing 2. I mainly wanted to
introduce the basics of C code, and
plan to help you learn more as this
column progresses along.
programming by using the Basic Atom
and PICBasic Pro. I also know others
who learned with the various other
options. There is no single correct
choice. If Proton or PICC-Lite or
PICAXE or BASIC Stamp or any other
choice gets you started programming
PIC MCUs, then go for it. When I started, the choices for the hobbyist or
beginner were limited and finding
help was next to impossible.
I often wished that I had someone
teaching me or had books to read
when I got started, but I couldn’t find
many. Those books I did find were written for the professional and were often
way over my head. I had to find all this
out on my own. I hope you keep
reading, and I’ll be more careful about
the errors. Send me emails with your
feedback, because as you can see, I
listen. Send them to chuck@elproducts.
com and stop by my website anytime
at www.elproducts.com. NV
Easy Ordering In Nanoseconds
CONCLUSION
I still feel that programming PIC
MCUs in Basic is the best option for
the beginner, but if you want to do
any programming outside of the hobbyist arena, you should at least learn
some C. I started with assembly and
have used Basic for years, so those are
like second nature to me. Adding C to
my software skills made programming
PIC MCUs even more fun, and I hope
to pass on what I know to those that
want to learn C, as well.
I’ve watched and helped many
complete beginners get started
NOTE:
■ PIC and MPLAB are registered
trademarks of Microchip Technology,
Inc., in the USA and other countries.
All other trademarks mentioned
herein are property of their
respective companies.
• The ONLY New Catalog Every 90 Days
• NEWEST Products & Technologies
• Over 800,000 Products Online
• More Than 330 Manufacturers
• No Minimum Order
• Fast Delivery, Same-day Shipping
The Newest Products
For Your Newest Designs
mouser.com (800) 346-6873
The NEWEST Semiconductors | Passives | Interconnects | Power | Electromechanical | Test, Tools & Supplies
Mouser and Mouser Electronics are registered trademarks of Mouser Electronics, Inc. Other products, logos, and
company names mentioned herein, may be trademarks of their respective owners.
June 2007 19