Reading Switches


• Embedded systems usually use switches as part of their user
interface.
• This general rule applies from the most basic remote-control
system for opening a garage door, right up to the most
sophisticated aircraft autopilot system.
• Whatever the system you create, you need to be able to
create a reliable switch interface.









In this seminar, we consider how you can read inputs from
mechanical switches in your embedded application.
Before considering switches themselves, we will consider the
process of reading the state of port pins.



Review: Basic techniques for reading from port pins

We can send some data to Port 1 as follows:
sfr P1 = 0x90; /* Usually in header file */
P1 = 0x0F; /* Write 00001111 to Port 1 */
In exactly the same way, we can read from Port 1 as follows:
unsigned char Port_data;
P1 = 0xFF; /* Set the port to ‘read mode’ */
Port_data = P1; /* Read from the port */