Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
73
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

350

Chapter 9 / The PIC Prototype

 

 

Develop Code in

IDE

Download

to

Microcontroller

Debug

using

In-Circuit Debugger

(ICD)

Modify

Hardware

End Product

CODE

Figure 9-1

Figure 9-1 assumes the passive component placement is completed and you are ready to add the intelligence that makes the circuit work. This iterative process begins with writing your source code, downloading to the target processor that is attached to the circuit, stepping through your source code, making changes to source and hardware (if necessary), and starting the process over again.

Chapter 9 / The PIC Prototype

351

 

 

Development Strategy

Unlike the BASIC Stamp, we will be using several languages and components to demonstrate the PIC implementation. We will develop two solutions using PIC processors; here’s why: The PIC processor line has an older part that supports low-speed USB. This part comes in a 28and 40-pin version (16C747/16C765). These parts are “one-time” programmable, which means they can’t be reprogrammed. These chips are used in two different demo kits: the PICKit 1 and the PICDEM USB. The PICKit 1 is a very inexpensive (under $40) tool that uses the 16C745 part as a USB programmer for other Microchip parts. The board has a flash-based 12F675 part that can be programmed via the USB port on a Windows PC. There are LEDs for simulating output on the target part, a push button switch, and pot for input. There is also another program that expands the variety of parts that the board can program. All of the source code to the USB part, the Windows portion, and sample target programs are included along with data books in PDF format. The board has a “break-away” prototype board that can be used to interface the sample 12F675 to the world.

Chapter 9

Figure 9-2

352

Chapter 9 / The PIC Prototype

 

 

The PICDEM USB board is larger in size and has the 16C765 40-pin part installed with a second socket for the 16C745 part. The kit also includes several 16C745 and 16C765 parts that are EEPROM based. These parts can be purchased and have the postfix of /JW when ordering. In addition, the PICDEM board has eight status LEDs, a DB9 RS-232 interface, a DB15 game adapter interface, a PS/2 connector/interface, keypad, and LCD connector.

Figure 9-3

The PICDEM USB also comes with all the source to the USB interface and several Windows programs that can be used for testing the different interfaces on the board.

Chapter 9 / The PIC Prototype

353

 

 

What Is HIDmaker?

HIDmaker is a unique product that assists embedded developers who use the 16C745 chips to develop their data flow and Windows HID interface. To understand the usefulness of this product you need to first understand what HID is. In the Windows operating system Microsoft implemented a tiered device driver scheme so developers of human interface devices (HID) like trackballs, mice, and keyboards could quickly bring their products to market. If this sounds unique to Microsoft, it isn’t. The USB specification includes the HID driver interface. The idea is that all human interface devices share some common properties, so the USB implementer forum decided to include a higher level interface just for such devices. The device type determines how the low-level driver that is part of the operating system will handle data to and from these devices and use one of the built-in handlers or a vendor-installed handler.

HIDmaker wraps code around the PIC USB firmware to bring the embedded systems into the HID data handling specification. So code is generated for the embedded processor, and a Windows HID driver interface with the data handling layout and scheme are also generated. When completed, the wrapper code for the PIC is embedded into the chip along with the USB firmware and a listing in the language of your choice is created for the Windows driver. So what about Linux and UNIX? This is a book about cross-platform development. The truth is that Linux allows the developer to handle this without a tiered driver interface. We will cover this topic in Chapter 11.

Chapter 9

354

Chapter 9 / The PIC Prototype

 

 

The following flowchart illustrates the development process using HIDmaker.

Design HID Interface

Design

HIDMaker

Application

Implement Design in

HIDMaker

Embedded

Compile / Test

Compile for 16C745 / 16C765

Test USB Interface

Include HIDMaker

code in

Host Application

Windows

Compile Host

Compile / Test

Application

 

 

 

 

 

 

Test Completed

Program

Figure 9-4

Using HIDmaker we could define our communications protocol, but we will instead use USB as a method of sending and receiving data. We will add only the TTL serial communications to the 16C745 to support serial I/O from the dsPIC. This is the identical

Chapter 9 / The PIC Prototype

355

 

 

method we used in Chapter 7 to build an interchangeable RS-232/USB/Ethernet interface. The difference here (aside from using different components) is that we are building both the USB interface and embedded controller. Once we have completed the dsPIC thermostat interface, the only remaining task is to be certain we can use either the low-speed 16C745 or full-speed 18F2455 devices. So let’s begin by writing the necessary software to interface our dsPIC to the thermostat boards.

For this example will use the Microchip C30 compiler and ICD 2. These combined with MPLAB will afford us the ability to not only develop but also debug our code at the source level as well. To develop our prototype we will use a modified version of the dsPICDEM 28 board, which provides us with a dsPIC 2010 28-pin part, reset switch, power LED, program-accessible LED, power interface, RS-232 interface, and a prototype area.

Chapter 9

Figure 9-5

To develop our code and provide a debugging interface we will need the ICD 2 debugger. This unit is USB driven and attaches to a six pin telco jack next to UART1 on the dsPICDEM 28 board. This arrangement will provide a development environment similar to the one used in Chapter 8.

356

Chapter 9 / The PIC Prototype

 

 

The dsPIC30F2010 Processor

We begin with the dsPIC30F2010 development. We need an I2C interface for our LCD, an SPI (3-Wire) for our DS2404 memory, a 1-Wire interface for the DS1822, and at least one TTL-RS-232 interface to communicate with our host interface. Actually, we should have two TTL-RS-232 interfaces. Figure 9-6 illustrates the communications interfaces we need.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TTL RS232 #1

 

dsPIC30F2010

 

 

TTL RS232 #2

 

(Host Comm)

 

 

 

 

(Aux Comm)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I2C

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Ethernet

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Controller

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Dallas 3-Wire (SPI)

 

 

 

Dallas 1-Wire

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PIC 16C745 USB

Figure 9-6

This is indentical to the interface in Chapter 7 except the first RS-232 port was connected to a transceiver for programming and debugging. In this case we are using an in-circuit debugger (ICD) as shown in the following photo.

Chapter 9 / The PIC Prototype

357

 

 

Figure 9-7

There are two ways to debug embedded systems using the PIC processor line. The first tool is the ICD that we’ve been discussing. The ICD is very versatile in that it also allows you to reprogram the chip in circuit on the finished board in the field. For debugging purposes it is an excellent tool; however, it does use the target processor pins so if you are are debugging, the I/O pins used for the debugger are unavailable for I/O. Second, your target board has to be working and powered. The alternative to the ICD is the in-circuit emulator, or ICE as it’s commonly called. The ICE is a small device that looks like a black box with a ribbon cable coming out of it. The ICE unit actually emulates the processor so you can download and run code without using any processor pins at all. The ICE also has its own power supply so it doesn’t need to be connected to anything other than the development system to work. The difference in price is considerable as the ICD is around $150 and the ICE is around $4,000. If you’re doing time-sensitive or real-time development, the ICE is the way to go. For our purposes, the ICD will work fine so we will develop using it.

Chapter 9

358

Chapter 9 / The PIC Prototype

 

 

The Ethernet Interface

Once again we will use the NetBurner SB72 single board Ethernet interface. In the last chapter we used TCP/IP to connect to a single host. This time we will use UDP (the User Datagram Protocol) to send and receive messages from the host.

Figure 9-8

Chapter 9 / The PIC Prototype

359

 

 

The dsPIC Code Development

Environments

Before we continue let’s get familiar with the dsPIC and the PIC development IDE MPLAB. MPLAB is a free IDE provided by Microchip, the same people who make the PIC and dsPIC products. MPLAB contains support for a simulator, debugger, programmer, and third-party tools. All of the code we develop will be written in C. The first compiler we will use is the C30 product from Microchip. This compiler is an enhanced GNU compiler that provides support for the dsPIC family of processors. We will also be using the language tools library that is included with the C30 product but can also be freely downloaded. This library provides C language wrappers around the silicon impementation of the communications and I/O functions we will need for this prototype. We will also use the HI-TECH dsPICC compiler, which is ANSI compliant, for one of our sample programs. HI-TECH also provides C compilers for all of the PIC products. We will also use the C18 and PIC18 products for developing software for the 18F4550 USB chip and PicBasic Pro for developing and testing code for the older 16C745 low-speed USB chip.

The MPLAB IDE

To provide a consistent development interface, we will use MPLAB 7 from Microchip. MPLAB is free and available for download from www.microchip.com; look for it under development tools. MPLAB includes a built-in simulator, programmer support, debugger support, and support for most third-party tools. We will be using C30 and C18 from Microchip, PICC Enterprise from HI-TECH software, and PicBasic Pro from microEngineering Labs. This combination of tools will give us varied experience along with the quickest path to completion. Once you’ve installed MPLAB an icon on your desktop is used to

Chapter 9

Соседние файлы в предмете Электротехника