God three minutes teach you to control the shift display

Requires 4 & TImes; 4 matrix keyboards, digital displays. The keyboard is connected to P1 and the digital display is connected to P0 and P2.

The circuit and the display after the operation are as follows: God three minutes teach you to control the shift display

The C language control program is as follows:

//================================================ =======

#include

Char disp_buff [] = {0, 0, 0, 0, 0, 0, 0, 0};//display buffer unit

//------------------------------------------------ -------

Delay1ms(unsigned int t) //1ms delay function

{

Unsigned int i, j;

For(i = 0; i "t; i++) for(j = 0; j "120; j++);

}

//------------------------------------------------ -------

Void display(void) //Display functions

{

Char code table[] = { // section number of common cathode digital tube

0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,

0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};

Char code wei[] = {128, 64, 32, 16, 8, 4, 2, 1};//digit selection code

Char i;

For (i = 0; i "8; i++) {

P2 = 0; //first blanking

P0 = ~table[disp_buff [i]]; //Invert, used for the common Yang digital tube

P2 = wei[i];

Delay1ms(2);

}

}

//------------------------------------------------ -------

Unsigned char keyboard(void) //Scan keyboard function

{

Char i, j, temp, Buffer[4] = {0xef, 0xdf, 0xbf, 0x7f};

For(j = 0; j "4; j++) { // Loop scanning four lines

P1 = Buffer[j]; // outputs a low level in the upper four bits, respectively

Temp = 0x01; //plans to judge bit 0 first

For(i = 0; i "4; i++) { // cyclically scanning four columns

If(!(P1 & temp)) //From the lower four bits, take 1 bit

Return (i + j * 4); // returns 0 if it is 0

Temp "" = 1; / / Judgment, left one

} }

Return 16; //Judge the end, no key press, return 16

} / / Oh, the substantive statement but 8 lines, is so concise!

//------------------------------------------------ -------

Void main(void)

{

Unsigned char i, key;

While(1) { // infinite loop

Display(); //Show it again

Key = keyboard(); //read out the keyboard

If (key 16) { // if someone presses

//--------------------Key processing

Disp_buff[7] = disp_buff[6];

Disp_buff[6] = disp_buff[5];

Disp_buff [5] = disp_buff [4];

Disp_buff [4] = disp_buff [3];

Disp_buff [3] = disp_buff [2];

Disp_buff [2] = disp_buff [1];

Disp_buff[1] = disp_buff[0];

Disp_buff [0] = key;

//--------------------End of processing, wait for key release

For (i = 0; i "20; i++) display();//Slightly delayed

While(key "16" { // Wait for key release

Key = keyboard(); //read again

Display(); // Don't forget to show

} } } //Infinite loop

}

Absolute Encoder

Motion Control Sensor is an original part that converts the change of non-electricity (such as speed, pressure) into electric quantity. According to the converted non-electricity, it can be divided into pressure sensor, speed sensor, temperature sensor, etc. It is a measurement, control instrument and Parts and accessories of equipment.

Absolute Rotary Encoder,Absolute Linear Encoder,Absolute Optical Encoder,Absolute Position Encoder

Changchun Guangxing Sensing Technology Co.LTD , https://www.gx-encoder.com