It is crucial to master these knowledge points when connecting MCU to DIP switch!
Q: What is the basic principle of DIP switch and MCU interface?
Connecting a microcontroller to a microcontroller using a dual-in-line package (DIP) switch is a common application. These switches, commonly known as "DIPs," are used in a variety of designs, from traditional DIPs suitable for breadboard prototyping to surface-mount " piano " types to rotary switches for easy hexadecimal reading .
In this article, we will take a closer look at rotary switches and explore how to integrate them into our microcontroller designs. The techniques presented in this article are generally applicable to all microcontroller designs.
Start with the rules
Let's start with a simple rule:
no floating inputs allowed
. A floating input occurs when a microcontroller pin is configured as an input but is otherwise unconnected. An example is shown here. When the switch is closed, the associated pin is tied to the positive rail. When the switch is open, the pin is floating.
Optimization solutions
Technical Tips:
Some microcontrollers have both pull-up and pull-down resistors. Others will have only one type, with the pull-up configuration being more common. These peripherals are often referred to as "weak pull-ups" and consume tens to hundreds of uA. This is equivalent to connecting an external pull-up resistor with a value between 15 kΩ and 150 kΩ.
-
The internal pull-up resistor is enabled using the microcontroller's special function registers
-
The common element of the switch is connected to ground
Technical tips:
The schematic shows an optional series resistor and an optional multiplexing section. This allows an I/O pin to perform double duty. For example, this narrow-width interface can be used to read a switch and also drive D3 to D0 on an LCD display. This can be desirable, as it potentially reduces microcontroller pin count and overall PCB size at the expense of circuit and code complexity.
Looking back at the microcontroller schematic and its associated pull-up resistors, we see an inversion. For example, when the switch is in the 1 position, there are three positive logic inputs at positions 2, 4, and 8. Meanwhile, if the complementary switch is installed, there is a positive logic (active-high) input corresponding to a 1 signal.
From a programming perspective, this difference in the physical switch code is insignificant. A simple bit-invert instruction will make them equal. From a troubleshooting or educational perspective, the complementary version may be easier to understand because it results in a positive logic value at the microcontroller pin.
This month's lucky draw password: Circuit Design
-
How to quickly get started with the new AVR MCU with integrated differential ADC?
-
Which programmer should I use for PIC microcontrollers including PIC16 and PIC18?
-
Implementing a Robust Microcontroller to FPGA SPI Interface: Part 3 - FPGA Top-Level Module
-
Overview: Relays, Switches, and General Electrical Connections










京公网安备 11010802033920号