next up previous contents
Next: Reading a Bit in Up: Basic Input and Output Previous: Writing Your First Program   Contents

Reading the state of a push button

Although it is uncommon to connect an advanced user interface to an MCU, it is common to connect push buttons to an MCU so an end user has a simple method to interact with the MCU.

Most of the time, a normally-open, momentary, single-pole-single-throw push button is connected to between an input pin and the ground. As a single-pole-single-throw button, it is only switched to one source (in our case, the ground). As a normally-open and momentary button, it remains open when no one pushes it, and only closes for as long as someone pushes the button.

Recall from section 10.4 what pull-up means. When a button is connected between a pulled-up input pin and ground, the button can affect the voltage experienced by the input pin. When the button is not pushed, it remains open, and the pulled-up input pin experiences a high voltage through the weak connection to high voltage. However, when the button is pushed, it provides a strong connection to ground and the input pin experiences a low voltage.

In other words, when the button is pushed, the input pin reads 0. When the button is released, the input pin reads 1. Although this sounds counter intuitive, this is actually how 99% of push buttons are implemented (that 0 indicates a button is pushed).


next up previous contents
Next: Reading a Bit in Up: Basic Input and Output Previous: Writing Your First Program   Contents
Tak Auyeung 2003-11-10