Understand the shape and code of the rotary encoder switch

In the design of electronic products, rotary coding switches, such as digital potentiometers, are often used. Its English name is translated into Rotary Encoder Switch. Before writing the driver for this component, I googled and baidu some of its instructions, knowing that it has three functions of left turn, right turn and press, with five feet, its shape is as shown below:

(1) 1, 3 feet should be connected with pull-up resistors, generally 10K is enough; (2) 2 feet are generally grounded; (3) 4, 5 feet are the switch wiring of the lower button (when pressed, 4 feet are low Level); The physical wiring diagram when I debug this component is:

In fact, it is not difficult to use. I have seen that the information on the Internet mostly says that it is difficult to judge the forward and reverse when operating it. Here I hope that the blogger will see that this is just a "legend" after reading my code. "! My code will make this question clear and simple! I think the key to judging forward and reverse is: When BMA is low, what is the edge of BMB? The rising edge indicates forward rotation and the falling edge indicates reverse rotation. As long as the description is clear with the code, the device can basically operate smoothly.

No extra words, just attach the code:

#include

#define uchar unsigned char

#define uint unsigned intsbit BMA=P1^4;

Sbit BMB=P1^5;

Sbit BMC=P1^6;

Sbit P27=P2^7;

Sbit P26=P2^6;

Sbit P25=P2^5;

Uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

Uchar count=0;

Understand the shape and code of the rotary encoder switch

Understand the shape and code of the rotary encoder switch

Understand the shape and code of the rotary encoder switch

Liquid Crystal Display For Vehicle Use

Dongguan Yijia Optoelectronics Co., Ltd. , https://www.everbestlcdlcms.com

This entry was posted in on