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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7<br />

Figure 7-1. You can detect the state of a toggle or slide switch at an input<br />

port.<br />

switch (A) to one of these inputs, the external pull-up is optional. <strong>The</strong> pulldown resistor for<br />

switch (B) is 1.5K to ensure a valid logic low for LSTTL inputs. With an 8052-BASIC or<br />

CMOS input, you can use a 10K pulldown resistor.<br />

If you want to offer a choice among several options, a rotary switch can do the job. Figure<br />

7-2 shows an 8-position switch connected to an 8-bit input port.<br />

Reading a Switch<br />

To find the state of a switch, you read the byte at its address and use BASIC-52’s logical<br />

operators to find the value of the bit of interest, just as you did when reading input ports in<br />

Chapter 6. For example, to find the logic state of a switch at bit 7 of an input port at E000h,<br />

use this statement:<br />

A=(XBY(0E000H).AND.80H)/80H<br />

Or, in more general terms, use this format:<br />

A=(XBY(address).AND.2**bit)/2**bit<br />

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

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

Saved successfully!

Ooh no, something went wrong!