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-3. A hardware debouncing circuit, using a 74HC14<br />

Schmitt-trigger inverter.<br />

outputs together and the combined output will be low when any interrupt source is active.<br />

To enable the 8052-BASIC to identify the interrupt source, each source can also set a port<br />

bit. Latching the interrupt requests (with a flip-flop, for example) will ensure that no requests<br />

are missed. <strong>The</strong> 8052-BASIC can clear the latch by writing to another port bit when it<br />

identifies the source.<br />

For level-triggered interrupts, use this statement to clear bit 2 of the TCON register:<br />

TCON=(TCON=TCON.AND.0FBH)<br />

To return to edge-triggered, use this statement to set bit 2 of TCON:<br />

TCON=(TCON=TCON.OR.4)<br />

Polling<br />

When you don’t want to use an interrupt, an alternate way to detect a keypress is by polling,<br />

which consists of having the program check periodically to see if the switch has been pressed.<br />

In a program that prompts for input and then waits for the user to press a key, you can poll<br />

continuously until you see a response. Listing 7-2 is an example that assumes that you have<br />

two normally open pushbuttons connected to pins 1 and 2 of the 8052-BASIC, as in Figure<br />

7-4. This program stops reading the switch as soon as it detects a switch press, so debouncing<br />

114 <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!