89C52 MCU serial port receiving and sending data

Publisher:RadiantDuskLatest update time:2022-10-11 Source: csdnKeywords:89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

Send data to the microcontroller through the serial port, and then the data + 1 is returned to the serial port

insert image description here

2. Function Implementation


#include


#define uchar unsigned char

#define uint unsigned int


sbit beep = P2^3; //Buzzer interface

uchar num; //Send temporary variable


void delay(uint z)

{

uint x,y;

for(x = z; x > 0; x--)

for(y = 114; y > 0 ; y--);

}

void UART_init()

{

TMOD = 0x20;  //T1 working mode 2 8-bit automatic reload

TH1 = 0xfd;

TL1 = 0xfd; //bit rate 9600 

TR1 = 1; //Start T1 timer

SM0 = 0;

SM1 = 1; //Serial port working mode 1 10-bit asynchronous

REN = 1; //Serial port allows receiving

EA = 1; // Enable general interrupt

ES = 1; //Serial port interrupt is turned on

}

void main()

{

UART_init(); //Serial port initialization

while(1);

}



void UART() interrupt 4 //Serial port interrupt

{

if(RI) //Check whether the reception is completed. When the hardware receives a data, RI is high.

{

num = SBUF;   //num takes out the value of the receive buffer

beep = 0;

delay(100);

beep = 1; //The buzzer emits a beeping sound

num++; //add 1 to the received data and send it

RI = 0;

SBUF = num;   //Return data to the buffer

while(!TI);

TI = 0;

}

}

Keywords:89C52 Reference address:89C52 MCU serial port receiving and sending data

Previous article:The use of 89C52 single chip microcomputer timer interrupt
Next article:51 MCU Basics DS18B20 Temperature Sensor

Recommended ReadingLatest update time:2024-11-22 22:27

An ISD4004 voice chip application circuit based on single-chip microcomputer control
1 Introduction The ISD4004 voice chip is a new product recently launched by the American ISD company. As the pin description and internal circuit of the voice chip can be easily found in the chip data provided by ISD, I will not describe it in detail in this article. I will only briefly introduce its characteris
[Microcontroller]
An ISD4004 voice chip application circuit based on single-chip microcomputer control
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号