Serial communication

share picture

/*< /span>At Fu’an Apartment at 00:30 on August 10, 2018
Function: Send the set characters to the PC through the serial port assistant and connect to the serial port It is displayed on the assistant panel
Note: No need to write any data, and no need to check the hex send and hex display buttons, just click send,
*/
#include

unsigned
char flag;
void init()
{
TM OD
=0x20;
TH1
=0xf3;
TL1
=0xf3;
TR1
=1;
SM1
=1;
SM0
=0;
PCON
=0x80 ;//Set SMOD=1
REN =1; //Allow serial reception
EA =1;
ES
=1;

}< br />
void main()
{
init();
while(1)
{
if(flag ==1 span>)
{
flag
=0;
ES
=0;//Close the serial port interruption, otherwise it will cause interruption when receiving and sending data, which will form an endless loop
SBUF ='6';
while(!TI);
TI
=0;
SBUF
='2';
while(!TI);
TI
=0 ;
SBUF
='8 ';
while(!TI);
TI
=0;
ES
=1;
}
}
}

void usart() interrupt 4
{
RI
=0 ;
P2
=SBUF;
flag
=1;
}

View Code

Share a picture

/*August 10, 2018 at 00:30 at Fu'an Apartment
Function: Send the set characters to the PC through the serial port assistant Computer and displayed on the panel of the serial assistant Yes,
*/
#include

unsigned
char flag;
void init()
{
TMOD
=0x20;
TH1
=0xf3;
TL1
=0xf3;
TR1
=1;
SM1
=1;
SM0
=0;
PCON
=0x80; //Set SMOD=1
REN =1; //Allow serial reception
EA =1;
ES
=1;

}
void main()
{
init ();
while(1)
{
if(flag == 1)
{
flag
=0;
ES
=0;// Close the serial port interrupt, otherwise it will cause interruption when receiving and sending data. This will form an endless loop
SBUF ='6';
while (!TI);
TI
=0;
SBUF
='2';
while(! TI);
TI
=0;
SBUF
='8';
while(!TI);
TI
=0;
ES
=1;
}
}
}

void usart() interrupt 4< span style="color: #000000">
{
RI
=0;
P2
=SBUF;
flag
=1 span>;
}

View Code

< p>

/*At 30:30 on August 10, 2018 at Fu’an Apartment
Function : Send the set characters to the PC through the serial port assistant and display them on the serial port assistant's panel.
Note: No need to write any data, and there is no need to check the hex sending and hex display buttons, directly Just click send,
*/
#include

unsigned
char flag;
void init()
{
TMOD
=0x20;
TH1
=0xf3;
TL1
=0xf3;
TR1
=1;
SM1
=1;
SM0
=0;
PCON
=0x80 ;//Set SMOD=1
REN =1; //Allow serial reception
EA =1 ;
ES
=1;

}
void main()
{
init();
while(1)
{
if(flag ==1)
{
flag
= 0;
ES
=0;//Close the serial port interrupt, otherwise it will cause interruption when receiving and sending data, which will form an endless loop
SBUF ='6';
while(!TI);
TI
=0 ;
SBUF
='2 ';
while(!TI);
TI
=0;
SBUF
='8';
while (!TI);
TI
=0;
ES
=1;
}
}
}

void usart() interrupt 4
{
RI
=0;
P2
=SBUF;
flag
=1;
}

Leave a Comment

Your email address will not be published.