Home > other >  For help, about 51 microcontroller serial port
For help, about 51 microcontroller serial port

Time:12-06

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

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] - 48


After - 48, what do you mean?
Don't understand,

CodePudding user response:

reference 1st floor hww5222 response:
case '+' : sum=receive receive [0] + [2] - 48


After - 48, what do you mean?
Don't understand,

48 ASCII value is 0, is to ASCII code is converted into digital

CodePudding user response:

, don't know if using industrial computer inside the string, 51 microcontroller program to read and convert to the parameters of industrial computer, PLC to read want to change?? Ask god to help answer my questions - I
51 single-chip microcomputer and PLC - how to read and write communication??
  • Related