Download as pdf
Download as pdf
You are on page 1of 10
About the Authors Martin P. Bates (Chapters 6, 7, 8, Appendices C, J) is the author of PIC Microcontrollers, He is currently lecturing on electronics and electrical engineering at Hastings College, UK. His interests include microcontroller applications and embedded system design. Lucio Di Jasio (Chapters 24, 25, 26, 27, 28, 29) is the author of Programming 16-bit Microcontrollers in C. He joined Microchip Technology in 1995 as a Field Application Engincer. Since 2005, he has been in charge of the Application Segment Group, a ctoss- divisional team of engincers that develops and promotes Microchip's solutions across a wide range of application segments, including: utility metering, intelligent power conversion, motor control and lighting applications. Chuck Hellebuyck (Chapters 15, 16, 17) is the author of Programming PIC Microcontrollers using PIC Basic. He is founder and president of Elproducts, Inc., a firm specializing in devices and project kits based on the PIC microcontroller. He writes a monthly column on the PIC microcontroller for “Nuts and Volts” magazine. Dogan Ibrahim (Chapters 1, 14) is the author of PICBasie Projects. He works for the Transport for London in UK. He was formerly a lecturer at South Bank University and Head of Department of Computer Engineering at Near East University, Cyprus. John Morton (Chapters 9, 10, Appendices D, E, F, G, H, I) is the author of The PIC Microcontroller. He is a Junior Research Fellow at St. John’s College, Oxford, investigating experimental quantum computation using electron spins. He works in the Oxford University Materials Department and Clarendon Laboratory and in collaboration with the Quantum Information Processing IRC. His interests include PIC Microcontrollers. D.W. Smith (Chapters 11, 12, 13) is the author of PIC in Practice. He has 30 years experience in the Electronics Industry. Before arriving at MMU he worked as an Electronics Design Engineer for ICL and Marconi, His teaching interests are focused on enabling Design and Technology students to implement microcontroller designs into their projects. Jack Smith (Chapters 18, 19, 20, 21, 22, 23) is the author of Programming the PIC Microcontroller with MBasic. He is currently with Clifton Laboratories in Virginia. He was PIC Microcontrollers Newnes Know It All Series PIC Microcontrollers: Know It All Lucio Di Jasio, Tim Wilmshurst, Dogan Ibrahim, John Morton, ‘Martin Bates, Jack Smith, D.W. Smith, and Chuck Hellebuyck ISBN: 978-0-7506-8615-0 Embedded Software: Know It All Jean Labrosse, Jack Ganssle, Tammy Noergaard, Robert Oshana, Colin Walls, Keith Curtis, Jason Andrews, David J. Katz, Rick Gentile, Kamal Hyder, and Bob Perrin ISBN: 978-0-7506-8583-2 Embedded Hardware: Know It All Jack Ganssle, Tammy Noergaard, Fred Eady, Lewin A.R.W. Edwards, David J. Katz, Rick Gentile, Ken Arnold, Kamal Hyder, and Bob Perrin ISBN: 978-0-7506-8584-9 Wireless Networking: Know It All Praphul Chandra, Daniel M. Dobkin, Alan Bensky, Ron Olexa, David Lide, and Farid Dowla ISBN: 978-0-7506-8582-5 RF & Wireless Technologies: Know It All Bruce Fette, Roberto Aiello, Praphul Chandra, Daniel Dobkin, Alan Bensky, Douglas Miron, David Lide, Farid Dowla, and Ron Olexa ISBN: 978-0-7506-8581-8 For more information on these and other Newnes titles visit: www.newnespress.com ELSEVIER PIC Microcontrollers Lucio Di Jasio Tim Wilmshurst Dogan Ibrahim John Morton Martin P. Bates Jack Smith D. W. Smith Chuck Hellebuyck AMSTERDAM + BOSTON + HEIDELBERG + LONDON NEW YORK + OXFORD + PARIS + SANDIEGO SAN FRANCISCO + SINGAPORE + SYDNEY + TOKYO Newnes is an imprint of Elsevier Newnes Newnes is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA. Linacre House, Jordan Hill, Oxford OX2 8DP, UK. Copyright © 2008, Elsevier Inc. All rights reserved, No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Permissions may be sought directly from Elsevier's Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: permissions@ elsevier.com. You may also complete your request online via the Elsevier homepage (http://elsevier.com), by selecting “Support & Contact” then Copyright and Permission” and then “Obtaining Permissions Gq Recognizing the importance of preserving what has been written, Elsevier prints its books on acid-free paper whenever possible. Library of Congress Cataloging-in-Publication Data PIC microcontrollers : know it all / Lucio Di Jasio ... [et al.] p. cm. ~ (The Newnes know it all series) ISBN-13: 978-0-7506-8615-0 1. Programmable controllers. 2. Microcomputers. 3. Microprocessors. I. Di Jasio, Lucio. 13223, P76PS2 2007 629.8'95416-de22 2007025364 British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN: 978-0-7506-8615-0 For information on all Newnes publications visit our Web site at www-books.elsevier.com 07 08 09 10 1987654321 Printed in the United States of America Working together to grow libraries in developing countries Contents About the Authors... Section |. An Introduction to PIC Microcontrollers ... Chapter 1. The PIC Microcontroller Family 3 1.1 12-bit Instruction Word . 6 1.2. 14-bit Instruction Word .. 7 1.3. 16-bit Instruction Word....... 1.4 Inside a PIC Microcontroller Chapter 2. Introducing the PI 16 Series and the 16F84A 39, 2.1 The Main Idea—the PIC 16 Series Family 2.2 An Architecture Overview of the 16F84A 2.3 A Review of Memory Technologies. 2.4 The 16F84A Memory. 2.5 Some Issues of Timing 2.6 Power-Up and Reset. 2.7 What Others Do—the Atmel AT89C2051 2.8 Taking Things Further—the 16F84A On-Chip Reset Circuit. 56 2.9 Summaty occ seers seers sees cosets coe SD References 59 Chapter 3, Parallel Ports, Power Supply and the Clock Oscillator 61 3.1 The Main Idea—Parallel Input/Output... 3.2 The Technical Challenge of Parallel Input/Output. 3.3. Connecting to the Parallel Port 3.4 The PIC 16F84A Parallel Ports 3.5 The Clock Oscillator 3.6 Power Supply... 3.7 The Hardware Design of the Electronic Ping Pong . 3.8 Summary References vi Contents Section Il. Programming PIC Microcontrollers Using Assembly Language .. Chapter 4. Starting to Program—An Introduction to Assembler 41 42 43 44 45 46 47 48 49 ‘The Main Idea—What Programs Do and How We Develop Them The PIC 16 Series Instruction Set, with a Little More on the ALU Assemblers and Assembler Format Creating Simple Programs. Adopting a Development Environment An Introductory MPLAB Tutorial. An Introduction to Simulation 1083 Downloading the Program to a Microcontroller 106 What Others Do—A Brief Comparison of CISC and RISC Instruction Sets... 108 4.10 Taking Things Further—The 16 Series Instruction Set Format 109 4.11 Summary evetnnstnntensennensennsenne eee 110 References 110 Chapter 5. Building Assembler Programs ... wld 5.1 ‘The Main Idea—Building Structured Programs. 1 5.2 Flow Control—Branching and Subroutines 14 5.3 Generating Time Delays and Intervals 118 5.4 Dealing with Data. se sevens 120 5.5 Introducing Logical Instructions. seeestnneennesenseee 1S 56 Introducing Arithmetic Instructions and the Carry Flag 125 5.7 Taming Assembler Complexity 130 5.8 More Use of the MPLAB Simulator ......--00eennnnnnnnnnnnnnnnnenennnee 132 5.9 The Ping-Pong Program .....ccsecsnesn 136 5.10 Simulating the Ping-Pong Program Tutorial. 140 5.11 What Others Do—Graphical Simulators. 143 5.12 Summary 143 References... 44 Chapter 6. Further Programming Techniques 145 6.1 Program Timing oo 145 6.2 Hardware Counter/Timer.... 147 6.3 Interrupts 152 6.4 More Register Operations. 158 65 Special Features 163 6.66 Program Data Table... esnestnneneensiescene seeeseee 167 6.7 Assembler Directives. 170 6.8 Special Instructions 173 6.9 Numerical Types...-socreernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnennnnnnees LTE 6.10 SUMMALY 6. os enninnsnnsnnnnnnnnninnninninninnnnnnnnnnninneines 175 Contents vii Chapter 7, Prototype Hardware....... 7.1 Hardware Design 7.2. Hardware Construction. 7.3 Demo Board 7.4 Demo Board Applic 7.5 Summary Chapter 8. More PIC Applications and Devices 199 8.1 16F877 Application........ . soneutnneneneananenie 199 Chapter 9. The PICI2F50x Series (8-pin PIC Microcontrollers) so 227 9.1 Differences from the PIC16F54 9.2 Example Project: PIC Dice. Chapter 10, Intermediate Operations Using the PICI2F675 10.1 The Inner Differences 10.2 Interrupts 10.3 EEPROM... - 10.4 Analog to Digital Conversion...... 10.5 Comparator Module 10.6 Final Project: Intelligent Garden Lights. Chapter 11, Using Inputs LLL Switch Flowchart 11.2 Program Development.... 11.3 Scanning (Using Multiple Inputs) . 11.4 Switch Scanning . 11.5 Control Application—A Hot Air Blower Chapter 12. Keypad Scanning. 12.1 Programming Example for the Keypad. Chapter 13, Program Examples 13.1 Counting Events 13.2 Look-Up Table. 13.3 7-Segment Display 13.4 Numbers Larger than 255... 13.5 Long Time Intervals 13.6 One Hour Delay. viii Contents Section IM, Programming PIC Microcontrollers Using PicBasic Chapter 14. PicBasic and PicBasic Pro Programming... 14.1 PicBasic Language 142 PicBasic Pro Language. 143 Liquid Crystal Display (LCD) Interface and Commands 14.4 Interrupts 14.5 Recommended PicBasic Pro Program Structure 14.6 Using Stepping Motors 14.7 Using Servomotors.... Chapter 15. Simple PIC Projects 15.1 Project #1—Flashing an LED 15.2 Project #2—Scrolling LEDs... 15.3 Project #3—Driving a 7-Segment LED Display Chapter 16. Moving On with the 16F876.... 16.1 Project #4—Accessing Port A VO... 16.2 Project #5—Analog-to-Digital Conversion. 16.3 Project #6—Driving a Servomotor. Chapter 17. Communication ccc 17.1 Project #7—Driving an LCD Module 17.2 Project #8—Serial Communication 17.3 Project #9—Driving an LCD with a Single Serial Connection, Section IV. Programming PIC Microcontrollers Using MBasic Chapter 18. MBasic Compiler and Development Boards ......1csnssnsnstnunnnns 18.1 The Compiler Package 18.2 BASIC and Its Essentials. 18.3 Development Boards 18.4 Programming Style... 18.5 Building the Circuits and Standard Assumptions. 18.66 Pins, Ports and Input/Output 18.7 Pseudo-Code and Planning the Program 18.8 Inside the Compiler... References Chapter 19. The Basics—Output 19.1 Pin Architectures 19.2 LED Indicators 19.3 Switching Inductive Loads - 2333 335 357 ..369 380 381 381 384 387 387 391 397 405 405 412 421 2429 429 439 447 463 12.465 465 467 470 473 415 416 485 2487 491 493 494 498 503

You might also like