Bailey O.H.Embedded systems.Desktop integration.2005
.pdf
340 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
|
|
|
|
|
DEBUG Dbyte |
// Display to Debug Console |
|
NEXT |
|
// Until LoopCtr = DLen |
DEBUG CR |
|
// Send CR to debug Console |
LOW Reset |
|
// Bring Reset Low |
RETURN |
|
|
WriteMem: |
|
// Write Scratchpad to RAM |
HIGH Reset |
// Bring Reset High |
|
SHIFTOUT Dio, Clk, LSBFIRST, [Cscp] |
// Output Control Byte |
|
SHIFTOUT Dio, Clk, LSBFIRST, [SMem, EMem, DLen]// Output RAM Start, End, and Length |
||
DEBUG DEC3 TA1, DEC3 TA2, DEC3 DLen, CR |
// Check Values to debug Screen |
|
DO |
|
// Do |
PAUSE 1 |
|
// Wait 1 ms |
LOOP UNTIL (Dio <> 0) |
// Until Data Line is Low |
|
LOW Reset |
|
// Bring Reset Low |
RETURN |
|
|
ReadRAM: |
|
// Read from DS2404 RAM |
HIGH Reset |
// Bring Reset High |
|
SHIFTOUT Dio, Clk, LSBFIRST, [RMem] |
// Output Control Byte |
|
SHIFTOUT Dio, Clk, LSBFIRST, [SMem, EMem] |
// Output Start & End RAM Locations |
|
FOR LoopCtr = 0 TO Dlen |
// Loop from 0 to DLen |
|
SHIFTIN Dio, Clk, LSBPRE, [Dbyte] |
// Read RAM Location Byte |
|
// WRITE DLen, DByte |
// Write to EEPROM |
|
DEBUG Dbyte |
// Send to Debug Terminal |
|
NEXT |
|
// Increment LoopCtr |
DEBUG CR |
|
// Send CR to Debug Console |
LOW Reset |
|
// Bring Reset Low |
RETURN |
|
|
Listing 8-12 is much smaller than Listing 8-11. Running this listing on either of the 3-Wire boards from Chapter 7 will produce the following output to the BS2 Debug terminal.
342 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
Figure 8-43
Listing 8-13
//Test Program for RS-232 output using MAX232 with RTS/CTS Handshaking
//for Embedded Systems Desktop Integration Chapter 8
//Copyright 2004 - Oliver H. Bailey
//
// Pins are assigned in the following order:
// Pin 12 - |
Transmit Data |
(TX or TD) => |
||
// Pin 14 |
- |
Receive Data |
(RX or RD) <= |
|
// Pin 13 |
- |
Clear To Send |
(CTS) |
=> |
// Pin 15 |
- Request To Send (RTS) |
<= |
||
// |
|
|
|
|
//This program uses the FPin variable on SerIn and SerOut commands. Example follows below
//Serout 12\15, 110, "Mary had a little lamb" CR, LF
InData VAR Byte
OutData VAR Byte
344 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
Figure 8-44
From the upper left going clockwise, are the Dallas temperature/clock/relay board, Matrix Orbital LK202-25 display, keyboard/alarm board, BS2p board, DLP Designs USB232BM board, and the NetBurner SB72 board. Not shown are the RS-232 host interface, the Parallax USB2SER board, and 7805 power supply.
Chapter Summary
We covered a lot of ground in this chapter and implemented several types of communications interfaces, two different Maxim/Dallas interfaces, and an I2C interface for the LCD. All of the remaining hardware chapters will use the same I/O boards and we will focus on the differences in the processors we use. The finished programs for the thermostat can be found at www.wordware.com/files/embsys or at www.time-lines.com.
346 |
Chapter 9 / The PIC Prototype |
|
|
This chapter has fewer photos and diagrams than the previous chapters. This is not an accident. The MPLAB IDE that is used in this chapter has its own documentation. I could never do that product justice by attempting to cover its features here so I have chosen to provide the logic and code snippets behind the implementation. This eliminates distracting you, the reader, from the main objective, which is developing the embedded device using the PIC microcontroller. I provide just enough code for you to test each feature and leave the main listings for you to download. Each listing is fully annotated as to what happens when and why it happens. This allows me to present the complete thought and implementation logic without again distracting you from the main development objective. Since the code is fully annotated it also allows you to use the code to build upon the design without having to have the book open. There is nothing I hate worse than having to open multiple documents or books at the same time to understand a subject.
Similarities between the BASIC Stamp and the PIC
The BASIC Stamp and the PIC share a similar BASIC language. This allows a quick prototype to be developed using the BASIC Stamp and then compiling the source using a third-party compiler to achieve the same functionality in the PIC. There are some implementation differences between the BS2p and the PIC. One example of this is POLLIN and POLLOUT commands on the BS2. The PIC instead supports interrupts — hardware features handled by software functions — so there is no need for these commands. An interrupt does not wait to be serviced as the POLL commands on the BASIC Stamp do. There is also no extra code needed between each BASIC command.
348 |
Chapter 9 / The PIC Prototype |
|
|
Types of PIC Microcontrollers and
Development Languages
There are literally hundreds of different PIC microcontroller configurations, but they can be broken down into different groups. They are:
8 bit
16 bit
Digital signal processing
Peripheral processing
Memory management
Power management
All of the PIC microcontrollers utilize the Harvard memory architecture, which uses a banked memory scheme instead of linear addressing.
Now let’s take a look at available compilers for the PIC processor line. The products range from free to about $1,000 depending on the source and type of compiler. Let’s take a look at the available languages for the PIC processor lines:
Assembler — Available free from Microchip and included with other products as well. Comes complete with an IDE.
The C language — Available from several vendors both in the U.S. and abroad. Prices range from free to about $1,000.
The C++ language — Available from at least one vendor, this product is priced below $100.
Pascal — Available from at least one vendor and also priced below $100.
BASIC — Available from several vendors and priced from $50 to $250 depending on compiler type and features.
