ebook img

PIC Basic Projects: 30 Projects using PIC Basic and PIC Basic Pro PDF

378 Pages·2006·6.74 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 PIC Basic Projects: 30 Projects using PIC Basic and PIC Basic Pro

Prelims-H6879.qxd 6/7/06 2:43 PM Page i PIC BASIC Projects This page intentionally left blank Prelims-H6879.qxd 6/7/06 2:43 PM Page iii PIC BASIC Projects 30 Projects Using PIC BASIC and PIC BASIC PRO By Dogan Ibrahim AMSTERDAM• BOSTON• HEIDELBERG• LONDON• NEWYORK• OXFORD PARIS• SANDIEGO• SANFRANCISCO• SINGAPORE• SYDNEY• TOKYO Prelims-H6879.qxd 6/7/06 2:43 PM Page iv This eBook does not include ancillary media that was packaged with the printed version of the book. Linacre House, Jordan Hill, Oxford OX2 8DP, UK 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA Copyright © 2006 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 ((cid:1)44) (0) 1865 843830; fax ((cid:1)44) (0) 1865 853333; email: [email protected]. Alternatively you can submit your request online by visiting the Elsevier web site at http://elsevier.com/locate/permissions, and selecting Obtaining permission to use Elsevier material Notice No responsibility is assumed by the publisher for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions or ideas contained in the material herein. Because of rapid advances in the medical sciences, in particular, independent verification of diagnoses and drug dosages should be made British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Control Number:2006927674 ISBN-10: 0-75-066879-2 For information on all publications visit our web site at http://books.elsevier.com Trademarks/Registered Trademarks PIC is a registered trademark of Microchip Technology Inc. All brand names mentioned in this book are protected by their respective trademarks and are acknowledged Typeset by Charon Tec Ltd, Chennai, India www.charontec.com Printed and bound in Great Britain, by MPG Books Ltd. Prelims-H6879.qxd 6/7/06 2:43 PM Page v Contents Preface ix 1 Microcontroller systems 1 1.1 Introduction 1 1.2 Microcontroller systems 2 1.2.1 RAM 5 1.2.2 ROM 6 1.2.3 EPROM 6 1.2.4 EEPROM 6 1.2.5 Flash EEPROM 6 1.3 Microcontroller features 6 1.3.1 Supply voltage 7 1.3.2 The clock 7 1.3.3 Timers 7 1.3.4 Watchdog 7 1.3.5 Reset input 8 1.3.6 Interrupts 8 1.3.7 Brown-out detector 8 1.3.8 Analogue-to-digital converter 8 1.3.9 Serial I/O 9 1.3.10 EEPROM data memory 9 1.3.11 LCD drivers 9 1.3.12 Analogue comparator 10 1.3.13 Real-time clock 10 1.3.14 Sleep mode 10 1.3.15 Power-on reset 10 1.3.16 Low power operation 10 1.3.17 Current sink/source capability 10 1.4 Microcontroller architectures 11 1.4.1 RISC and CISC 11 1.5 Exercises 11 2 The PIC microcontroller family 13 2.1 12-bit instruction word 15 2.2 14-bit instruction word 17 2.3 16-bit instruction word 21 2.4 Inside a PIC microcontroller 21 2.4.1 Program memory (Flash) 21 2.4.2 Data memory (RAM) 22 Prelims-H6879.qxd 6/7/06 2:43 PM Page vi vi Contents 2.4.3 Register file map and special function registers 22 2.4.4 Oscillator circuits 34 2.4.5 Reset circuit 40 2.4.6 Interrupts 41 2.4.7 The configuration word 42 2.4.8 I/O interface 42 2.5 Exercises 47 3 PIC microcontroller project development 49 3.1 Required hardware tools 49 3.1.1 PC 49 3.1.2 PIC microcontroller programmer device 50 3.1.3 Solderless breadboard 52 3.1.4 PIC microcontroller and minimum support components 53 3.1.5 Power supply 58 3.2 Required software tools 60 3.2.1 Text editor 60 3.2.2 PicBasic and PicBasic Pro compilers 65 3.2.3 Programmer device software 67 3.3 Bundled development systems 69 3.4 Experimenter boards 71 3.5 Example project development 73 3.6 Other useful development tools 77 3.6.1 Simulators 77 3.6.2 In Circuit Emulators (ICE) 77 3.7 Exercises 78 3.8 Links to useful web sites 78 4 PicBasic and PicBasic Pro programming 80 4.1 PicBasic language 80 4.1.1 PicBasic variables 80 4.1.2 PicBasic mathematical and logical operations 85 4.1.3 PicBasic program flow control commands 86 4.1.4 Other PicBasic commands 90 4.1.5 Recommended PicBasic program structure 101 4.2 PicBasic Pro language 101 4.2.1 PicBasic Pro variables 102 4.2.2 Constants 103 4.2.3 Comments 103 4.2.4 Multi-statement lines 103 4.2.5 INCLUDE 104 4.2.6 DEFINE 104 4.2.7 Line extension 104 4.2.8 Accessing ports and other registers in PicBasic Pro 104 Prelims-H6879.qxd 6/7/06 2:43 PM Page vii Contents vii 4.2.9 Arithmetic operators 105 4.2.10 PicBasic Pro commands 107 4.3 Liquid crystal display (LCD) interface and commands 113 4.3.1 Parallel LCDs 114 4.3.2 Serial LCDs 120 4.4 Interrupts 124 4.5 Recommended PicBasic Pro program structure 125 4.6 Using stepping motors 126 4.7 Using servomotors 128 4.8 Exercises 129 5 PicBasic and PicBasic Pro projects 131 Project 1 – Simple flashing LED 132 Project 2 – Complex flashing LED 138 Project 3 – Flashing LED warning lights 142 Project 4 – Turning on odd numbered LEDs 144 Project 5 – Binary counting LEDs 148 Project 6 – Left scrolling LEDs 152 Project 7 – Right scrolling LEDs 156 Project 8 – Right-left scrolling LEDs 160 Project 9 – LED dice 165 Project 10 – 7-segment LED display counter 172 Project 11 – 7-segment LED dice 182 Project 12 – Dual 7-segment LED display 189 Project 13 – Dual 7-segment LED display counter 198 Project 14 – Dual 7-segment LED event counter 204 Project 15 – 4-digit display with serial driver – counter project 210 Project 16 – 4-digit LED with serial driver – counter project with leading zeroes blanked 227 Project 17 – 4-digit external interrupt-driven event counter 236 Project 18 – 4-digit timer interrupt-driven chronograph 241 Project 19 – Car park control system 248 Project 20 – Seconds counter with LCD display 260 Project 21 – LCD-based clock with hours–minutes–seconds display 271 Project 22 – LCD-based chronometer 280 Project 23 – LCD-based voltmeter using A/D converter 288 Project 24 – LCD-based thermometer using A/D converter 300 Project 25 – Serial LCD-based thermometer with external EEPROM memory 306 Project 26 – Programmable thermometer with RS232 serial output 315 Project 27 – Electronic organ 331 Project 28 – Unipolar stepping motor control 337 Project 29 – Unipolar stepping motor control using UCN5804B 344 Project 30 – Servomotor-based mobile robot control 348 About the CDROM 359 Index 361 This page intentionally left blank Prelims-H6879.qxd 6/7/06 2:43 PM Page ix Preface Microcontrollers are single-chip computers consisting of CPU (central processing unit), data and program memory, serial and parallel I/O (input/output), timers, external and internal interrupts, all integrated into a single chip that can be purchased for as little as $2.00. Microcontrollers are intelligent electronic devices used to control and monitor devices in the real world. Today micro- controllers are used in most commercial and industrial equipment. About 40% of microcontroller applications are in office automation, such as PCs, laser printers, fax machines, intelligent tele- phones, and so forth. About one-third of microcontrollers are found in consumer electronics goods. Products such as CD players, hi-f- equipment, video games, washing machines and cook- ers fall into this category. The communications market, automotive market, and the military share the rest of the application areas. Microcontrollers are programmed devices. A program is a sequence of instructions that tell the microcontroller what to do. Microcontrollers have traditionally been programmed using the low- level assembly language of the target processor. This consists of a series of instructions in the form of mnemonics. The biggest disadvantage of assembly language is that microcontrollers from different manufacturers have different assembly languages and the user is forced to learn a new language every time a new processor is chosen. Assembly language is also difficult to work with, especially during the development, testing, and maintenance of complex projects. The solution to this problem has been to use a high-level language to program microcontrollers. A high-level lan- guage consists of easy to understand, more meaningful series of instructions. This approach makes the programs more readable and also portable. The same high-level language can usually be used to program different types of microcontrollers. Testing and the maintenance of microcontroller-based projects are also easier when high-level languages are used. This book is about programming microcontrollers using a high-level language. The PIC family of microcontrollers is chosen as the target microcontroller. PIC is currently one of the most popular microcontrollers used by many engineers, technicians, students, and hobbyists. PIC microcon- trollers are manufactured in different sizes and in varying complexity. These microcontrollers incorporate a RISC (reduced instruction set computer) architecture and there is only a small set of instructions that the user has to learn. Also, the power consumption of PIC microcontrollers is very low and this is one of the reasons which make these microcontrollers popular in portable hand-held applications. In this book, PicBasic and PicBasic Pro languages are used to program PIC microcontrollers. BASIC is one of the oldest and widely known high-level programming languages. Both PicBasic and PicBasic Pro have been developed by MicroEngineering Labs Inc. PicBasic is a low-cost com- piler and is aimed at the lower end of the market, mainly for students and the hobby market.

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.