MCU Lesson 11th: Serial Communication query method --- receiving data from a computer

Source: Internet
Author: User

How can I use a computer to send data to a single-chip computer and how can the single-chip computer receive data?

Jp3 is connected to P0 port. Send a hexadecimal data from the computer to the microcontroller, and then view the digital display.

# Include <reg51.h>/** send a hexadecimal data to the microcontroller to display the digital tube */void initser (); void main () {<span> </span> initser ();
While (1) {// query the RI value. If it is 1, the data is received and the software should be cleared. Ri = 0if (Ri = 1) {rI = 0; // obtain the data sent from the computer from the buffer and assign it to p0p0 = sbuf ;}}// initialization function void initser () {// enable the timer T1 to work in Mode 2 tmod = 0x20; // assign the value of Th1 = 0xfd; TL1 = 0xfd; // the serial port is 1 sm0 = 0; SM1 = 1; // allow serial port accept Ren = 1; // start the timer tr1 = 1; p0 = 0xc0 ;}
Steps for serial communication query:

1 --- determine how the timer T1 works

2 --- assign values to the two registers of the timer

3 --- start timer T1

4 --- determine how the serial port works

5 --- if the microcontroller needs to obtain data from the computer, it should make Ren = 1

6 --- query the RI value. If it is 1, the data is received. Note that the software should set Ri to 0 immediately.

MCU Lesson 11th: Serial Communication query method --- receiving data from a computer

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.