SCM 11th Lesson: Serial Communication Query Method---accept data from computer

Source: Internet
Author: User

How to use a computer to send data to a single-chip microcomputer, how to receive data from a single-chip microcomputer?

The JP3 is connected to the P0 port.

Send a hexadecimal data from the computer to the microcontroller and watch the display of the digital tube.

#include <reg51.h>/** send a hexadecimal data to the microcontroller to display the digital tube */void initser (); void Main () {<span></span>initser () ;
while (1) {//queries the value of RI. If it is 1, then the data is received. The software should be zeroed at this time. RI = 0if (ri = = 1) {ri = 0;//gets data sent from the computer from the buffer, assigned to P0P0 = Sbuf;}}} Initialize function void Initser () {//Let timer T1 work in mode 2 Tmod = 0x20;//Assignment TH1 = 0xfd; TL1 = 0xfd;//Serial Port working mode is 1SM0 = 0; SM1 = 1;//agreed serial port accepts ren = 1;//start timer TR1 = 1; P0 = 0xc0;}
Serial Communication Query Method steps:

1---Determine how the timer T1 works

2---Assigning two registers to a timer

3---start timer T1

4---Determine how the serial port works

5---Assuming that a single piece of data is obtained from the computer, ren = 1 should be

6---Query the value of RI, assuming that it is 1, then receive the data, note that the software should immediately be set to RI = 0

SCM 11th Lesson: Serial Communication Query Method---accept data from 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.