Home > Back-end >  For help how to move the left of the dynamic digital GuanGaiCheng move left and then press the equal
For help how to move the left of the dynamic digital GuanGaiCheng move left and then press the equal

Time:10-03

Presses the button on the digital tube display them one by one matrix corresponding to the key, the key value is as follows:
S1 to S4:0-3
S4 - the S8:4-7
The integrated - speed 12:8 - B
/S13 - S16: C - F
*/
# include

# define GPIO_DIG P0
# define GPIO_KEY P1

Sbit LSA=P2 ^ 2;
Sbit LSB=P2 ^ 3;
Sbit LSC=P2 ^ 4;

Unsigned char code DIG_CODE [17]={
X5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07,
X6f 0 x7f, 0, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71};
//0,1,2,3,4,5,6,7,8,9, A, b, C, d, E, F display code
Unsigned char KeyValue;
//used to store the keys of the read
Unsigned char KeyState;//record button state, 0 no, 1 have
Unsigned char DisplayData [8].
//used to store 8 digits to display the value of the
Void Delay10ms ();//delay 10 ms
Void KeyDown ();//test button function
Void DigDisplay ();//dynamic display function
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: the main
* function function: the main function
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main (void)
{
KeyState=0;
While (1)
{
KeyDown ();
If (KeyState==1)
{
DisplayData [7]=DisplayData [6].
DisplayData [6]=DisplayData [5].
DisplayData [5]=DisplayData [4].
DisplayData [4]=DisplayData [3].
DisplayData [3]=DisplayData [2].
DisplayData [2]=DisplayData [1].
DisplayData [1]=DisplayData [0].
DisplayData [0]=DIG_CODE [KeyValue];

KeyState=0;
}
DigDisplay ();
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: DigDisplay
* function function: using digital tube display
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void DigDisplay ()
{
unsigned char i;
Unsigned int j;
for(i=0; i<8; I++)
{
Switch (I)//person, choose the digital tube light,
{
Case (0) :
LSA=0; LSB=0; LSC=0; break;//show a 0
Case (1) :
LSA=1; LSB=0; LSC=0; break;//show the first bit
Case (2) :
LSA=0; LSB=1; LSC=0; break;//show the second
Case (3) :
LSA=1; LSB=1; LSC=0; break;//show the third
Case (4) :
LSA=0; LSB=0; LSC=1; break;//show 4
Case (5) :
LSA=1; LSB=0; LSC=1; break;//show the fifth
Case (6) :
LSA=0; LSB=1; LSC=1; break;//show the sixth
Case (7) :
LSA=1; LSB=1; LSC=1; break;//show the 7th
}
GPIO_DIG=DisplayData [I];//send paragraph
J=10;//scanning time interval set
While (j);
GPIO_DIG=0 x00;//blanking
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: KeyDown
* functions: detection with keys pressed and reads the keys
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void KeyDown (void)
{
Unsigned int a=0;
GPIO_KEY=0 x0f;
If (GPIO_KEY!=0 x0f)
{
Delay10ms ();
+;
A=0;
If (GPIO_KEY!=0 x0f)
{
KeyState=1;//a button press
//test column
GPIO_KEY=0 x0f;
//Delay10ms ();
The switch (GPIO_KEY)
{
Case (0 x07) : KeyValue=https://bbs.csdn.net/topics/0; break;
Case (0 x0b) : KeyValue=https://bbs.csdn.net/topics/1; break;
Case (0 x0d) : KeyValue=https://bbs.csdn.net/topics/2; break;
Case (0 x0e) : KeyValue=https://bbs.csdn.net/topics/3; break;
//the default: KeyValue=https://bbs.csdn.net/topics/17;//detection error reply 17 mean off all of the digital tube,
}
//test
GPIO_KEY=0 xf0;
Delay10ms ();
The switch (GPIO_KEY)
{
Case (0 x70) : KeyValue=https://bbs.csdn.net/topics/KeyValue; break;
Case (0 xb0) : KeyValue=https://bbs.csdn.net/topics/KeyValue+4; break;
Case (0 xd0) : KeyValue=https://bbs.csdn.net/topics/KeyValue+8; break;
Case (0 xe0-0xfc) : KeyValue=https://bbs.csdn.net/topics/KeyValue+12; break;
//the default: KeyValue=https://bbs.csdn.net/topics/17;
}
While ((a<500) & amp; & (GPIO_KEY!=0 xf0))//buttons let go test
{
Delay10ms ();
+;
}
A=0;
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: Delay10ms
* functions: delay function, delay 10 ms
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Delay10ms (void)//error 0 us
{
Unsigned char a, b, c;
For (c=1; C> 0; C -)
For (b=38; b> 0; B -)
For (a=130; A> 0; A -);
}
  • Related