Home > Back-end >  O which bosses, can you help me to convert the decimal calculator below into two, four, eight, sixte
O which bosses, can you help me to convert the decimal calculator below into two, four, eight, sixte

Time:11-24

# include "reg51. H"
Typedef unsigned char u8;//to statement defines the data type
Typedef unsigned int under-16;

Sbit LSA=P2 ^ 2;//74 hc138 decoder digital tube who choose
Sbit LSB=P2 ^ 3;
sbit LSC=P2^4;

# 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 press the number or operator or empty key
U8 code smgduan []={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71, 0 x40};//show 0 ~ F, minus sign '-'

Under-16 wei [8]={0};//used to store every digital tube digital array

Void delay (under-16 I)//delay function
{
While (I -);
}

Void the display ()//scan dynamic digital display tube
{
LSA=0; LSB=0; LSC=0; GPIO_DIG=smgduan [wei [7]]; delay(50); GPIO_DIG=0 x00;//blanking
LSA=1; LSB=0; LSC=0; GPIO_DIG=smgduan [wei [6]]; delay(50); GPIO_DIG=0 x00;
LSA=0; LSB=1; LSC=0; GPIO_DIG=smgduan [wei [5]]; delay(50); GPIO_DIG=0 x00;
LSA=1; LSB=1; LSC=0; GPIO_DIG=smgduan [wei [4]]; delay(50); GPIO_DIG=0 x00;
LSA=0; LSB=0; LSC=1; GPIO_DIG=smgduan [wei [3]]; delay(50); GPIO_DIG=0 x00;
LSA=1; LSB=0; LSC=1; GPIO_DIG=smgduan [wei [2]]; delay(50); GPIO_DIG=0 x00;
LSA=0; LSB=1; LSC=1; GPIO_DIG=smgduan [wei [1]]; delay(50); GPIO_DIG=0 x00;
LSA=1; LSB=1; LSC=1; GPIO_DIG=smgduan [wei [0]]; delay(50); GPIO_DIG=0 x00;
}

Void KeyDown (void)//testing with keys pressed and reads the keys
{
Under-16 a=0;
GPIO_KEY=0 x0f;
If (GPIO_KEY!=0 x0f)/whether/read button press
{
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)//line scanning method
{
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;
}
If (KeyValue=https://bbs.csdn.net/topics/=0 | | KeyValue==1 | | KeyValue==2 | | KeyValue==| 3 | KeyValue==4 | | Key