PREFACE

The advent of the microprocessor in a small all-encompassing package and the availability of easy-to-use software have changed the scope of what can be easily accomplished in the engineering laboratory and on the hobbyist’s workbench. The PIC® microcontrollers manufactured by Microchip Technology, Inc. of Tucson, Arizona form a formidable family of microcontrollers that can be used to fill myriad everyday needs. I have selected this family of microcontrollers for the projects in this book as a way of introducing the novice engineering student, serious hobbyist, and professional technician to the basic techniques that must be mastered to use these devices to make fairly sophisticated instruments and controllers.

The projects in this tutorial have been designed so they each emphasize the role of one specific technique for using these microcontrollers. Together, the eight projects give you the basic information and experience you require to design and build the unique instruments and controllers you will need for both your special and everyday needs.

The book is divided into two main areas of interest. The first part of the book introduces you to the PIC 16F877A in some detail so you know what is available in these microprocessors in the way of features. The second part of the book uses these features in the construction of the eight separate projects in detail. The 16F877A was chosen as the logic engine of choice in that this 40-pin IC has almost all the features one finds in the entire family of MCUs in the Microchip Technologies, Inc. offering. Once you understand the use of the 16F877A, you will be able to use the other microprocessors made by them and other manufacturers without difficulty. MicroEngineering Labs, Jameco, Solarbotics in Canada, and a large number of other vendors also provide a host of boards on which the 16F877A can be mounted.

The LAB-X1 board manufactured by microEngineering Labs was chosen as the basic board for all the experiments because it provides the user with a keyboard, an LCD display, a piezo speaker, and three potentiometers already mounted on the board and ready for use as part of the instruments we will make, and it can be used as a reliable test platform for the software we develop. It makes all the projects easier to assemble, experiment with, and modify as we develop them. The programs you create can be transferred to other microcontrollers in the family, with no modifications in some cases and minimal modifications in others. All you have to do is tell the compiler how you have changed the wiring, identify the microcontroller you are using, and it does the rest. Migration to MCUs made by other manufacturers should not present much difficulty either.

If you know very little about PIC microcontrollers and have never played with them, I strongly recommend you read my first book on microcontrollers, the Tutorial and Resource Book for the LAB-X1. This book is available from a number of sources, including me, microEngineering Labs in the U.S., Jameco, Solarbotics in Canada, and independent distributors all over the world. The first half of both books are similar in that they both concentrate on the properties of the microcontroller, but the first book will be much easier for you if you are a novice. This second book is targeted at readers who find my Tutorial and Resource Book for the LAB-X1 too basic for their needs. Though this book covers the basic properties of the 16F877A, it does not linger on fundamental explanations and techniques. This text delves into advanced techniques and greater integration and so is more suitable for the advanced engineer, the university student, the technician, and the amateur engineer/hobbyist.

This book is not designed to make you an expert in machine language programming or to prepare you to become a technical expert on PIC microprocessors. It is designed to give you a solid understanding of what these logical engines can do for you in the laboratory/field and to show you how you can use them to do it. I will cover everything in a nonmathematical, even somewhat nontechnical format, so if you have a minimal understanding of things both mechanical and electronic, you can use these microcontrollers to do useful work. With this in mind, I have concentrated on using the PICBASIC PRO Compiler provided by the manufacturers of the board to generate the assembly-level machine code rather than spend time teaching you how to use assembly language. The compiler uses a dialect of BASIC that is easy to understand and very powerful in that it does everything you need done in the context of programming the PIC microprocessors. The code generated is both compact and fast. There are times when assembly language subroutines can be added to the programming to make an especially critical task execute faster, and if you need to do this, the compiler allows it and offers ample information on the subject. This workbook does not cover assembly language or the “C” language.

The second part of this book teaches you about building basic microcontroller-based instruments and controllers by showing you how to build eight separate devices. These eight projects are designed to help you deal with real-world situations and each one concentrates on one aspect of the techniques used to make controllers and instruments. Sensors of various kinds are utilized to see how they can be used with microcontrollers to get the results you want. A detailed discussion of the problems that will be encountered, and how they may be solved, are included.

The workbook starts out with the construction of a programmable tachometer that teaches you about the most fundamental techniques used in microprocessors: counting pulses. It also covers the use of seven-segment displays, so you will be comfortable using them since they are usually the best solution for minimal displays. Having mastered the techniques covered in this exercise, you will be able to interface to all sensors/sources that provide pulsed signals.

The ability to read real-world inputs and control real-world outputs is combined to first create simple interactions, and then more sophisticated ones. An entire chapter is devoted to reading inputs of all kinds. In this chapter, you will find the information needed to interface your MCU to the kinds of things you find in your home and office, as well as in the engineering laboratory. Both ac and dc signals are covered so you can bring the information into the MCU no matter what the source.

Another entire chapter is devoted to controlling outputs of all kinds. The chapter gives you the information you need to control the real world with an MCU. Both low-current TTL devices and high-current solid state switches and relays are covered.

By the time you get to the end of this book, you should be able to use these logic engines to create small yet fairly sophisticated systems that can do work that is both interesting and useful. From there, you will have the knowledge and confidence needed to take on more complicated and sophisticated tasks.

Since this book is designed to be a resource, you will see things repeated from time to time in more than one chapter. This will save you from having to read the entire book to get the information you need. By doing this, each chapter has been made as self-contained as possible (within reason). Segments of code in the programs also repeat themselves for the same reason.

A lot of what any intelligent machine does has to do with the software in the machine. The software in the machine is specific to that machine, but the knowledge that goes into the design of a good program is universal. In this book, we will look into how the software is designed for these small processors, as well as how to determine what must be done to make a machine function properly so it can more completely realize its potential for doing useful work.

PIC microcontrollers I selected the Microchip Technology family of PIC microprocessors as the focus of these notes for two reasons. First, Microchip Technology provides the most comprehensive line of microprocessors for the kinds of projects we are interested in, and second, the compiler for these processors provides almost the entire line of PICs with comprehensive support. All you have to do is tell the compiler which PIC you are using, and if the features you have been addressing in your project are available on that particular PIC, the compiler will do the rest. You will never have to buy another compiler if you stay with the very comprehensive Microchip Technology family of PICs.

The LAB-X1 The microEngineering Labs LAB-X1 board was picked as the support board because it provides a very comprehensive set of onboard features that will let us do almost all our software experimentation and development on it with ease. The PIC 16F877A was chosen because if has almost all the features you would expect to find on any small microcontroller. All the skills you will develop with this device will be transferable to any other system you decide to migrate to with ease. The board and the compiler together give you the most value for your investment.

Discounted package Arrangements have been made with microEngineering Labs to provide a comprehensive package of software and hardware items suitable for use with this book at a discount. A coupon to claim this discount is included at the end of this book.

HARPRIT SINGH SANDHU
Champaign, IL, U.S.A.

Internet support sites: www.encodergeek.com and www.mhprofessional.com/sandhu