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

PIC Microcontroller Project Book: For PIC Basic and PIC Basic Pro Compliers / Edition 2
- 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
Buy New
$38.00Buy Used
$29.55-
SHIP THIS ITEM— Temporarily Out of Stock Online
-
PICK UP IN STORE
Your local store may have stock of this item.
Available within 2 business hours
Temporarily Out of Stock Online
-
SHIP THIS ITEM
Temporarily Out of Stock Online
Please check back later for updated availability.
Overview
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
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 1 | Microcontrollers | 1 |
What Is a Microcontroller? | 1 | |
Why Use a Microcontroller? | 1 | |
Microcontrollers Are the Future of Electronics | 1 | |
Designer Computers--So Many Microcontrollers | 2 | |
The PIC Chip | 2 | |
Better Than Any Stamp | 2 | |
PIC Programming Overview | 4 | |
PICBasic and PICBasic Pro Compilers | 5 | |
EPIC Programmer | 6 | |
Firmware | 7 | |
Consumables | 7 | |
16F84 PIC Microcontroller | 7 | |
Step 1 | Writing Code (The Basic Program) | 8 |
Step 2 | Using the Compiler | 8 |
Step 3 | Installing the Firmware, or Programming the PIC Chip | 9 |
Ready, Steady, Go | 9 | |
Hardware and Software | 10 | |
Parts List | 10 | |
Chapter 2 | Installing the Compiler | 13 |
Installing the PICBasic Compiler Software | 13 | |
Installing PICBasic Pro Compiler | 14 | |
Chapter 3 | Installing the EPIC Software | 23 |
Installing the EPIC Software in Windows | 23 | |
Installing the EPIC Software from DOS | 24 | |
Applications Directory | 26 | |
ZIF Adapter Sockets | 26 | |
AC Adapter | 27 | |
Chapter 4 | CodeDesigner | 29 |
CodeDesigner Features | 29 | |
Software Installation | 31 | |
Setting CodeDesigner Options | 31 | |
First Program | 36 | |
The EPIC Programming Board Software | 40 | |
Parts List | 41 | |
Chapter 5 | How to Use DOS Instead of Windows to Code, Compile, and Program | 43 |
Compile | 47 | |
Programming the PIC Microcontroller Chip | 48 | |
The EPIC Programming Board Software | 51 | |
Using the EPIC DOS Version | 51 | |
Continuing with the WINK.BAS Program | 51 | |
Chapter 6 | Testing the PIC Microcontroller | 55 |
The Solderless Breadboard | 55 | |
Three Schematics, One Circuit | 57 | |
Wink | 60 | |
Troubleshooting the Circuit | 60 | |
PIC Experimenter's Board and LCD | 60 | |
PIC Experimenter's Board | 62 | |
Using the X-Board's LCD: PICBasic and PICBasic Pro Examples | 68 | |
Chapter 7 | PIC 16F84 Microcontroller | 71 |
Advanced PIC Microcontrollers | 71 | |
Back to the 16F84 Microcontroller | 72 | |
Clock Oscillators | 72 | |
Reset | 73 | |
PIC Harvard Architecture | 74 | |
Register Map | 76 | |
Memory Mapped I/O | 76 | |
Binary Fundamentals | 77 | |
Registers and Ports | 79 | |
Using the TRIS and Port Registers | 81 | |
Writing to a Register Using PICBasic Compiler | 82 | |
Writing to a Register Using PICBasic Pro Compiler | 83 | |
Accessing the Ports for Output | 83 | |
Electrical Binary, TTL, and CMOS | 84 | |
Counting Program | 85 | |
Counting in Binary by One | 85 | |
Variable Space | 87 | |
Schematic for Program | 89 | |
Counting Binary Progression | 89 | |
Basic High and Low Commands | 91 | |
Programming Review | 92 | |
Next Chapter--Reading Input Signals | 94 | |
Parts List | 94 | |
Optional Parts | 94 | |
Chapter 8 | Reading I/O Lines | 95 |
Placing Electrical Signals on a Pin | 95 | |
Reading a Port | 96 | |
PICBasic Compiler and Variables B0 and B1 (Bit0 to Bit15) | 98 | |
Dynamic Changes | 99 | |
Delay Variable | 101 | |
Basic Input and Output Commands | 102 | |
Basic Input and Output Commands (Pro Version) | 102 | |
The Button Command | 103 | |
Debouncing a Switch | 103 | |
Auto-Repeat | 104 | |
The Variable Used in the Button Command | 105 | |
Multiple Statements--Single Line | 105 | |
Chapter 9 | PICBasic Language Reference | 107 |
Branch | 107 | |
Button | 108 | |
Call | 110 | |
Eeprom | 110 | |
End | 110 | |
For ... Next | 110 | |
Gosub | 111 | |
Goto | 111 | |
High | 112 | |
12CIN | 112 | |
12cout | 113 | |
If ... Then | 114 | |
Input | 115 | |
Let | 115 | |
Lookdown | 117 | |
Lookup | 117 | |
Low | 118 | |
Nap | 118 | |
Output | 118 | |
Pause | 119 | |
Peek | 119 | |
Poke | 120 | |
Pot | 120 | |
Pulsin | 121 | |
Pulsout | 121 | |
PWM | 122 | |
Random | 123 | |
Read | 123 | |
Return | 123 | |
Reverse | 124 | |
Serin | 124 | |
Serout | 125 | |
Sleep | 127 | |
Sound | 127 | |
Toggle | 128 | |
Write | 129 | |
Chapter 10 | Additional Command Reference for PICBasic Pro | 131 |
Adcin | 134 | |
Asm ... EndAsm | 134 | |
Branchl | 135 | |
Clear | 135 | |
Clearwdt | 135 | |
Count | 135 | |
Data | 135 | |
Debug | 136 | |
Debugin | 136 | |
Disable | 137 | |
Disable Debug | 137 | |
Disable Interrupt | 137 | |
DTMFout | 137 | |
Enable | 137 | |
Enable Debug | 138 | |
Enable Interrput | 138 | |
Freqout | 138 | |
Hserin | 138 | |
Hserout | 138 | |
12cread | 139 | |
12cwrite | 139 | |
If ... Then | 139 | |
Lcdin | 140 | |
Lcdout | 140 | |
Lookdown2 | 141 | |
Lookup2 | 142 | |
On Debug | 142 | |
On Interrupt | 142 | |
Pauseus | 144 | |
Peek | 145 | |
Poke | 145 | |
Pulsin | 145 | |
Pulsout | 146 | |
RCtime | 146 | |
Readcode | 147 | |
Resume | 147 | |
Serin2 | 147 | |
Serout2 | 147 | |
Shiftin | 148 | |
Shiftout | 148 | |
Swap | 148 | |
While...Wend | 148 | |
Writecode | 148 | |
Xin | 149 | |
Xout | 149 | |
Chapter 11 | Speech Synthesizer | 151 |
Speech Chip SPO256 | 151 | |
A Little on Linguistics | 154 | |
Interfacing to the SPO256 | 154 | |
Mode Select | 154 | |
The Circuit | 155 | |
Program Differences | 159 | |
Program Functions | 159 | |
Peek PortA, b0 | 159 | |
Parts List | 160 | |
Chapter 12 | Creating a New I/O Port | 163 |
Serial Communication | 163 | |
Output First | 163 | |
Basic Serial | 164 | |
Clear Pin | 166 | |
First Program | 166 | |
Bit Shift Correcting | 169 | |
Input I/O | 172 | |
Compatibility Issues | 176 | |
Parts List | 177 | |
Chapter 13 | Liquid Crystal Display (LCD) | 179 |
Serout Command's RS-232 Serial Communication | 179 | |
Error-Detection Algorithms | 181 | |
Parity | 181 | |
Serial Format: Mode and Baud Rate | 181 | |
XTAL Clock, Please | 181 | |
4.0 MHz Clock Limitations | 182 | |
Three-Wire Connection | 182 | |
Positioning the Cursor | 185 | |
Off-Screen Memory | 185 | |
PICBasic Pro Project: LCD Module | 186 | |
Using the LCD Module for Display | 188 | |
Parts List | 188 | |
Chapter 14 | Reading Resistive Sensors | 189 |
R/C Values | 190 | |
Scale | 190 | |
PIN Exceptions | 191 | |
Resistive Sensors | 191 | |
Test Program | 191 | |
Fuzzy Logic and Neural Sensors | 194 | |
Fuzzy First | 194 | |
Fuzzy Logic Light Tracker | 196 | |
DC Motor Control | 198 | |
Diodes | 201 | |
Operation | 202 | |
Fuzzy Output | 202 | |
Neural Sensors (Logic) | 203 | |
Multivalue Threshold | 203 | |
Parts List | 206 | |
Chapter 15 | Analog-to-Digital (A/D) Converters | 209 |
Analog Signal | 209 | |
Digital Equivalents | 209 | |
A/D Converters | 210 | |
Setting the Reference Voltage(s) | 212 | |
Voltage Range and Resolution | 212 | |
Interpreting the Results | 212 | |
Serial A/D Converter Chip Control | 213 | |
TLC549 Serial Sequence | 213 | |
Toxic Gas Sensor | 215 | |
Parts List | 217 | |
Chapter 16 | DC Motor Control | 219 |
The Transistor | 219 | |
First Method | 219 | |
Bidirectional | 220 | |
Diodes | 222 | |
Parts List | 223 | |
Chapter 17 | Stepper Motors | 225 |
Stepper Motor Construction and Operation | 225 | |
Resolution | 226 | |
Half-Step | 227 | |
Other Types of Stepper Motors | 227 | |
Real World | 227 | |
First Stepper Circuit | 228 | |
Electrical Equivalent of a Stepper Motor | 229 | |
Test Circuit Program | 231 | |
One Rotation | 232 | |
Second Basic Program | 232 | |
Half-Stepping | 234 | |
The "ti" Delay Variable | 234 | |
Troubleshooting | 236 | |
UCN 5804 Dedicated Stepper Motor ICs | 236 | |
Parts List | 240 | |
Chapter 18 | Servomotors | 241 |
Extending Servo Motor Range | 244 | |
Manual Servo Control | 245 | |
Multiple Servomotors | 247 | |
Timing and Servomotors | 250 | |
PICBasic Pro Compiler Project: Five-Servomotor Controller | 250 | |
Parts List | 254 | |
Chapter 19 | Controlling AC Appliances | 255 |
Inductive and Resistive Loads | 255 | |
Circuit Construction | 256 | |
Test Circuit | 260 | |
Smart Control | 260 | |
Electronic Nose | 261 | |
Parts List | 261 | |
Chapter 20 | A Few More Projects | 263 |
Binary Clock | 263 | |
Setting the Clock | 265 | |
Digital Geiger Counter | 266 | |
Frequency Generator | 268 | |
In Closing | 269 | |
Suppliers Index | 271 | |
Hexadecimal Numbers | 273 | |
Index | 275 |