» Iosoft Ltd
- ChipVid Video
- Software Updates
- Embedded Web
» Embedded TCP/IP
- License FAQ
- 802.11 kit
- Wireless FAQ
- Frame Grabber
» Real-time data
- Air Quality
- First Edition
- Second Edition
- Application notes
» Online Sales
A beginner's guide to the PICmicro®
A microcontroller is a complete computer-on-a-chip, which can function with a minimum of external components. ROM, RAM, I/O and communications functions are integrated on-chip. Microcontrollers are designed for high-volume low-cost applications, and are embedded into everyday appliances to give them some computing functionality.
The low cost of a microcontroller does make it more difficult to use than an ordinary PC; it has no screen, keyboard or disk drives, so just establishing communication with the device can be quite a challenge. Although the devices can be programmed in the 'C' language, specialist compilers are needed, and they have non-standard functionality to optimise the software to work in small amounts of memory.
The traditional way to debug a microcontroller system is to use an in-circuit emulator ('ICE') which is plugged into the microcontroller socket in place of the device. It employs a 'bond-out' chip that allows external access to the on-chip devices; a PC is used to control the emulator and display the internals of the emulated microcontroller.
The cost of an emulator is prohibitive for the student or hobbyist user, so a lower-cost alternative, the in-circuit debugger (ICD) has been created. This uses a low-cost 'pod' that communicates with a standard microcontroller using a 2-wire interface. This interface is used to program the device, control and monitor its internal operation.
Why use a microcontroller?
For embedded applications, microcontrollers have several advantages over PCs.
The PICmicro family of microcontrollers is manufactured by Microchip Technology www.microchip.com. We primarily use the PIC18F452 device, which has 32 Kbytes of flash reprogrammable ROM, 1.5 Kbytes of RAM and 33 I/O lines.
The I/O lines are arranged in blocks (known as ports A, B, C, D, E) each with specific functionality in addition to a general I/O capability. The pins of a specific port generally have an 'R' prefix, so RA0 and RA1 are the first two I/O pins of port A.
The specific functionality of a pin is defined by a combination of configuration registers within the chip. All ports have a 'TRIS' register which is a bitmap defining whether each pin is an input (1) or output (0), but in addition, but there may be other over-riding configurations within the chip, for example if RA0 is to be used as an I/O pin, its functionality as an ADC input must be specifically disabled. All this is described in the device data sheet, which is available free of charge from the Microchip Web site.
When the PICmicro powers up, it obtains some critical settings from the configuration 'fuses' that have been set when the device was programmed. If these configuration settings are wrong, it is possible that the PICmicro won't run at all, or will continually reset itself, so it is important to check they are correct when programming the device. The Iosoft standard settings for the PIC18F452 are:
The Iosoft code is compatible with the CSS www.ccsinfo.com and Hi-Tech www.htsoft.com PIC18 compilers; we do not support any alternatives. The CCS product compiles, links and locates the code in a single step, so there is no scope for linking other object files or libraries. For this reason, the Iosoft source code is structured as a single source file (e.g. P18WEB.C) with #include statement being used to include other files, rather than linking to these files.
Some compiler versions have specific bugs which will cause the Iosoft code to malfunction, see the Iosoft support pages for detailed information on compiler compatibility.
The compiler produces a 'hex' file containing the executable code, which must be programmed into a device. This may be done using an ICD (see below) but the simplest method is to use a device programmer. There are many on the market, and some of the low-cost hobbyist programmers (such as Newfound Electronics' WARP13) offer excellent functionality at a very reasonable price.
In-circuit debuggers (ICD)
Microchip and CSS offer ICD products, that are a low-cost alternatives to in-circuit emulators.
The microchip ICD 2 has serial and USB interfaces to the PC, and uses their free MPLAB® software interface. MPLAB supports a wide range of programmers and emulators as well, so can be confusing for the first-time user. The latest Iosoft ChipWeb software documentation does include some sample configurations.
The CCS ICD-S (serial) and ICD-U (USB) devices are similar in concept to the Microchip offering, but are only compatible with the Windows version of the CCS PIC18 compiler (PCWH).
ICD units require some care in setting up; it may be necessary to load new code ('re-flash') the ICD to match the Windows front-end, and if this process goes wrong the ICD can be rendered useless. Also, the limitations of the ICD two-wire interface do restrict its functionality; only one breakpoint is available, and single-stepping can be difficult due to compiler code optimisation (e.g. conversion of function calls into in-line code).
To allow ICD debugging of a PICmicro, the executable program code must be altered to enable the monitor program. This may be done by the compiler (e.g. CCS #ICD directive or MPLAB 'link for ICD' option). Check the ICD documentation to see how to switch between debugging and stand-alone modes.
In-circuit emulator (ICE)
For professional software development, Iosoft recommends the use of an in-circuit emulator, such as the microchip ICE2000.
When buying an emulator it is necessary to specify three parts: the main emulator interface (e.g. ICE2000), the processor pod (e.g. PCM18XC1 to emulate the PIC18F452) and the interface adaptor (e.g. DVA16XP401 for a 40-pin dual-in-line package).
|© Iosoft Ltd 2005|