PIC Microcontroller Project Book: For PIC Basic and PIC Basic Pro Compliers / Edition 2

PIC Microcontroller Project Book: For PIC Basic and PIC Basic Pro Compliers / Edition 2

by John Iovine
ISBN-10:
0071437045
ISBN-13:
9780071437042
Pub. Date:
03/29/2004
Publisher:
McGraw Hill LLC
ISBN-10:
0071437045
ISBN-13:
9780071437042
Pub. Date:
03/29/2004
Publisher:
McGraw Hill LLC
PIC Microcontroller Project Book: For PIC Basic and PIC Basic Pro Compliers / Edition 2

PIC Microcontroller Project Book: For PIC Basic and PIC Basic Pro Compliers / Edition 2

by John Iovine
$38.0
Current price is , Original price is $38.0. You
$38.00 
  • SHIP THIS ITEM
    Temporarily Out of Stock Online
  • PICK UP IN STORE
    Check Availability at Nearby Stores
$29.55  $38.00 Save 22% Current price is $29.55, Original price is $38. You Save 22%.
  • SHIP THIS ITEM

    Temporarily Out of Stock Online

    Please check back later for updated availability.

    Note: Access code and/or supplemental material are not guaranteed to be included with used textbook.

Temporarily Out of Stock Online


Overview

Publisher's Note: Products purchased from Third Party sellers are not guaranteed by the publisher for quality, authenticity, or access to any online entitlements included with the product.




This completely updated version of the best-selling PiC Microcontroller Project Book boasts updated software, many new projects, and comprehensive coverage of the new PIC Basic Pro version of the controller


The PIC microcontroller is enormously popular both in the U.S. and abroad. The first edition of this book was a tremendous success because of that. However, in the 4 years that have passed since the book was first published, the electronics hobbyist market has become more sophisticated. Many users of the PIC are now comfortable shelling out the $250 for the price of the Professional version of the PIC Basic (the regular version sells for $100). This new edition is fully updated and revised to include detailed directions on using both versions of the microcontroller, with no-nonsense recommendations on which is better served in different situations.

Product Details

ISBN-13: 9780071437042
Publisher: McGraw Hill LLC
Publication date: 03/29/2004
Series: Tab Robotics
Edition description: REV
Pages: 292
Product dimensions: 7.30(w) x 9.20(h) x 0.90(d)

About the Author

Electronics professional John Iovine is the author of several popular TAB titles that explore the frontiers of science. He wrote the cult classic Robots, Androids, and Animatrons. He also wrote such popular books as Homemade Holograms: The Complete Guide to Inexpensive, Do-It-Yourself Holography; Kirlian Photography: A Hands-On Guide; Fantastic Electronics: Build Your Own Negative-Ion Generator and Other Projects; and A Step into Virtual Reality. He is the "Amazing Science" columnist for Poptronics magazine and a regular contributor to Nuts and Volts.

Read an Excerpt

Chapter 1: Microcontroller

What Is a Microcontroller?

A microcontroller is an inexpensive single-chip computer. Single-chip computer means that the entire computer system lies within the confines of the integrated circuit chip. The microcontroller on the encapsulated sliver of silicon has features similar to those of our standard personal computer. Primarily, the microcontroller is capable of storing and running a program (its most important feature). The microcontroller contains a CPU (central processing unit), RAM (random-access memory), ROM (read-only memory), 1/O (input/output) lines, serial and parallel ports, timers, and sometimes other built-in peripherals such as A/D (analog-to-digital) and D/A (digital-to-analog) converters.

Why Use a Microcontroller?

Microcontrollers, as stated, are inexpensive computers. The microcontroller's ability to store and run unique programs makes it extremely versatile. For instance, one can program a microcontroller to make decisions (perform functions) based on predetermined situations (1/O-line logic) and selections. The microcontroller's ability to perform math and logic functions allows it to mimic sophisticated logic and electronic circuits.

Other programs can make the microcontroller behave like a neural circuit and/or a fuzzy-logic controller. Microcontrollers are responsible for the "intelligence" in most smart devices on the consumer market.

The Future of Electronics Is Here-It's Microcontrollers

Look in any hobbyist electronics magazine from this country or any other. You will see articles that feature the use of microcontrollers, either directly or embedded in the circuit's design. Becauseof their versatility, microcontrollers add a lot of power, control, and options at little cost. It therefore becomes essential that the electronics engineer or hobbyist learn to program these microcontrollers to maintain a level of competence and to gain the advantages microcontrollers provide in his or her own circuit designs.

If you examine consumer electronics, you will find microcontrollers embedded in just about everything. This is another reason to become familiar with microcontrollers.

Designer Computers

There is a large variety of microcontrollers on the market today. We will focus on a few versatile microcontroller chips called PIC chips (or PICMicro chips) from Microchip Technology.

The PIC Chip

Microchip Technology's series of microcontrollers is called PIC chips. Microchip secured a trademark for the name PIC. Microchip uses PIC to describe its series of PIC microcontrollers. PIC is generally assumed to mean programmable interface controller.

Better Than Any Stamp

Parallax Company sells an easy-to-use series of microcontroller circuits called the Basic Stamp. Parallax's Basic Stamps (BS1 and BS2) use Microchip Technology's PIC microcontrollers. What makes the Stamps so popular and easy to use is that they are programmed using a simplified form of the Basic language. Basic-language programming is easy to learn and use. This was the Stamps' main advantage over other microcontroller systems, which have a much longer learning curve because they force their users and developers to learn a niche assembly language. (A niche assembly language is one that is specific to that company's microcontroller and no one else's.)

The Basic Stamp has become one of the most popular microcontrollers in use today. Again, the Basic Stamp's popularity (this bears repeating) is due to its easy-to-learn and easy-to-use Basic-language programming. The PIC's Basiclanguage system is just as easy to learn and use, and the PIC has enormous benefits that make it better than any Stamp.

The Basic language of the PICBasic compiler that we will use to program the PIC chips is similar to that used in the Basic Stamp series. Programming PIC chips directly has just become as easy as programming Stamps. Now you can enjoy the same easy language the Basic Stamp offers, plus two more very important benefits.

Benefit one: faster speed

Our programmed PIC chips will run their program much faster. If we enter the identical Basic program into a Basic Stamp and into a PIC chip, the programmed PIC chip will run 20 to 100 times faster (depending upon the instructions used) than the Basic Stamp. Here's why.

The BS1 and BS2 Basic Stamp systems use a serial EEPROM memory connected to the PIC chip to store their programs. The basic commands in the program are stored as basic tokens. Basic tokens are like a shorthand for basic commands. When running the program, the Basic Stamp reads each instruction (token and data/address) over the serial line from the external EEPROM memory, interprets the token (converts token to the ML equivalent the PIC can understand), performs the instruction, reads the next instruction, and so on. Each and every instruction goes through these serial load, read, interpret, then perform steps as the program runs. The serial interface reading routine eats up gobs of the microcontroller's CPU time.

In contrast to this operation, when a PIC chip is programmed using the Basic compiler, the Basic program is first converted to a PIC machinelanguage (hex file) program. The ML program is then uploaded into the PIC chip. Being the native language of the PIC, this machine-language (ML) code does not need to be stored as tokens and interpreted as it runs because the program is written in the PIC chip's native language.

When the PIC chip runs the program, it reads the ML program instructions directly from its on-board memory and performs the instruction. There is no serial interface to an external EEPROM to eat up CPU time. The ML instructions are read in parallel, not bit by bit as in the serial interface. The ML instructions read directly without any basic-token-to-ML-equivalent conversion required. This enables programmed PIC chips to run their code 20 to 100 times faster than the same Basic program code in a Basic Stamp.

Benefit two: much lower cost

The next factor is cost. Using PIC chips directly will save you 75 percent of the cost of a comparable Basic Stamp. The retail price for the BS1, which has 256 bytes of programmable memory, is $34.95. The retail price for the BS2, which has 2K of programmable memory, is $49.95. The 16F84 PIC microcontroller featured throughout this book is more closely comparable to the BS2 Stamp. The 16F84 PIC chip we are using has 1K of programmable memory.

The retail cost of the 16F84 PIC chip is $6.95. To this, add the cost of a timing crystal, a few capacitors, a few resistors, and a 7805 voltage regulator to make a circuit equivalent to that of the Stamp. These components increase the total cost to about $10.00-still well below one-quarter the cost (75 percent savings) currently quoted for the BS2.

And this $10.00 cost for the PIC may be cut substantially in some situations...

Table of Contents

Chapter 1Microcontrollers1
What Is a Microcontroller?1
Why Use a Microcontroller?1
Microcontrollers Are the Future of Electronics1
Designer Computers--So Many Microcontrollers2
The PIC Chip2
Better Than Any Stamp2
PIC Programming Overview4
PICBasic and PICBasic Pro Compilers5
EPIC Programmer6
Firmware7
Consumables7
16F84 PIC Microcontroller7
Step 1Writing Code (The Basic Program)8
Step 2Using the Compiler8
Step 3Installing the Firmware, or Programming the PIC Chip9
Ready, Steady, Go9
Hardware and Software10
Parts List10
Chapter 2Installing the Compiler13
Installing the PICBasic Compiler Software13
Installing PICBasic Pro Compiler14
Chapter 3Installing the EPIC Software23
Installing the EPIC Software in Windows23
Installing the EPIC Software from DOS24
Applications Directory26
ZIF Adapter Sockets26
AC Adapter27
Chapter 4CodeDesigner29
CodeDesigner Features29
Software Installation31
Setting CodeDesigner Options31
First Program36
The EPIC Programming Board Software40
Parts List41
Chapter 5How to Use DOS Instead of Windows to Code, Compile, and Program43
Compile47
Programming the PIC Microcontroller Chip48
The EPIC Programming Board Software51
Using the EPIC DOS Version51
Continuing with the WINK.BAS Program51
Chapter 6Testing the PIC Microcontroller55
The Solderless Breadboard55
Three Schematics, One Circuit57
Wink60
Troubleshooting the Circuit60
PIC Experimenter's Board and LCD60
PIC Experimenter's Board62
Using the X-Board's LCD: PICBasic and PICBasic Pro Examples68
Chapter 7PIC 16F84 Microcontroller71
Advanced PIC Microcontrollers71
Back to the 16F84 Microcontroller72
Clock Oscillators72
Reset73
PIC Harvard Architecture74
Register Map76
Memory Mapped I/O76
Binary Fundamentals77
Registers and Ports79
Using the TRIS and Port Registers81
Writing to a Register Using PICBasic Compiler82
Writing to a Register Using PICBasic Pro Compiler83
Accessing the Ports for Output83
Electrical Binary, TTL, and CMOS84
Counting Program85
Counting in Binary by One85
Variable Space87
Schematic for Program89
Counting Binary Progression89
Basic High and Low Commands91
Programming Review92
Next Chapter--Reading Input Signals94
Parts List94
Optional Parts94
Chapter 8Reading I/O Lines95
Placing Electrical Signals on a Pin95
Reading a Port96
PICBasic Compiler and Variables B0 and B1 (Bit0 to Bit15)98
Dynamic Changes99
Delay Variable101
Basic Input and Output Commands102
Basic Input and Output Commands (Pro Version)102
The Button Command103
Debouncing a Switch103
Auto-Repeat104
The Variable Used in the Button Command105
Multiple Statements--Single Line105
Chapter 9PICBasic Language Reference107
Branch107
Button108
Call110
Eeprom110
End110
For ... Next110
Gosub111
Goto111
High112
12CIN112
12cout113
If ... Then114
Input115
Let115
Lookdown117
Lookup117
Low118
Nap118
Output118
Pause119
Peek119
Poke120
Pot120
Pulsin121
Pulsout121
PWM122
Random123
Read123
Return123
Reverse124
Serin124
Serout125
Sleep127
Sound127
Toggle128
Write129
Chapter 10Additional Command Reference for PICBasic Pro131
Adcin134
Asm ... EndAsm134
Branchl135
Clear135
Clearwdt135
Count135
Data135
Debug136
Debugin136
Disable137
Disable Debug137
Disable Interrupt137
DTMFout137
Enable137
Enable Debug138
Enable Interrput138
Freqout138
Hserin138
Hserout138
12cread139
12cwrite139
If ... Then139
Lcdin140
Lcdout140
Lookdown2141
Lookup2142
On Debug142
On Interrupt142
Pauseus144
Peek145
Poke145
Pulsin145
Pulsout146
RCtime146
Readcode147
Resume147
Serin2147
Serout2147
Shiftin148
Shiftout148
Swap148
While...Wend148
Writecode148
Xin149
Xout149
Chapter 11Speech Synthesizer151
Speech Chip SPO256151
A Little on Linguistics154
Interfacing to the SPO256154
Mode Select154
The Circuit155
Program Differences159
Program Functions159
Peek PortA, b0159
Parts List160
Chapter 12Creating a New I/O Port163
Serial Communication163
Output First163
Basic Serial164
Clear Pin166
First Program166
Bit Shift Correcting169
Input I/O172
Compatibility Issues176
Parts List177
Chapter 13Liquid Crystal Display (LCD)179
Serout Command's RS-232 Serial Communication179
Error-Detection Algorithms181
Parity181
Serial Format: Mode and Baud Rate181
XTAL Clock, Please181
4.0 MHz Clock Limitations182
Three-Wire Connection182
Positioning the Cursor185
Off-Screen Memory185
PICBasic Pro Project: LCD Module186
Using the LCD Module for Display188
Parts List188
Chapter 14Reading Resistive Sensors189
R/C Values190
Scale190
PIN Exceptions191
Resistive Sensors191
Test Program191
Fuzzy Logic and Neural Sensors194
Fuzzy First194
Fuzzy Logic Light Tracker196
DC Motor Control198
Diodes201
Operation202
Fuzzy Output202
Neural Sensors (Logic)203
Multivalue Threshold203
Parts List206
Chapter 15Analog-to-Digital (A/D) Converters209
Analog Signal209
Digital Equivalents209
A/D Converters210
Setting the Reference Voltage(s)212
Voltage Range and Resolution212
Interpreting the Results212
Serial A/D Converter Chip Control213
TLC549 Serial Sequence213
Toxic Gas Sensor215
Parts List217
Chapter 16DC Motor Control219
The Transistor219
First Method219
Bidirectional220
Diodes222
Parts List223
Chapter 17Stepper Motors225
Stepper Motor Construction and Operation225
Resolution226
Half-Step227
Other Types of Stepper Motors227
Real World227
First Stepper Circuit228
Electrical Equivalent of a Stepper Motor229
Test Circuit Program231
One Rotation232
Second Basic Program232
Half-Stepping234
The "ti" Delay Variable234
Troubleshooting236
UCN 5804 Dedicated Stepper Motor ICs236
Parts List240
Chapter 18Servomotors241
Extending Servo Motor Range244
Manual Servo Control245
Multiple Servomotors247
Timing and Servomotors250
PICBasic Pro Compiler Project: Five-Servomotor Controller250
Parts List254
Chapter 19Controlling AC Appliances255
Inductive and Resistive Loads255
Circuit Construction256
Test Circuit260
Smart Control260
Electronic Nose261
Parts List261
Chapter 20A Few More Projects263
Binary Clock263
Setting the Clock265
Digital Geiger Counter266
Frequency Generator268
In Closing269
Suppliers Index271
Hexadecimal Numbers273
Index275
From the B&N Reads Blog

Customer Reviews