18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Switches and Keypads<br />

Figure 7-2. Use a rotary switch to allow users to choose from among several<br />

options.<br />

where address is the location of the byte to be read in memory and bit is the bit number of<br />

the switch.<br />

Detecting a Switch Press<br />

Momentary switches are useful when you want to get the computer’s attention. For example,<br />

you might have a program that normally displays the current temperature and time, but<br />

switches to a setup routine when you press a switch. On a normally open pushbutton<br />

(momentary) switch, the contacts close when you press the switch, then open as you release<br />

it. In a normally closed momentary switch, the contacts open when you press, and close on<br />

release.<br />

Using Interrupts<br />

An easy way to detect a switch press is with an external interrupt. <strong>The</strong> 8052-BASIC<br />

automatically detects the switch press and branches to an interrupt-handling subroutine.<br />

<strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong> 111

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!