PIC Microcontroller Project Book For PiCBasic and PICBasic Pro Compilers John lovine Pe & - “ Second Edition ¡ THỨ VIỆN TRƯỜNG ĐHSPKT | McGraw-Hill New York Chicago San Fr
Trang 1
§0Imnnletely updated and
1⁄Ì
MTICROCONTROLLER:
PROUJ ECT BOOK
T119 i = nes,
Ne 4 “
= == Details for -
2 projects n
Trang 2
a
vn"
PIC Microcontroller
Project Book
For PiCBasic and PICBasic
Pro Compilers
John lovine
Pe
& -
“
Second Edition
¡ THỨ VIỆN TRƯỜNG ĐHSPKT |
McGraw-Hill
New York Chicago San Francisco Lisbon London Madrid
Mexico City Milan New Delhi San Juan Seoul
Singapore Sydney Toronto
Trang 3
Contents
Chapter 1 Microcontrollers
ye
What Is a Microcontroller?
4 Why Use a Microcontroller?
„
Microcontrollers Are the Future of Electronics
Designer Computers—So Many Microcontrollers
The PIC Chip
Better Than Any Stamp
Benefit 1: Faster Speed
Benefit 2: Lower Cost
Bonus Advantage
PIC Programming Overview
Software and Hardware
"
PICBasic and PICBasic Pro Compilers ⁄
EPIC Programmer
* Serial Port and Universal Serial Bus (USB) EPIC Programmer
Firmware
Consumables
16F84 PIC Microcontroller
Step 1: Writing Code (The Basic Program)
Step 2: Using the Compiler
Step 3: Installing the Firmware, or Programming the PIC Chip
Ready, Steady, Go
Hardware and Software
Parts List
Chapter 2 Installing the Compiler
Installing the PICBasic Compiler Software
Installing PICBasic Pro Compiler
COCLPMNINNIOD
ORR RON Noon
13 14
Trang 4vi Contents
Installing the EPIC Software in Windows 23 installing the EPIC Software from DOS ` 24 Applications Directory 26 ZIF Adapter Sockets 26
AC Adapter : 27
CodeDesigner Features 29 Software Installation 31 Setting CodeDesigner Options 31 First Program 36 The EPIC Programming Board Software 40 Parts List & 41
to Code, Compile, and Program 43
Compile 47 Programming the PIC Microcontroller Chip 48 The EPIC Programming Board Software 51
Continuing with the WINK.BAS Program 51
The Solderless Breadboard 4; 55
Wink 60 Troubleshooting the Circuit 60 PIC Experimenter’s Board and LCD 60 PIC Experimenter’s Board 62 Usage 63 Bank 3 Is the Same as Bank 2 66 Simple Experiment 66 Using the X-Board’s LCD: PICBasic and PiCBasic Pro Examples 68
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
Trang 5
Contents vii
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 User Available RAM
87 Changing Variable Names (PICBasic Compiler)
87 Overwriting RAM Space
88 Schematic for Program
89
Counting Binary Progression
Basic High and Low Commands
Programming Review
47 92
Comments
a 92 Identifiers
92 Line Labels
93 Symbols
93 Variables
93 Next Chapter—Reading Input Signals
94 Parts List ;
94
Optional Parts
94
Placing Electrical Signals on a Pin rf
95 Reading a Port
96
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
Button Example
104
The Variable Used in the Button Command
105 Multiple Statements—Single Line
105
Branch
107 Button
108 Call
110
Trang 6viii Contents
Eeprom 110
End 110
Gosub Nesting 111
Goto 111
High : 112
I2CIN 112
Input 115
Let 115
Lookup 117
Nap we 118
Output ae 118
PWM 122
Serin ; / 124
Sleep 127
Additional Sleep Notes 127
Toggle 128
Write 129
for PICBasic Pro 131
Adcin 134
Data 135
Debug 136
Debugin 136
Trang 7Disable
Disable Debug
Disable Interrupt
DTMFout
Enable
Enable Debug
Enable Interrput
Freqout
Hserin
Hserout
I2cread
l2cwrite
lf Then
Ledin
Ledout
Lookdown2
Lookup2
On Debug
On Interrupt
Pauseus
Peek
Poke
Pulsin
Pulsout
RCtime
Readcode
Resume
Serin2
Serout2
Shiftin
Shiftout
Swap
While Wend
Writecode
Xin
Xout
Speech Chip SPO256
A Little on Linguistics
Interfacing to the SPO256
Mode Select
The Circuit
Program Differences
Program Functions
Peek PortA, b0
Parts List
137
137
137
137
137
138
138
138
138
138
139
139
139
140
140
141
142
142
142
144
145
145
145
146
146
147
147
147
147
148
148
148
148
148
149
149
151
151
154
154
154
155
159
159
159 160
Trang 8x Contents
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
Serout Command’s RS-232 Serial Communication 179
Error-Detection Algorithms „ 181
Parity ra 181 -
Serial Format: Mode and Baud Rate v2 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 a 188
Scale 190
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
Analog Signal 209
Digital Equivalents 209
Trang 9Contents xi
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
,
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 T 229 Test Circuit Program ‘ 231
One Rotation 2 , 232
Second Basic Program if 232 Half-Stepping 234 The “ti” Delay Variable 234 Troubleshooting 236 UCN 5804 Dedicated Stepper Motor ICs 236 Parts List 240
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
Inductive and Resistive Loads 255 Circuit Construction 256
Trang 10xii Contents
Smart Control
Electronic Nose
Parts List
Binary Clock
Setting the Clock
Digital Geiger Counter
Frequency Generator
In Closing
Suppliers Index
Hexadecimal Numbers
Index
260
261
261
263
263
265
266
268
269
271
273 275
Trang 11an đang có trong tay thông tin cơ bản của một trong số những tài liệu có hàm lượng chất xám cao, với những thông tin vô cùng hữu ích cho quá trình học tập và
nghiên cứu của bản thân bạn !
Bạn đã và đang trải qua những ưu tư, trăn trở của bản thân mình trước biển kiến thức mênh mông vô hạn
và đang tìm hướng đi cho riêng mình bằng việc biến
HCM chia sẻ những khó khăn và trăn tr đó cùng bạn!
Tp HCM để cùng nhau, chúng ta xây dựng vương quốc khoa
ee : THU VIEN
Cùng với bạn, Thư viện ĐH Sư phạm Kỹ thuật Tp
HCM mong ước gop phan duy trì và phát triển văn hóa
QD doc!
X
THU VIEN
Kỹ thuật Tp HCM để cảm nhận, trải nghiệm và biến ước
mơ khoa học của bạn thành hiện thực ! 4ù
Hân hạnh được đón tiếp và phục vụ bạn tại
Số I~ 3, Võ Văn Ngân, Phường Linh Chiểu, Quận Thủ Đức, Tp HCM \
DT: (08) 3896 9920 — Email: thuvienspkt@hemute.edu.vn a, ae
Trang 13oy @Qos~
( l `% cùng hữu ích cho quá trình học tập và
bản thân mình trước biển kiến thức mênh mông vô hạn
6 Hay để Thư viện trường Đại học Sư phạm Kỹ thuật Tp
HCM chỉa sẻ những khó khăn và trăn trở đó cùng bạn! Ề
THU VIEN
Cùng với bạn, Thư viện ĐH Sư phạm Kỹ thuật Tp
HCM mong ước góp phần duy trì và phát triển văn hóa GY
an
Kỹ thuật Tp HCM để cảm nhận, trải nghiệm và biến ước
mơ khoa học của bạn thành hiện thực ! 3à
Hân hạnh được đón tiếp và phục vụ bạn tại
Số I— 3, Võ Văn Ngân, Phường Linh Chiêu, Quận Thủ Đức, Tp HCM Ả
ĐT: (08) 3896 9920 — Email: thuvienspkt@)hemute.edu.vn i \ http://www.thuvienspkt.edu.vn — http://thuvien.hemute.edu.vn &
4 Y
Trang 14i @)9\25— Thông tin tài