8051 microcontroller (STC89C52) implements serial communication in polling mode (51 receives data and sends it back to the PC)

Publisher:ShimmeringMoonLatest update time:2022-04-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include <STC89C5xRC.H>

 

int main()

{

char buf;

TMOD = 0x21; //Set the working mode of timer1

SCON = 0x50; //Set serial communication format

TH1 = 0xE6; //Set the initial value of timer1

TL1 = 0xE6; 

TR1 = 1; //Start timer1

while(1)

{

if(RI == 1)

{

//If data is received

buf = SBUF;

RI = 0;

SBUF = buf; //Send the received data back

while(TI == 0); //Wait for data to be sent

IF = 0;

}

}

return 0;

}

Reference address:8051 microcontroller (STC89C52) implements serial communication in polling mode (51 receives data and sends it back to the PC)

Previous article:51 single chip microcomputer - LED water light
Next article:8051 and ESP32 CAM serial communication

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号