#include
Typedef unsigned char u8;//to statement defines the data type
Typedef unsigned int under-16;
Sbit LSA=P2 ^ 2;//decoder 38 digital tube who choose
Sbit LSB=P2 ^ 3;
Sbit LSC=P2 ^ 4;
Sbit k1=P3 ^ 1;
Sbit k2=P3 ^ 0;
Sbit k3=P3 ^ 2;
Sbit k4=P3 ^ 3;
# define GPIO_KEY P1
# define GPIO_DIG P0
Under-16 KeyValue;//used to store the keys of the read
Under-16 keyflag, I;//used to reply whether there is a button to press
U8 code smgduan []={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};//show the value of 0 ~ F
Under-16 wei [8]={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: display
* function function: scan showed digital tube
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void the display ()
{
LSA=0; LSB=0; LSC=0; P0=smgduan [wei [0]]; Delay (50); P0=0 x00;
LSA=1; LSB=0; LSC=0; P0=smgduan [wei [1]]; Delay (50); P0=0 x00;
LSA=0; LSB=1; LSC=0; P0=smgduan [wei [2]]; Delay (50); P0=0 x00;
LSA=1; LSB=1; LSC=0; P0=smgduan [wei [3]]; Delay (50); P0=0 x00;
LSA=0; LSB=0; LSC=1; P0=smgduan [wei [4]]; Delay (50); P0=0 x00;
LSA=1; LSB=0; LSC=1; P0=smgduan [wei [5]]; Delay (50); P0=0 x00;
LSA=0; LSB=1; LSC=1; P0=smgduan [wei [6]]; Delay (50); P0=0 x00;
LSA=1; LSB=1; LSC=1; P0=smgduan [wei [7]]; Delay (50); P0=0 x00;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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;
delay(1000);//delay 10 ms away shaking,
If (GPIO_KEY!=0 x0f)//again to test whether the keyboard press
{
//test column
GPIO_KEY=0 x0f;
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;
}
//test
GPIO_KEY=0 xf0;
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;
}
While ((a<50) & amp; & (GPIO_KEY!=0 xf0))//inspection buttons let go
{
delay(1000);
+;
}
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: the main
* function function: the main function
No
* entered:No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main ()
{
Under-16 a=0, b=0, c=0;
While (1)
{
The display (); First digital input/* */
KeyDown ();
If (keyflag==1)
{
For (I=7. i> 0; I -)//input a number to the left to move a
{wei [I]=wei [I - 1); }
Wei [0]=KeyValue;
Keyflag=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * add operation * * * * * * * * * * * * * * * * * * * * * * * * * * * */
If (k1==0)
{
A=wei wei [0] + [1] * 10 + wei wei [2] * 100 + [3] * 1000 + wei wei [4] * 10000 + [5] * 100000 + wei wei [6] * 1000000 + [7] * 10000000;//calculate the value of a
for(i=0; i<8; I++)
Wei [I]=0;//to digital tube reset
While (1)//input the second number
{
The display ();
KeyDown ();
If (KeyValue=https://bbs.csdn.net/topics/=15) break;
If (keyflag==1)
{
For (I=7. i> 0; I -)
{wei [I]=wei [I - 1); }
Wei [0]=KeyValue;
Keyflag=0;
}
}
B=wei wei [0] + [1] * 10 + wei wei [2] * 100 + [3] * 1000 + wei wei [4] * 10000 + [5] * 100000 + wei [6] * 1000000 + wei [7] * 10000000;//calculate the value of b
C=a + b;
Wei [0]=c % 10;//calculate every bit of C digital
wei[1]=c/10%10;
wei[2]=c/100%10;
wei[3]=c/1000%10;
wei[4]=c/10000%10;
wei[5]=c/100000%10;
wei[6]=c/1000000%10;
wei[7]=c/10000000%10;
While (1)
{
The display ();
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * subtract * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Else if (k2==0)
{
A=wei wei [0] + [1] * 10 + wei wei [2] * 100 + [3] * 1000 + wei wei [4] * 10000 + [5] * 100000 + wei wei [6] * 1000000 + [7] * 10000000;//calculate the value of a
for(i=0; i<8; I++)
Wei [I]=0; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull