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 />

7<br />

Switches and Keypads<br />

Most microcontroller projects will include switches, a keypad, or some other way of<br />

allowing users to control the circuits inside. <strong>The</strong> control might involve flipping a switch<br />

begin an operation, pressing a key to to select an option, or entering a number for the program<br />

to use in its operations. For simple tasks, you can use toggle, slide, or pushbutton switches.<br />

Other projects might call for a keypad with an array of switches, with each labeled with a<br />

number, letter, or other description. This chapter shows how to add each of these to your<br />

system.<br />

Simple Switches<br />

Figure 7-1 shows two single-pole, single-throw toggle or slide switches connected to an<br />

input port. Each has contacts that connect when the switch is closed, and open when the<br />

switch is open.<br />

In (A), when the switch is open, the pull-up resistor brings the input high. When the switch<br />

closes, the input connects to ground and reads low. Switch (B) is the reverse: when the switch<br />

is open, the pull-down resistor brings the input low. When the switch closes, it connects to<br />

+5V and reads high.<br />

You can connect a switch to an unused bit on the 8052-BASIC’s Port 1, to an input on an<br />

8255 PPI, or to a input on a 74LS244 buffer. <strong>The</strong> 8052-BASIC has internal pullups that<br />

bring the inputs to +5V when they are not being driven by another source. So, if you connect<br />

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

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

Saved successfully!

Ooh no, something went wrong!