PROGRAMMING AND CUSTOMIZING THE PIC MICROCONTROLLER 3rd phần 1 ppt

130 600 1
PROGRAMMING AND CUSTOMIZING THE PIC MICROCONTROLLER 3rd phần 1 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com PROGRAMMING AND CUSTOMIZING THE PIC ® MICROCONTROLLER Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com About the Author A resident of Toronto, Canada, Myke Predko is the best-selling author of 13 McGraw-Hill electronics and engineering titles, including Digital Electronics Demystified and 123 Robotics Experiments for the Evil Genius. He holds a B.S.E.E. from the University of Waterloo, and is the Electrical Engineering/Firmware Development Manager for Logitech’s Harmony Remote Control Business Unit. Copyright © 2008, 2002, 1997 by The McGraw-Hill Companies, Inc. Click here for terms of use. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com PROGRAMMING AND CUSTOMIZING THE PIC ® MICROCONTROLLER MYKE PREDKO Third Edition New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Copyright © 2008, 2002, 1997 by The McGraw-Hill Companies, Inc. All rights reserved. Manufactured in the United States of America. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be repro- duced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written per- mission of the publisher. 0-07-151087-7 The material in this eBook also appears in the print version of this title: 0-07-147287-8. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in cor- porate training programs. For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw- hill.com or (212) 904-4069. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms. THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WAR- RANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, puni- tive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. DOI: 10.1036/0071472878 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com We hope you enjoy this McGraw-Hill eBook! If you’d like more information about this book, its author, or related books and websites, please click here. Professional Want to learn more? Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com v CONTENTS Introduction xi Acknowledgments x xi Chapter 1 Embedded Microcontrollers 1 Microcontroller Types 1 Internal Hardware 2 Applications 5 Processor Architectures 7 Instructions and Software 12 Peripheral Functions 17 Memory Types 21 Microcontroller Communication 28 Device Packaging 35 Application Development Tools 39 Chapter 2 The Microchip PIC Microcontroller 43 Accessing the Microchip Web Site 43 PIC Microcontroller Feature Summary 48 Features Unique to the PIC Microcontroller 54 PIC Microcontroller Families 59 Chapter 3 Software Development Tools 63 Tools Overview 65 High Level Languages 83 Microchip MPLAB IDE 103 Chapter 4 Programming PIC Microcontrollers 155 Hex File Format 156 Code Protection 158 Parallel Programming 159 PIC ICSP Programmer Interface 166 Microchip Programmers 178 My Programmers 181 Third-Party Programmers 204 Chapter 5 Emulators and Debuggers 207 MPLAB ICE-2000 210 MPLAB REAL ICE 213 For more information about this title, click here Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com vi CONTENTS MPLAB ICD 2 Debugger 214 The Emu-II 219 Other Emulators 241 Chapter 6 The Microchip PIC MCU Processor Architecture 243 The CPU 244 Hardware and File Registers 248 The PIC Microcontroller’s ALU 254 Data Movement 260 The Program Counter and Stack 264 Reset 268 Interrupts 271 Architecture Differences 273 Chapter 7 Using the PIC MCU Instruction Set 293 Setting Up the MPLAB IDE Simulator with a Test Template 294 PIC MCU Instruction Types 297 The Mid-Range Instruction Set 303 Low-End PIC Microcontroller Instruction Set 348 PIC18 Instruction Set 356 Chapter 8 Assembly-Language Software Techniques 373 Sample Template 374 Labels, Addresses, and Flags 376 Subroutines with Parameter Passing 381 Subtraction, Comparing and Negation 385 Bit AND and OR 389 16-Bit Operations 390 MulDiv, Constant Multiplication and Division 392 Delays 400 Patch Space 405 Structures, Pointers, and Arrays 407 Sorting Data 414 Interrupts 419 Reentrant Subroutines 423 Simulating Logic 423 Event-Driven Programming 426 State Machine Programming 429 Porting Code Between PIC Microcontroller Device Architectures 430 Optimizing PIC Microcontroller Applications 438 A Baker’s Dozen Rules to Follow That Will Help to Avoid Application Software Problems 443 Chapter 9 Basic Operating Features 445 Power Input and Decoupling 446 Configuration Fuses 451 OPTION Register 470 TMR0 478 Interrupt Operation 483 The Right PIC Microcontroller to Learn On 485 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com CONTENTS vii Chapter 10 Macro Development 489 PIC Microcontroller Assembly-Language Macros 489 The Difference Between Defines and Macros 492 The Assembler Calculator 494 Multiline C Macros 499 Conditional Assembly/Compilation 500 Using Defines and Conditional Assembly for Application Debug 507 Debugging Macros 509 Structured Programming Macros 513 Chapter 11 Building and Linking 519 Creating Linked Applications 519 Chapter 12 Bootloaders 527 Bootloader Requirements 528 Mid-Range Bootloaders 530 PIC18 Bootloaders 535 Chapter 13 Real-Time Operating Systems 537 Low-End and Mid-Range RTOSs 541 PIC18 RTOS Design 542 Chapter 14 Debugging Your Applications 565 Document the Expected State 566 Characterize the Problem 567 Hypothesize and Test Your Hypothesis 569 Propose Corrective Actions 571 Test Fixes 572 Release Your Solution 576 Debug: An Application to Test Your Debug Skills 577 Chapter 15 PIC Microcontroller Application Design and Hardware Interfacing 589 Requirements Definition 590 PIC Microcontroller Resource Allocation 595 Effective User Interfacing 597 Project Management 599 Power Management 603 Reset 608 Interfacing to External Devices 611 Chapter 16 PIC MCU Optional Hardware Features 617 Mid-Range Built-in EEPROM/Flash Access 618 TMR1 624 TMR2 626 Compare/Capture/PWM (CCP) Module 628 Serial I/O 633 Analog I/O 649 Parallel Slave Port (PSP) 657 In-Circuit Serial Programming (ICSP) 659 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com viii CONTENTS Chapter 17 PIC MCU Input and Output Device Interfacing 661 LEDs 661 Switch Bounce 665 Matrix Keypads 668 LCDs 672 Analog I/O 682 Audio Output 690 Relays and Solenoids 692 Asynchronous (NRZ) Serial Interfaces 693 Synchronous Serial Interfaces 704 Chapter 18 Motor Control 711 Dc Motors 711 Stepper Motors 724 R/C Servo Control 733 Chapter 19 Practical PC Interfacing 739 PC Software Application Development Tools 740 Serial Port 742 Parallel Port 749 Chapter 20 PIC Microcontroller Application Basics 755 Jumping Around 755 Some Basic Functions 771 Analog Input/Output 798 I/O with Interrupts 810 Serial I/O 832 Chapter 21 Projects 853 Low-End Devices 853 Mid-Range Devices 878 PIC18 Devices 953 Appendix A Resources 965 Microchip 965 Books to Help You Learn Moreabout the PIC Microcontroller 966 Useful Books 967 Recommended PIC Microcontroller Websites 970 Periodicals 971 Other Websites of Interest 972 Part Suppliers 973 Appendix B PIC Microcontroller Summary 977 Feature to Part Number Table 977 Instruction Sets 977 I/O Register Addresses 1016 Device Pinouts 1030 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... 10 73 10 73 10 89 10 91 C Programming Language 11 23 Common Library Functions 11 30 PICC Library Functions 11 33 Microchip C18 Library Functions 11 38 Appendix G Reuse, Return, and Recycle 11 49 Useful Snippets 11 50 Mykemacs.inc 11 60 Sixteen-Bit Numbers 12 00 Glossary 12 13 Index 12 29 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com This page intentionally left blank Simpo PDF Merge and Split... introduction of the PIC2 4 16 bit data word size MCUs and the PIC1 7 which has a 16 bit instruction size like the PIC1 8 The PIC1 8 architecture is your best choice for developing applications that need to communicate with external devices or your PC (many of the chips have built in USB ports which do not require any external interface chips) The PIC1 8 also offers the largest program memory space and best performance... connectivity with other devices Somebody may point out that the Parallax Stamp products use the low-end PIC microcontrollers, but at the time the products were designed, these were the cheapest chips available; today the mid-range and PIC1 8 devices provide much more capabilities at a lower price point than the low-end did when the Stamp was first conceived The mid-range (14 bit instruction size) PIC microcontrollers... own PIC microcontroller programmer (although the design for the PIC microcontroller programmer is discussed in the body of the book) The decision not to include these features was quite easy when I looked at the current situation and what is being offered with this book The primary purpose of the CD-ROM included in the previous editions of the book was to provide the source code for the experiments and. .. code for the projects All parts specified in this book are available easily from a variety of sources Where there can be confusion with regards to the parts, I have listed distributor part numbers in the text The latest PIC microcontroller devices and features are presented The eight and fourteen pin PIC microcontrollers along with the latest EEPROM/Flash and PIC1 8 microcontroller parts and their features... that are designed around the PIC MCU, you would discover that the vast majority are designed around two or three part numbers (the PIC1 6F84, PIC1 6C54, and perhaps the PIC1 6F877) This is unfortunate because there are a plethora of different PIC microcontrollers that you can choose from to build your applications around and chances are there will be a part number that has exactly the features that will... They are: 1 Some of the information was given in the first edition before prerequisite informa- 2 3 4 5 6 7 8 9 10 11 12 13 14 15 tion was presented Some chapters have been reordered and changed to eliminate this from being a problem in the second edition, and this has been continued in the third edition All pseudo-code examples are written in “C.” C is the most popular high-level language for PIC microcontroller. .. studying and working through these different application types you will gain a strong insight into the operation of the PIC microcontroller and help to understand how you can develop your applications using the different part numbers available to you PIC Microcontroller Resources and Tools Unlike the previous edition there is no CD-ROM included with this book and there is no PCB for the user to build their... and Split Unregistered Version - http://www.simpopdf.com ix CONTENTS Appendix C Useful Tables and Data 10 61 Electrical Engineering Formulas 10 63 Mathematical Formulas 10 65 Mathematical Conversions 10 66 ASCII 10 67 Appendix D Miscellaneous Electronic Reference Information Basic Electronic Components and Their Symbols Test Equipment 10 80 Appendix E Basic Programming Language PICBASIC Appendix F 10 73 10 73... somewhat unusual, but I believe they are appropriate for real-time microcontroller applications Copyrights and Trademarks Microchip is the owner of the following trademarks: PIC, PIC microcontroller, REAL ICE, ICSP, KEELOQ, MPLAB, PICSTART, PRO MATE and PICMASTER PICC and PICC Lite are owned by HI-TECH Software microEngineering Labs, Inc is the owner of PicBasic Microsoft is the owner of Windows/95, Windows/98, . Language 10 89 PICBASIC 10 91 Appendix F C Programming Language 11 23 Common Library Functions 11 30 PICC Library Functions 11 33 Microchip C18 Library Functions 11 38 Appendix G Reuse, Return, and Recycle. input bitwise AND ––Truth Table: Inputs Output AB 00 0 01 0 10 0 11 1 AND | && Logical AND | ––Two input bitwise OR ––Truth Table: Inputs Output AB 00 0 01 1 10 1 11 1 OR | || Logical. microcontroller line due to the recent introduction of the PIC2 4 16 bit data word size MCUs and the PIC1 7 which has a 16 bit instruction size like the PIC1 8. The PIC1 8 architecture is your best choice for developing

Ngày đăng: 12/08/2014, 23:21

Từ khóa liên quan

Mục lục

  • Contents

  • Introduction

  • Acknowledgments

  • Chapter 1 Embedded Microcontrollers

    • Microcontroller Types

    • Internal Hardware

    • Applications

    • Processor Architectures

    • Instructions and Software

    • Peripheral Functions

    • Memory Types

    • Microcontroller Communication

    • Device Packaging

    • Application Development Tools

    • Chapter 2 The Microchip PIC Microcontroller

      • Accessing the Microchip Web Site

      • PIC Microcontroller Feature Summary

      • Features Unique to the PIC Microcontroller

      • PIC Microcontroller Families

      • Chapter 3 Software Development Tools

        • Tools Overview

        • High Level Languages

        • Microchip MPLAB IDE

Tài liệu cùng người dùng

Tài liệu liên quan