Home > Back-end >  Modify the MCU program
Modify the MCU program

Time:12-29

The program now only two operation how to unsigned decimal addition, subtraction, multiplication, and division can be two signed decimal arithmetic and the result is negative in the highest showed negative
#include
# define uint unsigned int
# define uchar unsigned char
Sbit dula=P2 ^ 6;//clip pin
Sbit wela=P2 ^ 7;//a selected pin
Uint flag, inputnum1 inputnum2 displaynum, mathsign, outputnum, keynum;
Uchar address []={XFD 0 xfe, 0, 0 XFB, 0 xf7, 0 xef, 0 XDF};//6 digital tube array address


Uchar table []={x5b x3f 0, 0 x06, 0, 0 x4f,//0 F Yin type digital tube glyph code
X6d 0 x66, 0, 0 x7d, 0 x07,
X6f 0 x7f, 0, 0 x77, 0 x7c,
X5e 0 x39, 0, 0 x79, 0 x71, 0 x40};


Void delayms (uint XMS)//delay function
{
Uint x, y;
For (x=XMS; x> 0; X -)
For (y=110; Y> 0; Y -);
}




Void keyscan ()
{
Uchar temp, temph templ, k;
P3=0 xf0;
Temp=P3;
Temph=temp& 0 xf0;
If (temph!=0 xf0)
{
Delayms (10);
Temp=P3;
Temph=temp& 0 xf0;
If (temph!=0 xf0)
{
P3=0 x0f;
Temp=P3;
Templ=temp& 0 x0f;
K=temph ^ templ;
The switch (k)
{
Case 0 xee: keynum=0; break;//0
Case 0 xde: keynum=1; break;//the number 1
Case 0 xbe: keynum=2; break;//number 2
Case 0 x7e: keynum=3; break;//the number 3


Case 0 xed: keynum=4; break;//number 4
Case 0 XDD: keynum=5; break;//the number 5
Case 0 XBD: keynum=6; break;//number 6
Case 0 x7d: keynum=7; break;//number 7


Case 0 xeb: keynum=8; break;//the number 8
Case 0 XDB: keynum=9; break;//the number nine
Case 0 XBB: keynum=10; break;//=
Case 0 x7b: keynum=11; break;//reset


Case 0 xe7: keynum=12; break;//+
Case 0 xd7: keynum=13; break;//-
Case 0 xb7: keynum=14; break;//*
Case 0 x77: keynum=15; break;///
}
While (temph!=0 xf0)
{
P3=0 xf0;
Temp=P3;
Temph=temp& 0 xf0;
}
}
}
}


Void the display ()
{
If (displaynum<10)/show/1 digits, 0 ~ 9
{
P0=0 XFF;
Wela=1;
P0=address [5];
Wela=0;


P0=0 x00;
Dula=1;
P0=table [displaynum];
Dula=0;
Delayms (1);
}
Else if
(displaynum<100)//show 2 digits, 10 to 99
{
P0=0 XFF;
Wela=1;
P0=address [5];
Wela=0;


P0=0 x00;
Dula=1;
P0=table [10] displaynum %;
Dula=0;
Delayms (1);


P0=0 XFF;
Wela=1;
P0=address [4];
Wela=0;


P0=0 x00;
Dula=1;
P0=table [10] displaynum/;
Dula=0;
Delayms (1);
}
The else//display 3 digits, 100 ~ 999
{
P0=0 XFF;
Wela=1;
P0=address [5];
Wela=0;


P0=0 x00;
Dula=1;
P0=table [10] displaynum %;
Dula=0;
Delayms (1);


P0=0 XFF;
Wela=1;
P0=address [4];
Wela=0;


P0=0 x00;
Dula=1;
P0=table [100/10] displaynum %;
Dula=0;
Delayms (1);


P0=0 XFF;
Wela=1;
P0=address [3].
Wela=0;


P0=0 x00;
Dula=1;
P0=table displaynum/100;
Dula=0;


Wela=1;
P0=address [3].
Wela=0;


P0=0 x00;
Dula=1;
P0=0 x40;
Dula=0;


Delayms (1);
}
}








Void main ()
{
While (1)
{
Keyscan ();
If (keynum<10)
{
If (flag==0)
{
Inputnum1=keynum;
Displaynum=inputnum1;
}
If (flag==1)
{
Inputnum2=keynum;
Displaynum=inputnum2;
}
}


If (keynum==10)
{
The switch (mathsign)
{
Case 12: outputnum=inputnum1 + inputnum2; break;
Case 13: outputnum=inputnum1 - inputnum2; break;
Case 14: outputnum=inputnum1 * inputnum2; break;
Case: 15 outputnum=inputnum1/inputnum2; break;
}
Displaynum=outputnum;
}


If (keynum==11)
{
Displaynum=0;
Inputnum1=0;
Inputnum2=0;
Outputnum=0;
Flag=0;
Keynum=16;
Mathsign=0;
}


If ((keynum>=12) & amp; & (keynum<=15))
{
flag=1;
Mathsign=keynum;
Displaynum=0;
}
The display ();
}
}
Next:o
  • Related