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.
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.
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
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.
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.
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