ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
■ BY PETER BEST
REWRITING C IN PICBASIC PRO
THE C PROGRAMMING LANGUAGE HAS GROWN LIKE a creeping weed
extending its branches and leaves out from the personal computer (PC) world
and into the realm of the microcontroller. To put a C language program into a
microcontroller, you will need a C compiler that is tooled for microcontrollers.
Good C compilers are based on a set of standards that have been applied
to other equal or better C compilers. Thus, C programs written with these
standards-based C compilers tend to be portable between hardware platforms.
For instance, it is fairly easy to port a Microchip C18 application to the ways of
the HI-TECH PICC- 18 C compiler. It’s also light work to port any Custom
Computer Services PIC C compiler application to either Microchip C18 or the
HI-TECH PICC- 18 C compiler. That’s nice. However, the project we’re about to
tackle will be coded entirely in Basic. When I think of PIC microcontrollers and
BASIC, an image of code splashes written with the microEngineering Labs
PICBASIC PRO Basic Compiler displays for my mind’s eye.
STAND AND BE COUNTED
Many of you Nuts & Volts readers are avid Basic
programmers. I’m not privy to the Nuts & Volts subscriber
list, but I’ll bet that much of the Basic code aimed at microcontrollers found or referenced within the microEngineering
Labs developer’s resources forum was created by Nuts &
Volts readers. Believe it or not, when it comes to portability,
source code aimed at the PICBASIC PRO Basic Compiler
can be easily redirected to and from lines of C source code.
If you don’t see the light now, you will by the time we’re
finished with this project as we will port the entire Ethernet
MINI driver from HI-TECH C to PICBASIC PRO Basic.
At first glance, the C-to-Basic port we’re about to
embark on does not look to be a walk in the park. There is
a considerable amount of C source we must convert to
equivalent Basic statements. As with all huge and seemingly insurmountable tasks, the key to success is to divide and
conquer. We will break the porting tasks down into small
chunks and logically work our way up the coding hill.
However, before we begin this porting hike, it would be
wise to have a plan and understand the pitfalls we will
encounter along our way.
We will be writing code for the EDTP Ethernet MINI
(shown in Photo 1), which is based on the Microchip
PIC18F67J60 microcontroller. A complete set of hardware
drivers for the Ethernet MINI — which includes ARP, PING,
DHCP, TCP, and UDP — has already been fielded by EDTP’s
Fred Eady. We will take that existing (and known working)
technology and convert line by line Fred’s firmware C
statements to corresponding Basic statements.
■ PHOTO 1. We discussed this piece of hardware in the
previous installment of Design Cycle. The Ethernet MINI is
based on the Microchip PIC18F67J60, a stand-alone Ethernet
node/microcontroller combination. You’ll need to understand
how this puppy works to get the most out of the porting project.