4 * 4 keys, seven segment digital tube display, a total of anode button 8 0 ~ F, each press a button, the number of the original left shift, the latest of several always appear on the far right,
The following procedures as if can only be in the right variables, cannot shift to the left and keep the original number
Is there a big help me take a look at how to change
Thank you very much!!!!!!!!!!!
# include "reg51. H"//this file defines the MCU some special function register
Typedef unsigned int under-16;//to statement defines the data type
Typedef unsigned char u8;
# define GPIO_DIG P0
# define GPIO_KEY P1
U8 KeyValue;//used to store the keys of the read
U8 keyflag;//used to reply whether there is a button to press
U8 code smgduan [16]={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92,
0 x82, 0 xf8, 0 x80, 0 x90, 0 x88, 0 x83, 0 xc6, xa1 0, 0 x86, 0 x8e};//show the value of 0 ~ F
Under-16 wei [8]=,1,2,3,4,5,6,7 {0};//used to store every digital tube digital array
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: delay
* function function: delay function, I=1, delay about 10 us
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay (under-16 I)
{
while(i--);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: KeyDown
* functions: detection with keys pressed and reads the keys
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void KeyDown (void)
{
Char a=0;
GPIO_KEY=0 x0f;
If (GPIO_KEY!=0 x0f)/whether/read button press
{
Keyflag=1;//a button press, value is 1;
delay(1000);//delay 10 ms away shaking,
If (GPIO_KEY!=0 x0f)//again to test whether the keyboard press
{
//test column
GPIO_KEY=0 xf0;
//Delay10ms ();
The switch (GPIO_KEY)
{
Case (0 xe0-0xfc) : KeyValue=https://bbs.csdn.net/topics/0; break;
Case (0 xd0) : KeyValue=https://bbs.csdn.net/topics/1; break;
Case (0 xb0) : KeyValue=https://bbs.csdn.net/topics/2; break;
Case (0 x70) : 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 x0f;
/* Delay10ms (); */
The switch (GPIO_KEY)
{
Case (0 x0e) : KeyValue=https://bbs.csdn.net/topics/KeyValue; break;
Case (0 x0d) : KeyValue=https://bbs.csdn.net/topics/KeyValue+4; break;
Case (0 x0b) : KeyValue=https://bbs.csdn.net/topics/KeyValue+8; break;
Case (0 x07) : KeyValue=https://bbs.csdn.net/topics/KeyValue+12; break;
While ((a<500) & amp; & (GPIO_KEY!=0 xf0))//inspection buttons let go
{
delay(1000);
a++;
}
}
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: display
* function function: scan showed digital tube
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void the display ()
{unsigned char (I);
Unsigned char j;
for(i=0; I<8; I++)
{
P0=smgduan [wei [I]].
The P2=~ (1 & lt; for(j=0; J<200; J++)
{}
The P2=0 XFF;
for(j=0; J<10; J++)
{}}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: the main
* function function: the main function
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main ()
{
u8 i;
While (1)
{
The display ();//digital tube display
KeyDown ();//determine whether buttons to press
If (keyflag==1)//if the button pressed, each number in the array to move forward a
{
For (I=7. I> 0; I -)
{wei [I]=wei [I - 1); }
Wei [0]=KeyValue;
Keyflag=0;
}
}
}