MCU Lesson 13th: Serial Communication --- send data to a computer

Source: Internet
Author: User

Jp3 is connected to P0 port.

# Include <reg51.h> # define uchar unsigned charuchar flag, num; // void initser (); void main () {// initser (); While (1) {// the data received from the computer is immediately sent to the computer if (flag = 1) {// close the interruption, otherwise it is necessary to enter the interrupted service program, will cause a vicious circle es = 0; flag = 0; // send data, write data to the sending cache sbuf = num; while (! Ti); Ti = 0; es = 1 ;}}// void initser () {// T1 works in Mode 2 tmod = 0x20; // initial installation value --- 9600 baud rate smod = 0th1 = 0xfd; TL1 = 0xfd; // start the timer tr1 = 1; // Serial Port Works in Mode 1 sm0 = 0; SM1 = 1; // enable MCU to receive data Ren = 1; // on interrupt es = 1; EA = 1;} // void Ser () interrupt 4 {// software reset rI = 0; // read data p0 = sbuf; num = sbuf; flag = 1 ;}


MCU Lesson 13th: Serial Communication --- send data to 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.