ebook img

The Quintessential PIC Microcontroller PDF

484 Pages·2001·16.82 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Quintessential PIC Microcontroller

Computer Communications and Networks Springer-V erlag London Ltd. The Computer Communications and Networks series is a range of textbooks, monographs and handbooks. It setsout to provide students, researchers and non specialists alike with a sure grounding in current knowledge, together with comprehensible access to the latest developments in computer communications and networking. Emphasis is placed on clear and explanatory styles that support a tutorial approach, so that even the most complex of topics is presented in a lucid and intelligible manner. Also in this series: An Information Security Handbook John M.D. Hunter 1-85233-180-1 Multimedia Internet Broadcasting: Quality, Technology and Interface Andy Sloane and Dave Lawrence (Eds) 1-85233-283-2 Sid Katzen The Quintessential PIC Microcontroller Sid Katzen, BSc, MSc, DPhil, MI EE, MIEEE, CEng School of Electrical and Mechanical Engineering, University of Ulster, Newtownabbey, County Antrim BT37 OQB, UK Series editor Professor A.J. Sammes, BSc, MPhil, PhD, FBCS, CEng CISM Group, Cranfield University, RMCS, Shrivenham, Swindon SN6 8LA, UK In memory of Eva Jones ISBN 978-1-85233-309-6 British Library Cataloguing in Publication Data Katzen,Sid The quintessential PIC microcontroller. - (Computer communications and networks) 1. Programmable controllers 1. Title 629.8'9 ISBN 978-1-85233-309-6 Library of Congress Cataloging-in-Publication Data Katzen, Sid. The quintessential PIC microcontroller. / Sid Katzen. p. cm. - (Computer communications and networks) Includes index. ISBN 978-1-85233-309-6 ISBN 978-1-4471-3704-7 (eBook) DOI 10.1007/978-1-4471-3704-7 1. Programmable controllers. 1. Tîtle. II. Series. TJ223.P76 K38 2001 629.8'9-dc21 00-066153 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers,or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. © Springer-Verlag London 2001 Originally published by Springer-Verlag London Berlin Heidelberg in 2001 The use of registered names, trademarks etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Typesetting: Camera-ready by author 34/3830-543210 Printed on acid-free paper SPIN 10700872 Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VII Part I The Fundamentals 1. Digital Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Logic Circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3. Stored Program Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Part II The Software 4. The PIC16F84 Microcontroller............................... 77 5. The Instruction Set ......................................... 105 6. Subroutines and Modu1es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5 7. Interrupt Handling ......................................... 169 8. Assembly Language ........................................ 195 9. High-Level Language ....................................... 227 Part 111 The Outside World 10. The Real World ............................................ 249 11. One Byte at a Time ......................................... 267 12. One Bit at a Time .......................................... 301 13. Timeis of the Essence ...................................... 357 VI Contents 14. Take the Rough with the Smooth ............................ 385 15. To Have and to Hold ....................................... 425 16. A Case Study .............................................. 449 Appendices A. 14-bit Core lnstruction Set .................................. 469 B. Special Purpose Register Structure for the PIC16C74B ......... 471 C. C Instruction Set ........................................... 4 73 D. Acronyms and Abbreviations ............................... 475 Index ......................................................... 479 Preface Microprocessors and their microcontroller derivatives are a ubiquitous, if rather invisible, part of the infrastructure of our 21st century electronic and communications society. In 1998 it was reckoned 1 that hidden in ev ery home were about 100 microcontrollers and microprocessors; in the sillging birthday card, washing machine, microwave oven, television con troller, telephone, personal computer and so on. About 20 more lurked in the average family car. For example monitoring in-tire radio pressure sensors and displaying critical data through the car area network (CAN). Around 4 billion such devices are sold each year to implement the intelligence of these smart electronic devices, ranging from smart egg timers through aircraft management systems. The evolution of the mi croprocessor from the firstIntel device introduced 30 years ago in 1971 has revolutionised the structure of society, effectively creating the sec ond smart industrial revolution coming to fruition at the beginning of the 21st century. Although the microprocessor is better known in its guise of powering the ubiquitous PC, in which raw computing power is the goal, sales of such microprocessors as the Intel Pentium, represent only around 2% of total volume. The vast majority of sales are of low-cost microcontrollers embedded into a dedicated-function digital electronic device, such as the smart card. Here the emphasis is the integration of the core processor with memory and input/output resources in the one chip. This integrated computing system is known as a microcontroller. In seeking to write a book in this area the overall objective was to get the reader up to speed in designing small embedded microcontroller based systems, rather than using microcontrollers as a vehicle to illus trate computer architecture in the traditional sense. This will hopefully give the reader the confidence that even at such an introductory level, he/she can design, construct and program a complete working embed ded system. Given the practical mature of this material, real-world hardware and software products are used throughout to illustrate the material. The mi crocontroller market is dominated by devices that operate on 8-bit data (although 4- and 16-bit instances are available) like early microproces sors and unlike the 64-bit Intel Pentium and Motorola Power PC 'heavy brigade'. In contrast the essence of the microcontroller lies in their high 1New Scientist, vol. 59, no. 2141, 4th July 1998, pp.139. VIII The Quintessential PIC Microcontroller system integration/low cost profile. Power can be increased by distribut ing processors throughout the system. Thus, for example, a robot arm may have a microcontroller for each joint implementing simple local pro cesses and communicating with a more powerful processor making over all executive decisions. In choosing a target architecture, both acceptance in the industrial market, easy availability and low cost development software has made the Microchip family one of the most popular choices as the pedagogic vehicle in learning microprocessor/microcontroller technology at alllev els of electronic engineering from grade school to university. In particular the reduced instruction set together with the relatively simple innovative architecture reduces the learning curve. As well as its industrial and ed ucational roles, the PIC families are the mainstay of hobbyist projects; as a leaf through any Electronic magazine will show. Microchip inc. is a relatively recent entrant to the microcontroller mar ket with its family of Havard architecture PIC devices introduced in 1989. By 1999, Microchip was the second largest producer of 8-bit units - be hind only Motorola. The book is split into three parts. Part I covers sufficient digital, logic and computer architecture to act as a foundation for the microcontroller engineering topics presented in the rest of the text. Inclusion of this material makes the text suitable for stand-alone usage, as it does not require a prerequisite digital systems module. Part II looks mainly at the software aspects of the mid-range PIC mi crocontroller family, its instruction set, how to program it at assembly and high-level C coding levels, and how the microcontroller handles sub routines and interrupts. Although the 14-bit PIC family is the exemplar, both architecture and software are comparable to both the 12-and 16-bit ranges. Part III moves on to the hardware aspects of interfacing and interrupt handling, with the integration of the hardware and software being a con stant theme throughout. Paralleland serial inputjoutput, timing, analog and EEPROM data handling techniques are covered. A practical build and program case study integrates the previous material into a working sys tem, as well as illustrating simple testing strategies. With the exception of the first two and last chapter, all chapters have both fully worked examples and self-assessment questions. As an exten sion to this, an associated Web site at http://www.engj.ulst.ac.uk/sidk/quintessential has the following facilities: • Salutions to self-assessment questions. • Further self-assessment questions. • Additional material. Preface IX • Source code for all examples and questions in the text. • Pointers to development software and data sheets for devices used in the book. • Errata. • Feedback from readers. The manuscript was typeset on a Siemens Seenie D Pentium 133 PC by the author using a Y&Y implementation of ~TEX 2E and the Lucida Bright font family. Camera-ready copy was produced in . pdf format and used to directly generate plates at 1270dpi resolution. Line drawings were created or modified with Autocad Rl3 and incorporated as encapsulated PostScript files. Photographs were taken by the author using a Olympus C-14001 1.4M pixeldigital camera- absolutely full of microcontrollers! S.]. Katzen University of Ulster at Jordanstown December 2000 PART I The Fundamentals This book is about microcontrollers (MCUs). These are digital engines modeled after the architecture of a stored-program computer and in tegrated on to a single very large-scale integrated circuit together with support circuitry, memories and peripheral interface devices. Although the MCU is often confused with its better-known cousin the micropro cessor in its role as the driving force of the ubiquitous personal com puter, the vast majority of both microprocessors and microcontrollers are embedded into an assemblage of other digital components. The first microprocessors in the early 1970s were marketed as an alternative way of implementing digital circuitry. Here the task would be determined by a series of instructions encoded as binary code groups in read-only memory. This is more flexible than the alternative approach of wiring hardware integrated circuits in the appropriate manner. The microcon troller is simply the embodiment of this original role of the integrated computer. We willlook at embedded MCUs in a generaldigital processing context in Parts II and III. Here our objective is to lay the foundation for this material. We will be covering: • Digital code patterns. • Binary arithmetic. • Digital circuitry. • Computer architecture and programming. This will by no means be a comprehensive review of the subject, but there are many other excellent texts in this area2 which willlaunch you into greater depths. 2Such as S.J, Cahill's Digitaland Microprocessor Engineering, 2nd edn., Prentice Hall, 1993.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.