Serial Communication Method 1 Programming

Source: Internet
Author: User

Send a character X to the serial port debugging assistant on the host computer. After receiving the character, the MCU returns the "I get X" to the host computer. The serial port baud rate is set to 9600bps.

# Include <reg52.h>
# Define uchar unsigned char
Unsigned char flag, A, I;
Uchar code table [] = "I get ";
Void Init ()
{
Tmod = 0x20; // set the T1 timer Working Mode 2
Th1 = 0xfd; // Initial Value of T1 Timer
TL1 = 0xfd;
Tr1 = 1; // start the T1 Timer
Ren = 1; // allow serial port Mode 1
Sm0 = 0; // set the serial port Mode 1
SM1 = 1;
Ea = 1; // total disconnection
Es = 1; // enable serial port interruption
}


Void main ()
{
Init ();
While (1)
{
If (flag = 1)
{
Es = 0;
For (I = 0; I <8; I ++)
{
Sbuf = table [I];
While (! Ti );
Ti = 0;
}
Sbuf =;
While (! Ti)
Ti = 0;
Es = 1;
Flag = 0;
}
}
}


Void Ser () interrupt 4
{
Ri = 0;
A = sbuf;
Flag = 1;
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.