Knowledge Base
...
Applied PIC Micro Development
Basics: Working With Hardware

Rotary BCD Switch

5min

Lead In

In the previous topic, we investigated the 8 BIT DIP bank, where the switches could represent simple switches or coded binary. The rotary-coded switch is an intuitive piece of hardware, where depending on the position of the switch, a specific BCD value is available.

See Also: BCD - Binary Coded Decimal๏ปฟ๏ปฟ

Working With the Rotary Switch

Shown below is a Wurth Electronic rotary switch, with the nine positions labeled on the switch. When used in a project, and installed in a target PCB, the switch produces a coded decimal output, which translates to the same position on the dial. The four input bits would then be wired or connected to the MCU.

Document image
๏ปฟ

The pinout and dimensional specifications are shown below.

๏ปฟ

Document image
๏ปฟ

BCD Implementation

You may have to stretch your memories back to the books to when you first learned about BCD (Binary Coded Decimal). Inspecting the pin layout of the switch below the implementation can be straightforward.

What the truth table indicates are the outputs that will be conducting, depending on the position. Wired up to the microcontroller and read in the same way as the DIP switch discussed previously, the rotary switch is an alternative to the DIP switch bank.

Truth Table
Truth Table
๏ปฟ

It is important to note that although the switch's output is BCD, it only provides 0 - 9 in decimal.

Code Sample

C
๏ปฟ

Lead Out

Implementing the rotary switch does require taking into consideration the value that is inputted. If the rotary switch is connected to the lower 4 bits you have a BCD value.

Updated 14 Nov 2023
Doc contributor
Did this page help you?