PIC Microcontrollers: Know It All

Chapter 11: Using Inputs

Overview

A control program usually requires more than turning outputs on and off. They switch on and off because an event has happened. This event is then connected to the input of the microcontroller to "tell" it what to do next. The input could be derived from a switch or it could come from a sensor measuring temperature, light levels, soil moisture, air quality, fluid pressure, engine speed, etc. In this chapter we will concern ourselves with digital on/off inputs. As an example let us design a circuit so that switch SW 1 will turn an LED on and off. The circuit diagram is shown in Fig. 11.1. This circuit uses the 16F84 microcontroller with a 32-kHz crystal.


Figure 11.1: Circuit Diagram of the Microcontroller Switch

It can of course also be performed with any of the microcontrollers discussed previously, including the 16F818 using its internal oscillator, in which case the crystal and 2 68pF capacitors are not required.

The program to control the hardware would use the following steps:

  1. Wait for SW1 to close.

  2. Turn on LED1.

  3. Wait for SW1 to open.

  4. Turn off LED1.

  5. Repeat.

In the circuit diagram SW1 is connected to A0 and LED1 to B0. When the switch is closed A0 goes low or clear, so we wait until A0 is clear. The code for this is:

BEGIN    BTFSC    PORTA,0 (test bit 0 in file PORTA skip if clear)         GOTO...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Air Switches
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.