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

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

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

390

Chapter 9 / The PIC Prototype

 

 

The TTL Serial Routine

The only remaining communications routine to implement is the TTL serial interface for the 16C745 device. I need to again stress that the compiler suite for this device is different from the dsPIC, so we will be using different tools. There are differences in the number of pins and functionality of the different PIC processors. This time we will show how to create two TTL serial ports on Port B and handle SUB I/O using PicBasic Pro. Listing 9-8, when used in conjunction with the HIDmaker files and the USB init and I/O files from Microchip, illustrates how to set up our two serial ports and send a USB message.

Listing 9-8

//Chapter 9 USB & Serial Port Test

//Embedded Systems, Desktop Integration

//Copyright 2004, Oliver H. Bailey

//

//This program illustrates how USB and serial

//code can co-exist.

//

//First we define the I/O pins to use on the 16C745

//For this example we will assign two TTL serial

//ports to the pins on port RB. The following code

//will send the hello world string to our first

//defined TTL port.

//

//This code works in conjunction with the HIDmaker code defined

//earlier and the endpoint descriptors created by HIDmaker.

//This program is also dependent on the USB initialization,

//and I/O assembler routines from Microchip

//Declare Byte Array for Message

Msg var byte[11]

// Assign String to Array Msg[0] = "H"

Msg[1] = "e"

Chapter 9 / The PIC Prototype

391

 

 

Msg[2] = "l"

Msg[3] = "l"

Msg[4] = "o"

Msg[5] = "W"

Msg[6] = "o"

Msg[7] = "r"

Msg[8] = "l"

Msg[9] = "d"

Msg[10] = 0

//Serial Output with flow control, 84 = 9600 Baud

//First TTL Serial Port

SEROUT2 PORTB.0\PORTB.2, 84, [Msg]

//Do it Again for Second Serial Port Serout2 Portb.4\portb.6, 84, [Msg]

//Initialize USB

usbinit

//SendUSB is defined as send from PIC, not Host! sendUSB:

//Send the Msg Array to EndPoint 0.

//If transmission can't be made jump to busy and wait 10 ms

//Then try again

usbout 1, Msg, 11, busy

//Once the message is sent, goto complete. goto complete

busy: pause 10

goto sendUSB

//End of program

complete: end

Chapter 9

392

Chapter 9 / The PIC Prototype

 

 

The Finished Circuit

Unlike the BASIC Stamp, there are a few more components required for the PIC version. To start with, we have to supply a clock source. The dsPIC can be controlled through an external or internal clock source. For this circuit we will use an external clock because it provides a higher speed. Following is the parts list for the dsPIC interface board:

One 24 mHz crystal oscillator

One 2.2 K ¼-watt resistor

Two 4.7 K ¼-watt resistors

One red power LED

One 7805 voltage regulator

One normally open push button switch

One 1N914 diode

One 2-pole terminal strip

Two 3-pole terminal strips

Three 3-pole terminal strips

One dsPIC 30F2010 microcontroller

Since the dsPIC is a relatively new product, please check the current data sheet at www.microchip.com for the latest information on recommended clock crystals. The dsPIC 30F2010 can be purchased from Microchip, DigiKey, or Jameco, as can the rest of these parts. The terminal strips are standard 0.1" center-to-cen- ter and are also available from the above sources. In earlier parts list I have listed Radio Shack as a source. While Radio Shack does carry the resistors, diodes, and LEDs, they don’t have a wide selection of terminal strips, which is why they are not listed here. DigiKey is the best source and has all of the above components.

Chapter 9 / The PIC Prototype

393

 

 

Because of the increased complexity of our circuit, this time we will need to make a two-sided circuit board. If you wish to purchase the board instead, please visit www.time-lines.com and follow the Embedded Systems 1 Component link. If you choose to make your own boards, the schematics follow.

Chapter 9

Figure 9-18

394

Chapter 9 / The PIC Prototype

 

 

 

 

 

 

 

 

 

 

 

 

Figure 9-19

If you wish to make the boards using the photoetching process, then you will need to print the images to laser transparency film first. This differs from previous artwork, which can be transferred to transparency film using a copier.

Chapter 9 / The PIC Prototype

395

 

 

Chapter Summary

We have covered a lot of ground in this chapter. Let’s review the steps that we’ve taken to build our temperature control using the dsPIC and PIC 16C745 communications controller. We began by interfacing the dsPIC to a TTL serial port for interfacing to the host communications controller. We then added SPI support for communicating with the memory portion of the DS2404. We then implemented the I2C interface to our LCD display using a software implementation of the I2C protocol. Next, we developed the USB communications software for the PIC 16C745 communications processor and the Windows host software. We haven’t worked with the application side yet because our product is cross platform. Then we implemented the UDP code for the NetBurner Ethernet controller. Finally, we implemented two TTL serial ports in the PIC 16C745, one for the Ethernet controller interface and the other for the RS-232 interface. Both interfaces will be used for host communications. A third serial interface will need to be implemented for communication with the embedded controller. I used RA0 to RA3 for the final TTL serial interface. Since we have a limited amount of storage RAM on the 16C745, we will use our protocol between the communications controller and the embedded system. This means we will be sending data in smaller chunks when necessary, so we will be using the handshake lines between the embedded controller and the communications controller to signal when data can be transmitted. All of the complete source code listings can be found at www.wordware.com/files/embsys or www.time-lines.com.

The next chapter is on using the Cypress EZ-USB and PSoC. Chapter 11 deals with cross-platform development.

Chapter 9

This page intentionally left blank.

Chapter 10

The PSoC Prototype

Well, we’ve finally made it to our last hardware chapter. Some of the information regarding Ethernet and RS-232 may seem redundant but covering the differences from prior hardware platforms is a very important topic. We will continue to use the NetBurner SB72 board and the same TTL-to-RS-232 interface we developed earlier, with a few code changes to each that are specific to the PSoC. I’ll also introduce you to the EZ-USB from the same maker as the PSoC. This chapter will focus only on the differences in the hardware and software from prior hardware chapters. If you’ve made it this far, then read on because there are some very interesting things the PSoC and EZ-USB are capable of.

What Is the PSoC?

PSoC is an acronym for Programmable System on Chip. On the surface the PSoC appears to be just another microcontroller, but if we look a little closer there are some significant differences.

We will begin by highlighting the unique features of the PSoC and then compare the PSoC to the PIC and finally to the BASIC Stamp. So let’s begin with the PSoC highlights.

The short definition of the PSoC is software configurable silicon. When designing a PSoC system the hardware is defined

397

398

Chapter 10 / The PSoC Prototype

 

 

through software using several different steps. The PSoC chip can actually be several different devices within the same chip that interact together or act as separate components. In addition the PSoC can be reprogrammed on the fly, allowing each device (or block) within the PSoC to have several personalities depending on event triggers or interrupts. This feature is what makes the PSoC different from the other microcontrollers we’ve worked with so far. This chapter will not cover on-the-fly programming because of the subject scope; instead we will implement functions comparable to the PIC and BASIC Stamp equivalents. For more information on the advanced features of the PsoC, visit the Cypress web site at www.cypress.com or my site at www.time-lines.com.

Developing PsoC-based hardware is heavily dependent on software, namely the PSoC Designer. Everything from designing PSoC hardware blocks and writing source code to debugging in-circuit emulation is handled by the PSoC Designer. The PSoC Designer provides a selection of “canned” hardware functions that can be plugged in by simply dragging and dropping the function onto the design screen. Using the Designer the engineer can define which pins provide associated functions. As different functions are added, how different hardware functions can interact through the use of registers and memory can be defined. Later in this chapter we will work through an actual design session for our thermostat.

Comparing the PIC and the PSoC

At first glance both of these microcontrollers seem identical. Both allow the engineer to design using a building block approach. Both allow analog and digital signals to be processed and both come with similar amounts of RAM and even similar packages. Even so, there are many differences between these devices.

Chapter 10 / The PSoC Prototype

399

 

 

The first major difference (and the most obvious) is the PSoC’s ability to alter or load programs on the fly. In short, conditional events or interrupts can allow a program block to load alternate software for processing. While this is a useful feature, care must be taken to avoid problems that can arise from redefining I/O pins, their functions, and data direction. Unlike the dsPIC, which has all of its I/O pins predefined by function, the PSoC instead allows the engineer to develop in blocks and assign pins based on analog or digital functionality. There is more flexibility because the designer has more control over how the pins are defined and how the blocks interact and share data. For example, the dsPIC only provides two UARTs, whereas the PSoC can have as many UARTs as allowed by the number of pins and memory. It should be noted that there is a maximum number of analog and digital blocks available on every part, so there are limits to the design.

The last and most important difference is the ability to extend the PSoC Designer with custom devices. If a unique or custom block is developed, it can be added permanently to the Designer in one of the existing categories, allowing a starting point for a new hardware design. In fact, that is exactly how we implement the Dallas 1-Wire interface. The PSoC goes beyond the dsPIC in being able to define blocks of functionality, thereby allowing a custom processor to be built on the fly. The PSoC allows custom-defined microcontrollers to be developed while protecting the intellectual property within them. In short, a PSoC can be used to define a custom analog or digital chip that can be remarketed for a specific use while protecting the code and techniques used to create the part.

As we have already seen in Chapter 9, the differences between the BASIC Stamp and PIC are many. Those same differences apply here so we won’t cover that topic again. If you’ve never used the PSoC before I strongly suggest going to the Cypress Semiconductor web site at www.cypress.com and taking a look at the documentation and samples. Learning how to use this chip takes some preplanning, and before changing functions on the fly, you must think about your end circuit so as not to

Chapter 10

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