A detection function that determines whether the serial port receives new data. The serial port receives the detection function.

Source: Internet
Author: User

A detection function that determines whether the serial port receives new data. The serial port receives the detection function.

Unsigned char Rxdsuc_test ()
{
Unsigned char noRxd_time = 10; // It is deemed that the data has been accepted after 10*5 ms and the next character is not received.
If (newRxd_flag) // when the sci serial port receives a character, newRxd_flag is set to 1; noRxd_flag is set to 0;
{
While (noRxd_time)
{
If (noRxd_flag)
{
Delay5ms (1 );
If (noRxd_flag)
NoRxd_time --;
}
Else
{
NoRxd_time = 10; // In the 10*5 ms wait, once the next character is received, the wait time is reset to 10*5 ms.
NoRxd_flag = 1;
}
}
RxdPoint = 0;
NewRxd_flag = 0;
Rxdsuc_flag = 1;
Return 1; // indicates that the new data has been received
}
Return 0; // indicates no new data
}

This function is used anywhere in the program and called when receiving data.

 

Related Article

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.