CONTENTS

Preface

PART I The PIC 16F877A

Chapter 1 An Introduction to the PIC 16F877A Microcontroller Unit

The Microcontroller

Special Precautions and Notes of Interest

Data Sheets

Some Useable PICS

Chapter 2 Getting Started: The Hardware and Software Setup

The Programmers

Loading the Software

Using the Software in the Windows Environment

Software Notes from MicroEngineering Labs

Chapter 3 Understanding Microchip Technology’s PIC 16F877A: A Description of the MCU

16F877A Microcontroller’s Core Features

Peripheral Features

Configuring and Controlling the Properties of the Ports

PORTA

PORTB

PORTC

PORTD

PORTE

TIMERS

Chapter 4 The Software, the Compilers, and the Editor

The Basic Compiler Instruction Set

The PICBASIC PRO Compiler Instruction Set

PICBASIC PRO Compiler

Chapter 5 Controlling the Output and Reading the Input

General

Programs That Create Output

Programs That Read the Inputs and Then Provide Output

Creating Outputs

Blink One LED

Blink Eight LEDs in Sequence

Dim and Brighten One LED

LCD Display

Controlling the Digital and Analog Settings

Writing Binary, Hex, and Decimal Values to the LCD

Reading a Potentiometer and Displaying the Results on the LED Bargraph

A Simple Beep

Advanced Exercise: Controlling an RC Servo from the Keyboard

Reading the Inputs

Read Keyboard and Display Key Number on the LCD

Read One Potentiometer and Display Its 8-Bit Value on LCD in Binary, Hex, and Decimal Notation, Also Impress the Binary Value on the Bargraph

Read All Three Potentiometers and Display Their Values on the LCD

Adding the Kind of Flexibility That Defines Computer Interfaces and Demonstrates the Ability to Make Sophisticated Real-Time Adjustments

Exercises

Chapter 6 Timers and Counters

General

Timers

Timer0

Timer1: The Second Timer

Timer2: The Third Timer

Counters

Exercises for Timers

Exercises for Counters

Chapter 7 Clocks, Memory, and Sockets

Sockets U3, U4, and U5: For Serial One-Wire Memory Devices

Which EEPROM Type Should You Use?

Socket U3—I2C SEEPROM

Socket U4—SPI SEEPROM

Socket U5—Microwire Devices

Socket U6—Real-Time Clocks

The LTC1298 12-Bit A-to-D Converter (Also Used in Socket U6)

Sockets U7 (and U8)

Chapter 8 Serial Communications: Sockets U9 and U10

When and How Will I Know if It Is Working?

Using the RS485 Communications

Chapter 9 Using Liquid Crystal Displays: An Extended Information Resource

General

Using LCDs in Your Projects

Understanding the Hardware and Software Interaction

Talking to the LCD

The Hardware

Setting Out Our Design Intent

Liquid-Crystal Display Exercises

PART II The Projects

Chapter 10 Using Sensors (Transducers)

General

The Most Basic Question We Must Answer Is…

Types of Sensors

Two Interesting Resources You Will Want to Investigate

Chapter 11 Conditioning the Input Signal

General

Alternating Current Outline

Direct Current Outline

Simple Switches and Other Contacts

Circuitry for Conditioning dc Signals

Chapter 12 Conditioning the Output Signal

General

Chapter 13 An Introduction to the Eight Projects

The Web Site

The Eight Techniques

Notes

Chapter 14 The Universal Instrument: A Background Discussion

The Properties and Capabilities of a Universal Instrument

A Basic Temperature-Controlling Device

Notes

Chapter 15 Counting Pulses: A Programmable Tachometer

Project 1

Notes on Using Seven-Segment Displays

Chapter 16 Creating Accurate Intervals with Timers: The Metronomes

Project 2

Timer0

Timer1

Timer2

The Timer2 Program

The Watchdog Timer

Chapter 17 Understanding the Counters: Counting Marbles

Project 3

Counting with an Escapement

Some Real-World Notes

Counting to a Register Using an Interrupt

Counting Directly into an Internal Counter

Using Timer1 in Counter Mode

Special Notes for Timer1 Usage

Chapter 18 A Dual Thermometer Instrument

Project 4

Chapter 19 An Artificial Horizon: A Table Surface That Stays Level

Project 5

Discussion

Setting Up the Hardware Connections

Building the Artificial Horizon Table

Gravity Sensor Exercises

Chapter 20 Building a Simple Eight-Button Touch Panel

Project 6

Chapter 21 Single Set Point Controller with Remote Inhibit Capability

Project 7

Chapter 22 Logging Data from a Solar Collector

Project 8

Microcontroller Hardware

Software

Chapter 23 Debugging

General

Debugging and Troubleshooting

First Problem That Must Be Fixed: The Microcontroller Crystal Must Oscillate

If the Chip Refuses to Run

Using the PBP Compiler Commands to Help Debug a Program

Commands That Can Provide Debug Output to a Serial Port

Dumb Terminal Programs

Solderless Breadboards

Debugging at the Practical Level

Configuring the 16F877A and Related Notes

Settings

Configuration

Options

Simple Checks

Some Programmer-Related Error Messages

Things I Have Noticed but Have Not Figured Out (and Other Mysteries)

Setting the Ports

Chapter 24 Some Real-World Projects You Can Build

Conclusion

Appendixes

Appendix A Setting Up a Compiler for One-Keystroke Operation

Appendix B Abbreviations Used in this Book and in the Datasheets

Appendix C Listings of PICBASIC PRO Programs on the Internet at melabs.com

Appendix D Notes on Designing a Simple Battery Monitor Instrument: Thinking about a Simple Problem Out Loud

Appendix E Using the Support Web Site to Help Make Instruments and Controllers

Index