Using single chip microcomputer to make addition and subtraction serial calculator, within a decade, such as via a serial port to the MCU send 1 + 2, microcontroller through serial port sends the result 3
# include
typedef unsigned int u16;
typedef unsigned char u8;
U8 receive [5].
Under-16 I=0;
U8 sum;
Void UsartInit ()
{
TMOD=0x20;
TH1=0 xf9;
TL1=0 xf9;
PCON=0 x80;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
}
Void main ()
{
UsartInit ();
while(1);
}
Void Uasart () interrupt 4
{
ES=0;
The receive [i++]=SBUF;
If (I==3)
{
i=0;
The switch (the receive [1])
{
Case '+' : sum=receive [0] + the receive [2] - 48; break;
Case '-' : sum=receive [0] - the receive [2] + 48; break;
}
SBUF=sum;
while(! TI);
TI=0;
}
ES=1;
RI=0;
}
CodePudding user response:
Case '+' : sum=receive [0] + the receive [2] - 48After - 48, what do you mean?
Don't understand,
CodePudding user response: